OLD | NEW |
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 11 matching lines...) Expand all Loading... |
22 } | 22 } |
23 | 23 |
24 gfx::Display* GLContextVirtual::display() { | 24 gfx::Display* GLContextVirtual::display() { |
25 return display_; | 25 return display_; |
26 } | 26 } |
27 | 27 |
28 bool GLContextVirtual::Initialize( | 28 bool GLContextVirtual::Initialize( |
29 gfx::GLSurface* compatible_surface, gfx::GpuPreference gpu_preference) { | 29 gfx::GLSurface* compatible_surface, gfx::GpuPreference gpu_preference) { |
30 display_ = static_cast<gfx::Display*>(compatible_surface->GetDisplay()); | 30 display_ = static_cast<gfx::Display*>(compatible_surface->GetDisplay()); |
31 | 31 |
32 if (!shared_context_->MakeCurrent(compatible_surface)) | 32 // Virtual contexts obviously can't make a context that is compatible |
33 return false; | 33 // with the surface (the context already exists), but we do need to |
| 34 // make a context current for SetupForVirtualization() below. |
| 35 if (!IsCurrent(compatible_surface)) { |
| 36 if (!shared_context_->MakeCurrent(compatible_surface)) { |
| 37 // This is likely an error. The real context should be made as |
| 38 // compatible with all required surfaces when it was created. |
| 39 LOG(ERROR) << "Failed MakeCurrent(compatible_surface)"; |
| 40 return false; |
| 41 } |
| 42 } |
34 | 43 |
35 shared_context_->SetupForVirtualization(); | 44 shared_context_->SetupForVirtualization(); |
36 | |
37 shared_context_->ReleaseCurrent(compatible_surface); | |
38 return true; | 45 return true; |
39 } | 46 } |
40 | 47 |
41 void GLContextVirtual::Destroy() { | 48 void GLContextVirtual::Destroy() { |
42 shared_context_->OnDestroyVirtualContext(this); | 49 shared_context_->OnDestroyVirtualContext(this); |
43 shared_context_ = NULL; | 50 shared_context_ = NULL; |
44 display_ = NULL; | 51 display_ = NULL; |
45 } | 52 } |
46 | 53 |
47 bool GLContextVirtual::MakeCurrent(gfx::GLSurface* surface) { | 54 bool GLContextVirtual::MakeCurrent(gfx::GLSurface* surface) { |
48 if (decoder_.get() && decoder_->initialized()) | 55 if (decoder_.get() && decoder_->initialized()) |
49 shared_context_->MakeVirtuallyCurrent(this, surface); | 56 shared_context_->MakeVirtuallyCurrent(this, surface); |
50 else | 57 else |
51 shared_context_->MakeCurrent(surface); | 58 shared_context_->MakeCurrent(surface); |
52 return true; | 59 return true; |
53 } | 60 } |
54 | 61 |
55 void GLContextVirtual::ReleaseCurrent(gfx::GLSurface* surface) { | 62 void GLContextVirtual::ReleaseCurrent(gfx::GLSurface* surface) { |
56 if (IsCurrent(surface)) | 63 if (IsCurrent(surface)) |
57 shared_context_->ReleaseCurrent(surface); | 64 shared_context_->ReleaseCurrent(surface); |
58 } | 65 } |
59 | 66 |
60 bool GLContextVirtual::IsCurrent(gfx::GLSurface* surface) { | 67 bool GLContextVirtual::IsCurrent(gfx::GLSurface* surface) { |
61 bool context_current = shared_context_->IsCurrent(NULL); | 68 // If it's a real surface it needs to be current. |
62 if (!context_current) | 69 if (surface && |
63 return false; | 70 !surface->GetBackingFrameBufferObject() && |
| 71 !surface->IsOffscreen()) |
| 72 return shared_context_->IsCurrent(surface); |
64 | 73 |
65 if (!surface) | 74 // Otherwise, only insure the context itself is current. |
66 return true; | 75 return shared_context_->IsCurrent(NULL); |
67 | |
68 gfx::GLSurface* current_surface = gfx::GLSurface::GetCurrent(); | |
69 return surface->GetBackingFrameBufferObject() || | |
70 surface->IsOffscreen() || | |
71 (current_surface && | |
72 current_surface->GetHandle() == surface->GetHandle()); | |
73 } | 76 } |
74 | 77 |
75 void* GLContextVirtual::GetHandle() { | 78 void* GLContextVirtual::GetHandle() { |
76 return shared_context_->GetHandle(); | 79 return shared_context_->GetHandle(); |
77 } | 80 } |
78 | 81 |
79 gfx::GLStateRestorer* GLContextVirtual::GetGLStateRestorer() { | 82 gfx::GLStateRestorer* GLContextVirtual::GetGLStateRestorer() { |
80 return state_restorer_.get(); | 83 return state_restorer_.get(); |
81 } | 84 } |
82 | 85 |
(...skipping 22 matching lines...) Expand all Loading... |
105 | 108 |
106 void GLContextVirtual::SetUnbindFboOnMakeCurrent() { | 109 void GLContextVirtual::SetUnbindFboOnMakeCurrent() { |
107 shared_context_->SetUnbindFboOnMakeCurrent(); | 110 shared_context_->SetUnbindFboOnMakeCurrent(); |
108 } | 111 } |
109 | 112 |
110 GLContextVirtual::~GLContextVirtual() { | 113 GLContextVirtual::~GLContextVirtual() { |
111 Destroy(); | 114 Destroy(); |
112 } | 115 } |
113 | 116 |
114 } // namespace gpu | 117 } // namespace gpu |
OLD | NEW |