| 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_gl_api_implementation.h" | 9 #include "ui/gl/gl_gl_api_implementation.h" |
| 10 #include "ui/gl/gl_surface.h" | 10 #include "ui/gl/gl_surface.h" |
| 11 #include "ui/gl/gpu_timing.h" | 11 #include "ui/gl/gpu_timing.h" |
| 12 | 12 |
| 13 namespace gpu { | 13 namespace gpu { |
| 14 | 14 |
| 15 GLContextVirtual::GLContextVirtual( | 15 GLContextVirtual::GLContextVirtual( |
| 16 gfx::GLShareGroup* share_group, | 16 gfx::GLShareGroup* share_group, |
| 17 gfx::GLContext* shared_context, | 17 gfx::GLContext* shared_context, |
| 18 base::WeakPtr<gles2::GLES2Decoder> decoder) | 18 base::WeakPtr<gles2::GLES2Decoder> decoder) |
| 19 : GLContext(share_group), | 19 : GLContext(share_group), |
| 20 shared_context_(shared_context), | 20 shared_context_(shared_context), |
| 21 display_(NULL), | |
| 22 decoder_(decoder) { | 21 decoder_(decoder) { |
| 23 } | 22 } |
| 24 | 23 |
| 25 gfx::Display* GLContextVirtual::display() { | |
| 26 return display_; | |
| 27 } | |
| 28 | |
| 29 bool GLContextVirtual::Initialize( | 24 bool GLContextVirtual::Initialize( |
| 30 gfx::GLSurface* compatible_surface, gfx::GpuPreference gpu_preference) { | 25 gfx::GLSurface* compatible_surface, gfx::GpuPreference gpu_preference) { |
| 31 SetGLStateRestorer(new GLStateRestorerImpl(decoder_)); | 26 SetGLStateRestorer(new GLStateRestorerImpl(decoder_)); |
| 32 | 27 |
| 33 display_ = static_cast<gfx::Display*>(compatible_surface->GetDisplay()); | |
| 34 | |
| 35 // Virtual contexts obviously can't make a context that is compatible | 28 // Virtual contexts obviously can't make a context that is compatible |
| 36 // with the surface (the context already exists), but we do need to | 29 // with the surface (the context already exists), but we do need to |
| 37 // make a context current for SetupForVirtualization() below. | 30 // make a context current for SetupForVirtualization() below. |
| 38 if (!IsCurrent(compatible_surface)) { | 31 if (!IsCurrent(compatible_surface)) { |
| 39 if (!shared_context_->MakeCurrent(compatible_surface)) { | 32 if (!shared_context_->MakeCurrent(compatible_surface)) { |
| 40 // This is likely an error. The real context should be made as | 33 // This is likely an error. The real context should be made as |
| 41 // compatible with all required surfaces when it was created. | 34 // compatible with all required surfaces when it was created. |
| 42 LOG(ERROR) << "Failed MakeCurrent(compatible_surface)"; | 35 LOG(ERROR) << "Failed MakeCurrent(compatible_surface)"; |
| 43 return false; | 36 return false; |
| 44 } | 37 } |
| 45 } | 38 } |
| 46 | 39 |
| 47 shared_context_->SetupForVirtualization(); | 40 shared_context_->SetupForVirtualization(); |
| 48 shared_context_->MakeVirtuallyCurrent(this, compatible_surface); | 41 shared_context_->MakeVirtuallyCurrent(this, compatible_surface); |
| 49 return true; | 42 return true; |
| 50 } | 43 } |
| 51 | 44 |
| 52 void GLContextVirtual::Destroy() { | 45 void GLContextVirtual::Destroy() { |
| 53 shared_context_->OnReleaseVirtuallyCurrent(this); | 46 shared_context_->OnReleaseVirtuallyCurrent(this); |
| 54 shared_context_ = NULL; | 47 shared_context_ = NULL; |
| 55 display_ = NULL; | |
| 56 } | 48 } |
| 57 | 49 |
| 58 bool GLContextVirtual::MakeCurrent(gfx::GLSurface* surface) { | 50 bool GLContextVirtual::MakeCurrent(gfx::GLSurface* surface) { |
| 59 if (decoder_.get()) | 51 if (decoder_.get()) |
| 60 return shared_context_->MakeVirtuallyCurrent(this, surface); | 52 return shared_context_->MakeVirtuallyCurrent(this, surface); |
| 61 | 53 |
| 62 LOG(ERROR) << "Trying to make virtual context current without decoder."; | 54 LOG(ERROR) << "Trying to make virtual context current without decoder."; |
| 63 return false; | 55 return false; |
| 64 } | 56 } |
| 65 | 57 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 gfx::ScopedSetGLToRealGLApi scoped_set_gl_api; | 120 gfx::ScopedSetGLToRealGLApi scoped_set_gl_api; |
| 129 GetGLStateRestorer()->RestoreState(NULL); | 121 GetGLStateRestorer()->RestoreState(NULL); |
| 130 shared_context_->SetStateWasDirtiedExternally(false); | 122 shared_context_->SetStateWasDirtiedExternally(false); |
| 131 } | 123 } |
| 132 | 124 |
| 133 GLContextVirtual::~GLContextVirtual() { | 125 GLContextVirtual::~GLContextVirtual() { |
| 134 Destroy(); | 126 Destroy(); |
| 135 } | 127 } |
| 136 | 128 |
| 137 } // namespace gpu | 129 } // namespace gpu |
| OLD | NEW |