Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(299)

Side by Side Diff: gpu/command_buffer/service/gl_context_virtual.cc

Issue 15841002: gpu: Fix corrupted state due to virtual MakeCurrent race. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reland patch. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | gpu/command_buffer/service/gl_state_restorer_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gpu/command_buffer/service/gl_context_virtual.h" 5 #include "gpu/command_buffer/service/gl_context_virtual.h"
6 6
7 #include "gpu/command_buffer/service/gl_state_restorer_impl.h" 7 #include "gpu/command_buffer/service/gl_state_restorer_impl.h"
8 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" 8 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
9 #include "ui/gl/gl_surface.h" 9 #include "ui/gl/gl_surface.h"
10 10
(...skipping 12 matching lines...) Expand all
23 gfx::Display* GLContextVirtual::display() { 23 gfx::Display* GLContextVirtual::display() {
24 return display_; 24 return display_;
25 } 25 }
26 26
27 bool GLContextVirtual::Initialize( 27 bool GLContextVirtual::Initialize(
28 gfx::GLSurface* compatible_surface, gfx::GpuPreference gpu_preference) { 28 gfx::GLSurface* compatible_surface, gfx::GpuPreference gpu_preference) {
29 SetGLStateRestorer(new GLStateRestorerImpl(decoder_)); 29 SetGLStateRestorer(new GLStateRestorerImpl(decoder_));
30 30
31 display_ = static_cast<gfx::Display*>(compatible_surface->GetDisplay()); 31 display_ = static_cast<gfx::Display*>(compatible_surface->GetDisplay());
32 32
33 if (!shared_context_->MakeCurrent(compatible_surface)) 33 // Virtual contexts obviously can't make a context that is compatible
34 return false; 34 // with the surface (the context already exists), but we do need to
35 // make a context current for SetupForVirtualization() below.
36 if (!IsCurrent(compatible_surface)) {
37 if (!shared_context_->MakeCurrent(compatible_surface)) {
38 // This is likely an error. The real context should be made as
39 // compatible with all required surfaces when it was created.
40 LOG(ERROR) << "Failed MakeCurrent(compatible_surface)";
41 return false;
42 }
43 }
35 44
36 shared_context_->SetupForVirtualization(); 45 shared_context_->SetupForVirtualization();
37 46 shared_context_->MakeVirtuallyCurrent(this, compatible_surface);
38 shared_context_->ReleaseCurrent(compatible_surface);
39 return true; 47 return true;
40 } 48 }
41 49
42 void GLContextVirtual::Destroy() { 50 void GLContextVirtual::Destroy() {
43 shared_context_->OnDestroyVirtualContext(this); 51 shared_context_->OnDestroyVirtualContext(this);
44 shared_context_ = NULL; 52 shared_context_ = NULL;
45 display_ = NULL; 53 display_ = NULL;
46 } 54 }
47 55
48 bool GLContextVirtual::MakeCurrent(gfx::GLSurface* surface) { 56 bool GLContextVirtual::MakeCurrent(gfx::GLSurface* surface) {
49 if (decoder_.get() && decoder_->initialized()) 57 // TODO(epenner): We should avoid bypassing MakeVirtuallyCurrent() below
58 // (return false or DCHECK when !decoder). To do this we must reorder
59 // tear-down in GpuCommandBufferStub::Destroy().
60 if (decoder_.get())
50 shared_context_->MakeVirtuallyCurrent(this, surface); 61 shared_context_->MakeVirtuallyCurrent(this, surface);
51 else 62 else if (!IsCurrent(surface))
52 shared_context_->MakeCurrent(surface); 63 shared_context_->MakeCurrent(surface);
53 return true; 64 return true;
54 } 65 }
55 66
56 void GLContextVirtual::ReleaseCurrent(gfx::GLSurface* surface) { 67 void GLContextVirtual::ReleaseCurrent(gfx::GLSurface* surface) {
57 if (IsCurrent(surface)) 68 if (IsCurrent(surface))
58 shared_context_->ReleaseCurrent(surface); 69 shared_context_->ReleaseCurrent(surface);
59 } 70 }
60 71
61 bool GLContextVirtual::IsCurrent(gfx::GLSurface* surface) { 72 bool GLContextVirtual::IsCurrent(gfx::GLSurface* surface) {
62 bool context_current = shared_context_->IsCurrent(NULL); 73 // If it's a real surface it needs to be current.
63 if (!context_current) 74 if (surface &&
64 return false; 75 !surface->GetBackingFrameBufferObject() &&
76 !surface->IsOffscreen())
77 return shared_context_->IsCurrent(surface);
65 78
66 if (!surface) 79 // Otherwise, only insure the context itself is current.
67 return true; 80 return shared_context_->IsCurrent(NULL);
68
69 gfx::GLSurface* current_surface = gfx::GLSurface::GetCurrent();
70 return surface->GetBackingFrameBufferObject() ||
71 surface->IsOffscreen() ||
72 (current_surface &&
73 current_surface->GetHandle() == surface->GetHandle());
74 } 81 }
75 82
76 void* GLContextVirtual::GetHandle() { 83 void* GLContextVirtual::GetHandle() {
77 return shared_context_->GetHandle(); 84 return shared_context_->GetHandle();
78 } 85 }
79 86
80 void GLContextVirtual::SetSwapInterval(int interval) { 87 void GLContextVirtual::SetSwapInterval(int interval) {
81 shared_context_->SetSwapInterval(interval); 88 shared_context_->SetSwapInterval(interval);
82 } 89 }
83 90
(...skipping 18 matching lines...) Expand all
102 109
103 void GLContextVirtual::SetUnbindFboOnMakeCurrent() { 110 void GLContextVirtual::SetUnbindFboOnMakeCurrent() {
104 shared_context_->SetUnbindFboOnMakeCurrent(); 111 shared_context_->SetUnbindFboOnMakeCurrent();
105 } 112 }
106 113
107 GLContextVirtual::~GLContextVirtual() { 114 GLContextVirtual::~GLContextVirtual() {
108 Destroy(); 115 Destroy();
109 } 116 }
110 117
111 } // namespace gpu 118 } // namespace gpu
OLDNEW
« no previous file with comments | « no previous file | gpu/command_buffer/service/gl_state_restorer_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698