| 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 "base/callback.h" | 7 #include "base/callback.h" | 
| 8 #include "gpu/command_buffer/service/gl_state_restorer_impl.h" | 8 #include "gpu/command_buffer/service/gl_state_restorer_impl.h" | 
| 9 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 9 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 
| 10 #include "ui/gl/gl_gl_api_implementation.h" | 10 #include "ui/gl/gl_gl_api_implementation.h" | 
| 11 #include "ui/gl/gl_surface.h" | 11 #include "ui/gl/gl_surface.h" | 
| 12 #include "ui/gl/gpu_preference.h" | 12 #include "ui/gl/gpu_preference.h" | 
| 13 #include "ui/gl/gpu_timing.h" | 13 #include "ui/gl/gpu_timing.h" | 
| 14 #include "ui/gl/scoped_api.h" | 14 #include "ui/gl/scoped_api.h" | 
| 15 | 15 | 
| 16 namespace gpu { | 16 namespace gpu { | 
| 17 | 17 | 
| 18 GLContextVirtual::GLContextVirtual( | 18 GLContextVirtual::GLContextVirtual(gl::GLShareGroup* share_group, | 
| 19     gfx::GLShareGroup* share_group, | 19                                    gl::GLContext* shared_context, | 
| 20     gfx::GLContext* shared_context, | 20                                    base::WeakPtr<gles2::GLES2Decoder> decoder) | 
| 21     base::WeakPtr<gles2::GLES2Decoder> decoder) | 21     : GLContext(share_group), | 
| 22   : GLContext(share_group), | 22       shared_context_(shared_context), | 
| 23     shared_context_(shared_context), | 23       decoder_(decoder) {} | 
| 24     decoder_(decoder) { |  | 
| 25 } |  | 
| 26 | 24 | 
| 27 bool GLContextVirtual::Initialize( | 25 bool GLContextVirtual::Initialize(gl::GLSurface* compatible_surface, | 
| 28     gfx::GLSurface* compatible_surface, gfx::GpuPreference gpu_preference) { | 26                                   gl::GpuPreference gpu_preference) { | 
| 29   SetGLStateRestorer(new GLStateRestorerImpl(decoder_)); | 27   SetGLStateRestorer(new GLStateRestorerImpl(decoder_)); | 
| 30 | 28 | 
| 31   // Virtual contexts obviously can't make a context that is compatible | 29   // Virtual contexts obviously can't make a context that is compatible | 
| 32   // with the surface (the context already exists), but we do need to | 30   // with the surface (the context already exists), but we do need to | 
| 33   // make a context current for SetupForVirtualization() below. | 31   // make a context current for SetupForVirtualization() below. | 
| 34   if (!IsCurrent(compatible_surface)) { | 32   if (!IsCurrent(compatible_surface)) { | 
| 35     if (!shared_context_->MakeCurrent(compatible_surface)) { | 33     if (!shared_context_->MakeCurrent(compatible_surface)) { | 
| 36       // This is likely an error. The real context should be made as | 34       // This is likely an error. The real context should be made as | 
| 37       // compatible with all required surfaces when it was created. | 35       // compatible with all required surfaces when it was created. | 
| 38       LOG(ERROR) << "Failed MakeCurrent(compatible_surface)"; | 36       LOG(ERROR) << "Failed MakeCurrent(compatible_surface)"; | 
| 39       return false; | 37       return false; | 
| 40     } | 38     } | 
| 41   } | 39   } | 
| 42 | 40 | 
| 43   shared_context_->SetupForVirtualization(); | 41   shared_context_->SetupForVirtualization(); | 
| 44   shared_context_->MakeVirtuallyCurrent(this, compatible_surface); | 42   shared_context_->MakeVirtuallyCurrent(this, compatible_surface); | 
| 45   return true; | 43   return true; | 
| 46 } | 44 } | 
| 47 | 45 | 
| 48 void GLContextVirtual::Destroy() { | 46 void GLContextVirtual::Destroy() { | 
| 49   shared_context_->OnReleaseVirtuallyCurrent(this); | 47   shared_context_->OnReleaseVirtuallyCurrent(this); | 
| 50   shared_context_ = NULL; | 48   shared_context_ = NULL; | 
| 51 } | 49 } | 
| 52 | 50 | 
| 53 bool GLContextVirtual::MakeCurrent(gfx::GLSurface* surface) { | 51 bool GLContextVirtual::MakeCurrent(gl::GLSurface* surface) { | 
| 54   if (decoder_.get()) | 52   if (decoder_.get()) | 
| 55     return shared_context_->MakeVirtuallyCurrent(this, surface); | 53     return shared_context_->MakeVirtuallyCurrent(this, surface); | 
| 56 | 54 | 
| 57   LOG(ERROR) << "Trying to make virtual context current without decoder."; | 55   LOG(ERROR) << "Trying to make virtual context current without decoder."; | 
| 58   return false; | 56   return false; | 
| 59 } | 57 } | 
| 60 | 58 | 
| 61 void GLContextVirtual::ReleaseCurrent(gfx::GLSurface* surface) { | 59 void GLContextVirtual::ReleaseCurrent(gl::GLSurface* surface) { | 
| 62   if (IsCurrent(surface)) { | 60   if (IsCurrent(surface)) { | 
| 63     shared_context_->OnReleaseVirtuallyCurrent(this); | 61     shared_context_->OnReleaseVirtuallyCurrent(this); | 
| 64     shared_context_->ReleaseCurrent(surface); | 62     shared_context_->ReleaseCurrent(surface); | 
| 65   } | 63   } | 
| 66 } | 64 } | 
| 67 | 65 | 
| 68 bool GLContextVirtual::IsCurrent(gfx::GLSurface* surface) { | 66 bool GLContextVirtual::IsCurrent(gl::GLSurface* surface) { | 
| 69   // If it's a real surface it needs to be current. | 67   // If it's a real surface it needs to be current. | 
| 70   if (surface && | 68   if (surface && | 
| 71       !surface->IsOffscreen()) | 69       !surface->IsOffscreen()) | 
| 72     return shared_context_->IsCurrent(surface); | 70     return shared_context_->IsCurrent(surface); | 
| 73 | 71 | 
| 74   // Otherwise, only insure the context itself is current. | 72   // Otherwise, only insure the context itself is current. | 
| 75   return shared_context_->IsCurrent(NULL); | 73   return shared_context_->IsCurrent(NULL); | 
| 76 } | 74 } | 
| 77 | 75 | 
| 78 void* GLContextVirtual::GetHandle() { | 76 void* GLContextVirtual::GetHandle() { | 
| 79   return shared_context_->GetHandle(); | 77   return shared_context_->GetHandle(); | 
| 80 } | 78 } | 
| 81 | 79 | 
| 82 scoped_refptr<gfx::GPUTimingClient> GLContextVirtual::CreateGPUTimingClient() { | 80 scoped_refptr<gl::GPUTimingClient> GLContextVirtual::CreateGPUTimingClient() { | 
| 83   return shared_context_->CreateGPUTimingClient(); | 81   return shared_context_->CreateGPUTimingClient(); | 
| 84 } | 82 } | 
| 85 | 83 | 
| 86 void GLContextVirtual::OnSetSwapInterval(int interval) { | 84 void GLContextVirtual::OnSetSwapInterval(int interval) { | 
| 87   shared_context_->SetSwapInterval(interval); | 85   shared_context_->SetSwapInterval(interval); | 
| 88 } | 86 } | 
| 89 | 87 | 
| 90 std::string GLContextVirtual::GetExtensions() { | 88 std::string GLContextVirtual::GetExtensions() { | 
| 91   return shared_context_->GetExtensions(); | 89   return shared_context_->GetExtensions(); | 
| 92 } | 90 } | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
| 108 | 106 | 
| 109 gl::YUVToRGBConverter* GLContextVirtual::GetYUVToRGBConverter() { | 107 gl::YUVToRGBConverter* GLContextVirtual::GetYUVToRGBConverter() { | 
| 110   return shared_context_->GetYUVToRGBConverter(); | 108   return shared_context_->GetYUVToRGBConverter(); | 
| 111 } | 109 } | 
| 112 | 110 | 
| 113 GLContextVirtual::~GLContextVirtual() { | 111 GLContextVirtual::~GLContextVirtual() { | 
| 114   Destroy(); | 112   Destroy(); | 
| 115 } | 113 } | 
| 116 | 114 | 
| 117 }  // namespace gpu | 115 }  // namespace gpu | 
| OLD | NEW | 
|---|