| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ipc/service/image_transport_surface_overlay_mac.h" | 5 #include "gpu/ipc/service/image_transport_surface_overlay_mac.h" |
| 6 | 6 |
| 7 #include <CoreGraphics/CoreGraphics.h> | 7 #include <CoreGraphics/CoreGraphics.h> |
| 8 #include <IOSurface/IOSurface.h> | 8 #include <IOSurface/IOSurface.h> |
| 9 #include <OpenGL/CGLRenderers.h> | 9 #include <OpenGL/CGLRenderers.h> |
| 10 #include <OpenGL/CGLTypes.h> | 10 #include <OpenGL/CGLTypes.h> |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 | 52 |
| 53 void IOSurfaceContextNoOp(scoped_refptr<ui::IOSurfaceContext>) { | 53 void IOSurfaceContextNoOp(scoped_refptr<ui::IOSurfaceContext>) { |
| 54 } | 54 } |
| 55 | 55 |
| 56 } // namespace | 56 } // namespace |
| 57 | 57 |
| 58 namespace gpu { | 58 namespace gpu { |
| 59 | 59 |
| 60 scoped_refptr<gfx::GLSurface> ImageTransportSurfaceCreateNativeSurface( | 60 scoped_refptr<gl::GLSurface> ImageTransportSurfaceCreateNativeSurface( |
| 61 GpuChannelManager* manager, | 61 GpuChannelManager* manager, |
| 62 GpuCommandBufferStub* stub, | 62 GpuCommandBufferStub* stub, |
| 63 SurfaceHandle handle) { | 63 SurfaceHandle handle) { |
| 64 return new ImageTransportSurfaceOverlayMac(stub, handle); | 64 return new ImageTransportSurfaceOverlayMac(stub, handle); |
| 65 } | 65 } |
| 66 | 66 |
| 67 ImageTransportSurfaceOverlayMac::ImageTransportSurfaceOverlayMac( | 67 ImageTransportSurfaceOverlayMac::ImageTransportSurfaceOverlayMac( |
| 68 GpuCommandBufferStub* stub, | 68 GpuCommandBufferStub* stub, |
| 69 SurfaceHandle handle) | 69 SurfaceHandle handle) |
| 70 : stub_(stub->AsWeakPtr()), | 70 : stub_(stub->AsWeakPtr()), |
| 71 handle_(handle), | 71 handle_(handle), |
| 72 use_remote_layer_api_(ui::RemoteLayerAPISupported()), | 72 use_remote_layer_api_(ui::RemoteLayerAPISupported()), |
| 73 scale_factor_(1), | 73 scale_factor_(1), |
| 74 gl_renderer_id_(0) { | 74 gl_renderer_id_(0) { |
| 75 ui::GpuSwitchingManager::GetInstance()->AddObserver(this); | 75 ui::GpuSwitchingManager::GetInstance()->AddObserver(this); |
| 76 ca_layer_tree_coordinator_.reset( | 76 ca_layer_tree_coordinator_.reset( |
| 77 new ui::CALayerTreeCoordinator(use_remote_layer_api_)); | 77 new ui::CALayerTreeCoordinator(use_remote_layer_api_)); |
| 78 } | 78 } |
| 79 | 79 |
| 80 ImageTransportSurfaceOverlayMac::~ImageTransportSurfaceOverlayMac() { | 80 ImageTransportSurfaceOverlayMac::~ImageTransportSurfaceOverlayMac() { |
| 81 ui::GpuSwitchingManager::GetInstance()->RemoveObserver(this); | 81 ui::GpuSwitchingManager::GetInstance()->RemoveObserver(this); |
| 82 if (stub_.get()) { | 82 if (stub_.get()) { |
| 83 stub_->SetLatencyInfoCallback( | 83 stub_->SetLatencyInfoCallback( |
| 84 base::Callback<void(const std::vector<ui::LatencyInfo>&)>()); | 84 base::Callback<void(const std::vector<ui::LatencyInfo>&)>()); |
| 85 } | 85 } |
| 86 Destroy(); | 86 Destroy(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 bool ImageTransportSurfaceOverlayMac::Initialize( | 89 bool ImageTransportSurfaceOverlayMac::Initialize(gl::GLSurface::Format format) { |
| 90 gfx::GLSurface::Format format) { | |
| 91 if (!stub_.get() || !stub_->decoder()) | 90 if (!stub_.get() || !stub_->decoder()) |
| 92 return false; | 91 return false; |
| 93 | 92 |
| 94 stub_->SetLatencyInfoCallback( | 93 stub_->SetLatencyInfoCallback( |
| 95 base::Bind(&ImageTransportSurfaceOverlayMac::SetLatencyInfo, | 94 base::Bind(&ImageTransportSurfaceOverlayMac::SetLatencyInfo, |
| 96 base::Unretained(this))); | 95 base::Unretained(this))); |
| 97 | 96 |
| 98 // Create the CAContext to send this to the GPU process, and the layer for | 97 // Create the CAContext to send this to the GPU process, and the layer for |
| 99 // the context. | 98 // the context. |
| 100 if (use_remote_layer_api_) { | 99 if (use_remote_layer_api_) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 129 gpu::SurfaceHandle surface_handle, | 128 gpu::SurfaceHandle surface_handle, |
| 130 CAContextID ca_context_id, | 129 CAContextID ca_context_id, |
| 131 bool fullscreen_low_power_ca_context_valid, | 130 bool fullscreen_low_power_ca_context_valid, |
| 132 CAContextID fullscreen_low_power_ca_context_id, | 131 CAContextID fullscreen_low_power_ca_context_id, |
| 133 const gfx::ScopedRefCountedIOSurfaceMachPort& io_surface, | 132 const gfx::ScopedRefCountedIOSurfaceMachPort& io_surface, |
| 134 const gfx::Size& size, | 133 const gfx::Size& size, |
| 135 float scale_factor, | 134 float scale_factor, |
| 136 std::vector<ui::LatencyInfo> latency_info) { | 135 std::vector<ui::LatencyInfo> latency_info) { |
| 137 // TRACE_EVENT for gpu tests: | 136 // TRACE_EVENT for gpu tests: |
| 138 TRACE_EVENT_INSTANT2("test_gpu", "SwapBuffers", TRACE_EVENT_SCOPE_THREAD, | 137 TRACE_EVENT_INSTANT2("test_gpu", "SwapBuffers", TRACE_EVENT_SCOPE_THREAD, |
| 139 "GLImpl", static_cast<int>(gfx::GetGLImplementation()), | 138 "GLImpl", static_cast<int>(gl::GetGLImplementation()), |
| 140 "width", size.width()); | 139 "width", size.width()); |
| 141 | 140 |
| 142 GpuCommandBufferMsg_SwapBuffersCompleted_Params params; | 141 GpuCommandBufferMsg_SwapBuffersCompleted_Params params; |
| 143 params.surface_handle = surface_handle; | 142 params.surface_handle = surface_handle; |
| 144 params.ca_context_id = ca_context_id; | 143 params.ca_context_id = ca_context_id; |
| 145 params.fullscreen_low_power_ca_context_valid = | 144 params.fullscreen_low_power_ca_context_valid = |
| 146 fullscreen_low_power_ca_context_valid; | 145 fullscreen_low_power_ca_context_valid; |
| 147 params.fullscreen_low_power_ca_context_id = | 146 params.fullscreen_low_power_ca_context_id = |
| 148 fullscreen_low_power_ca_context_id; | 147 fullscreen_low_power_ca_context_id; |
| 149 params.io_surface = io_surface; | 148 params.io_surface = io_surface; |
| 150 params.pixel_size = size; | 149 params.pixel_size = size; |
| 151 params.scale_factor = scale_factor; | 150 params.scale_factor = scale_factor; |
| 152 params.latency_info = std::move(latency_info); | 151 params.latency_info = std::move(latency_info); |
| 153 params.result = gfx::SwapResult::SWAP_ACK; | 152 params.result = gfx::SwapResult::SWAP_ACK; |
| 154 stub_->SendSwapBuffersCompleted(params); | 153 stub_->SendSwapBuffersCompleted(params); |
| 155 } | 154 } |
| 156 | 155 |
| 157 gfx::SwapResult ImageTransportSurfaceOverlayMac::SwapBuffersInternal( | 156 gfx::SwapResult ImageTransportSurfaceOverlayMac::SwapBuffersInternal( |
| 158 const gfx::Rect& pixel_damage_rect) { | 157 const gfx::Rect& pixel_damage_rect) { |
| 159 TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::SwapBuffersInternal"); | 158 TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::SwapBuffersInternal"); |
| 160 | 159 |
| 161 // A glFlush is necessary to ensure correct content appears. A glFinish | 160 // A glFlush is necessary to ensure correct content appears. A glFinish |
| 162 // appears empirically to be the best way to get maximum performance when | 161 // appears empirically to be the best way to get maximum performance when |
| 163 // GPU bound. | 162 // GPU bound. |
| 164 { | 163 { |
| 165 gfx::ScopedSetGLToRealGLApi scoped_set_gl_api; | 164 gl::ScopedSetGLToRealGLApi scoped_set_gl_api; |
| 166 TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::glFinish"); | 165 TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::glFinish"); |
| 167 CheckGLErrors("Before finish"); | 166 CheckGLErrors("Before finish"); |
| 168 glFinish(); | 167 glFinish(); |
| 169 CheckGLErrors("After finish"); | 168 CheckGLErrors("After finish"); |
| 170 } | 169 } |
| 171 | 170 |
| 172 base::TimeTicks finish_time = base::TimeTicks::Now(); | 171 base::TimeTicks finish_time = base::TimeTicks::Now(); |
| 173 | 172 |
| 174 bool fullscreen_low_power_layer_valid = false; | 173 bool fullscreen_low_power_layer_valid = false; |
| 175 ca_layer_tree_coordinator_->CommitPendingTreesToCA( | 174 ca_layer_tree_coordinator_->CommitPendingTreesToCA( |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 } | 226 } |
| 228 | 227 |
| 229 gfx::Size ImageTransportSurfaceOverlayMac::GetSize() { | 228 gfx::Size ImageTransportSurfaceOverlayMac::GetSize() { |
| 230 return gfx::Size(); | 229 return gfx::Size(); |
| 231 } | 230 } |
| 232 | 231 |
| 233 void* ImageTransportSurfaceOverlayMac::GetHandle() { | 232 void* ImageTransportSurfaceOverlayMac::GetHandle() { |
| 234 return nullptr; | 233 return nullptr; |
| 235 } | 234 } |
| 236 | 235 |
| 237 bool ImageTransportSurfaceOverlayMac::OnMakeCurrent(gfx::GLContext* context) { | 236 bool ImageTransportSurfaceOverlayMac::OnMakeCurrent(gl::GLContext* context) { |
| 238 // Ensure that the context is on the appropriate GL renderer. The GL renderer | 237 // Ensure that the context is on the appropriate GL renderer. The GL renderer |
| 239 // will generally only change when the GPU changes. | 238 // will generally only change when the GPU changes. |
| 240 if (gl_renderer_id_ && context) | 239 if (gl_renderer_id_ && context) |
| 241 context->share_group()->SetRendererID(gl_renderer_id_); | 240 context->share_group()->SetRendererID(gl_renderer_id_); |
| 242 return true; | 241 return true; |
| 243 } | 242 } |
| 244 | 243 |
| 245 bool ImageTransportSurfaceOverlayMac::ScheduleOverlayPlane( | 244 bool ImageTransportSurfaceOverlayMac::ScheduleOverlayPlane( |
| 246 int z_order, | 245 int z_order, |
| 247 gfx::OverlayTransform transform, | 246 gfx::OverlayTransform transform, |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 gl_renderer_id_ = context_renderer_id & kCGLRendererIDMatchingMask; | 316 gl_renderer_id_ = context_renderer_id & kCGLRendererIDMatchingMask; |
| 318 | 317 |
| 319 // Post a task holding a reference to the new GL context. The reason for | 318 // Post a task holding a reference to the new GL context. The reason for |
| 320 // this is to avoid creating-then-destroying the context for every image | 319 // this is to avoid creating-then-destroying the context for every image |
| 321 // transport surface that is observing the GPU switch. | 320 // transport surface that is observing the GPU switch. |
| 322 base::MessageLoop::current()->PostTask( | 321 base::MessageLoop::current()->PostTask( |
| 323 FROM_HERE, base::Bind(&IOSurfaceContextNoOp, context_on_new_gpu)); | 322 FROM_HERE, base::Bind(&IOSurfaceContextNoOp, context_on_new_gpu)); |
| 324 } | 323 } |
| 325 | 324 |
| 326 } // namespace gpu | 325 } // namespace gpu |
| OLD | NEW |