| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 } | 52 } |
| 53 } | 53 } |
| 54 | 54 |
| 55 void IOSurfaceContextNoOp(scoped_refptr<ui::IOSurfaceContext>) { | 55 void IOSurfaceContextNoOp(scoped_refptr<ui::IOSurfaceContext>) { |
| 56 } | 56 } |
| 57 | 57 |
| 58 } // namespace | 58 } // namespace |
| 59 | 59 |
| 60 namespace gpu { | 60 namespace gpu { |
| 61 | 61 |
| 62 scoped_refptr<gl::GLSurface> ImageTransportSurfaceCreateNativeSurface( | |
| 63 GpuChannelManager* manager, | |
| 64 GpuCommandBufferStub* stub, | |
| 65 SurfaceHandle handle) { | |
| 66 return new ImageTransportSurfaceOverlayMac(stub, handle); | |
| 67 } | |
| 68 | |
| 69 ImageTransportSurfaceOverlayMac::ImageTransportSurfaceOverlayMac( | 62 ImageTransportSurfaceOverlayMac::ImageTransportSurfaceOverlayMac( |
| 70 GpuCommandBufferStub* stub, | 63 GpuCommandBufferStub* stub) |
| 71 SurfaceHandle handle) | |
| 72 : stub_(stub->AsWeakPtr()), | 64 : stub_(stub->AsWeakPtr()), |
| 73 handle_(handle), | |
| 74 use_remote_layer_api_(ui::RemoteLayerAPISupported()), | 65 use_remote_layer_api_(ui::RemoteLayerAPISupported()), |
| 75 scale_factor_(1), | 66 scale_factor_(1), |
| 76 gl_renderer_id_(0) { | 67 gl_renderer_id_(0) { |
| 77 ui::GpuSwitchingManager::GetInstance()->AddObserver(this); | 68 ui::GpuSwitchingManager::GetInstance()->AddObserver(this); |
| 78 ca_layer_tree_coordinator_.reset( | 69 ca_layer_tree_coordinator_.reset( |
| 79 new ui::CALayerTreeCoordinator(use_remote_layer_api_)); | 70 new ui::CALayerTreeCoordinator(use_remote_layer_api_)); |
| 80 } | 71 } |
| 81 | 72 |
| 82 ImageTransportSurfaceOverlayMac::~ImageTransportSurfaceOverlayMac() { | 73 ImageTransportSurfaceOverlayMac::~ImageTransportSurfaceOverlayMac() { |
| 83 ui::GpuSwitchingManager::GetInstance()->RemoveObserver(this); | 74 ui::GpuSwitchingManager::GetInstance()->RemoveObserver(this); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 return false; | 119 return false; |
| 129 } | 120 } |
| 130 | 121 |
| 131 void ImageTransportSurfaceOverlayMac::SetLatencyInfo( | 122 void ImageTransportSurfaceOverlayMac::SetLatencyInfo( |
| 132 const std::vector<ui::LatencyInfo>& latency_info) { | 123 const std::vector<ui::LatencyInfo>& latency_info) { |
| 133 latency_info_.insert(latency_info_.end(), latency_info.begin(), | 124 latency_info_.insert(latency_info_.end(), latency_info.begin(), |
| 134 latency_info.end()); | 125 latency_info.end()); |
| 135 } | 126 } |
| 136 | 127 |
| 137 void ImageTransportSurfaceOverlayMac::SendAcceleratedSurfaceBuffersSwapped( | 128 void ImageTransportSurfaceOverlayMac::SendAcceleratedSurfaceBuffersSwapped( |
| 138 gpu::SurfaceHandle surface_handle, | |
| 139 CAContextID ca_context_id, | 129 CAContextID ca_context_id, |
| 140 bool fullscreen_low_power_ca_context_valid, | 130 bool fullscreen_low_power_ca_context_valid, |
| 141 CAContextID fullscreen_low_power_ca_context_id, | 131 CAContextID fullscreen_low_power_ca_context_id, |
| 142 const gfx::ScopedRefCountedIOSurfaceMachPort& io_surface, | 132 const gfx::ScopedRefCountedIOSurfaceMachPort& io_surface, |
| 143 const gfx::Size& size, | 133 const gfx::Size& size, |
| 144 float scale_factor, | 134 float scale_factor, |
| 145 std::vector<ui::LatencyInfo> latency_info) { | 135 std::vector<ui::LatencyInfo> latency_info) { |
| 146 // TRACE_EVENT for gpu tests: | 136 // TRACE_EVENT for gpu tests: |
| 147 TRACE_EVENT_INSTANT2("test_gpu", "SwapBuffers", TRACE_EVENT_SCOPE_THREAD, | 137 TRACE_EVENT_INSTANT2("test_gpu", "SwapBuffers", TRACE_EVENT_SCOPE_THREAD, |
| 148 "GLImpl", static_cast<int>(gl::GetGLImplementation()), | 138 "GLImpl", static_cast<int>(gl::GetGLImplementation()), |
| 149 "width", size.width()); | 139 "width", size.width()); |
| 150 | 140 |
| 151 GpuCommandBufferMsg_SwapBuffersCompleted_Params params; | 141 GpuCommandBufferMsg_SwapBuffersCompleted_Params params; |
| 152 params.surface_handle = surface_handle; | |
| 153 params.ca_context_id = ca_context_id; | 142 params.ca_context_id = ca_context_id; |
| 154 params.fullscreen_low_power_ca_context_valid = | 143 params.fullscreen_low_power_ca_context_valid = |
| 155 fullscreen_low_power_ca_context_valid; | 144 fullscreen_low_power_ca_context_valid; |
| 156 params.fullscreen_low_power_ca_context_id = | 145 params.fullscreen_low_power_ca_context_id = |
| 157 fullscreen_low_power_ca_context_id; | 146 fullscreen_low_power_ca_context_id; |
| 158 params.io_surface = io_surface; | 147 params.io_surface = io_surface; |
| 159 params.pixel_size = size; | 148 params.pixel_size = size; |
| 160 params.scale_factor = scale_factor; | 149 params.scale_factor = scale_factor; |
| 161 params.latency_info = std::move(latency_info); | 150 params.latency_info = std::move(latency_info); |
| 162 params.result = gfx::SwapResult::SWAP_ACK; | 151 params.result = gfx::SwapResult::SWAP_ACK; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 ca_context_id = [ca_context_ contextId]; | 259 ca_context_id = [ca_context_ contextId]; |
| 271 fullscreen_low_power_ca_context_id = | 260 fullscreen_low_power_ca_context_id = |
| 272 [fullscreen_low_power_ca_context_ contextId]; | 261 [fullscreen_low_power_ca_context_ contextId]; |
| 273 } else { | 262 } else { |
| 274 IOSurfaceRef io_surface = | 263 IOSurfaceRef io_surface = |
| 275 ca_layer_tree_coordinator_->GetIOSurfaceForDisplay(); | 264 ca_layer_tree_coordinator_->GetIOSurfaceForDisplay(); |
| 276 if (io_surface) | 265 if (io_surface) |
| 277 io_surface_mach_port.reset(IOSurfaceCreateMachPort(io_surface)); | 266 io_surface_mach_port.reset(IOSurfaceCreateMachPort(io_surface)); |
| 278 } | 267 } |
| 279 SendAcceleratedSurfaceBuffersSwapped( | 268 SendAcceleratedSurfaceBuffersSwapped( |
| 280 handle_, ca_context_id, fullscreen_low_power_layer_valid, | 269 ca_context_id, fullscreen_low_power_layer_valid, |
| 281 fullscreen_low_power_ca_context_id, io_surface_mach_port, pixel_size_, | 270 fullscreen_low_power_ca_context_id, io_surface_mach_port, pixel_size_, |
| 282 scale_factor_, std::move(latency_info_)); | 271 scale_factor_, std::move(latency_info_)); |
| 283 | 272 |
| 284 // Reset all state for the next frame. | 273 // Reset all state for the next frame. |
| 285 latency_info_.clear(); | 274 latency_info_.clear(); |
| 286 return gfx::SwapResult::SWAP_ACK; | 275 return gfx::SwapResult::SWAP_ACK; |
| 287 } | 276 } |
| 288 | 277 |
| 289 gfx::SwapResult ImageTransportSurfaceOverlayMac::SwapBuffers() { | 278 gfx::SwapResult ImageTransportSurfaceOverlayMac::SwapBuffers() { |
| 290 return SwapBuffersInternal( | 279 return SwapBuffersInternal( |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 gl_renderer_id_ = context_renderer_id & kCGLRendererIDMatchingMask; | 379 gl_renderer_id_ = context_renderer_id & kCGLRendererIDMatchingMask; |
| 391 | 380 |
| 392 // Post a task holding a reference to the new GL context. The reason for | 381 // Post a task holding a reference to the new GL context. The reason for |
| 393 // this is to avoid creating-then-destroying the context for every image | 382 // this is to avoid creating-then-destroying the context for every image |
| 394 // transport surface that is observing the GPU switch. | 383 // transport surface that is observing the GPU switch. |
| 395 base::ThreadTaskRunnerHandle::Get()->PostTask( | 384 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 396 FROM_HERE, base::Bind(&IOSurfaceContextNoOp, context_on_new_gpu)); | 385 FROM_HERE, base::Bind(&IOSurfaceContextNoOp, context_on_new_gpu)); |
| 397 } | 386 } |
| 398 | 387 |
| 399 } // namespace gpu | 388 } // namespace gpu |
| OLD | NEW |