| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 base::Bind(&ImageTransportSurfaceOverlayMac::SetLatencyInfo, | 100 base::Bind(&ImageTransportSurfaceOverlayMac::SetLatencyInfo, |
| 101 base::Unretained(this))); | 101 base::Unretained(this))); |
| 102 | 102 |
| 103 // Create the CAContext to send this to the GPU process, and the layer for | 103 // Create the CAContext to send this to the GPU process, and the layer for |
| 104 // the context. | 104 // the context. |
| 105 if (use_remote_layer_api_) { | 105 if (use_remote_layer_api_) { |
| 106 CGSConnectionID connection_id = CGSMainConnectionID(); | 106 CGSConnectionID connection_id = CGSMainConnectionID(); |
| 107 ca_context_.reset([ | 107 ca_context_.reset([ |
| 108 [CAContext contextWithCGSConnection:connection_id options:@{}] retain]); | 108 [CAContext contextWithCGSConnection:connection_id options:@{}] retain]); |
| 109 [ca_context_ setLayer:ca_layer_tree_coordinator_->GetCALayerForDisplay()]; | 109 [ca_context_ setLayer:ca_layer_tree_coordinator_->GetCALayerForDisplay()]; |
| 110 |
| 111 fullscreen_low_power_ca_context_.reset([ |
| 112 [CAContext contextWithCGSConnection:connection_id options:@{}] retain]); |
| 113 [fullscreen_low_power_ca_context_ setLayer: |
| 114 ca_layer_tree_coordinator_->GetFullscreenLowPowerLayerForDisplay()]; |
| 110 } | 115 } |
| 111 return true; | 116 return true; |
| 112 } | 117 } |
| 113 | 118 |
| 114 void ImageTransportSurfaceOverlayMac::Destroy() { | 119 void ImageTransportSurfaceOverlayMac::Destroy() { |
| 115 ca_layer_tree_coordinator_.reset(); | 120 ca_layer_tree_coordinator_.reset(); |
| 116 } | 121 } |
| 117 | 122 |
| 118 bool ImageTransportSurfaceOverlayMac::IsOffscreen() { | 123 bool ImageTransportSurfaceOverlayMac::IsOffscreen() { |
| 119 return false; | 124 return false; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 137 if (vsync_parameters_valid_) { | 142 if (vsync_parameters_valid_) { |
| 138 vsync_timebase_ -= | 143 vsync_timebase_ -= |
| 139 vsync_interval_ * | 144 vsync_interval_ * |
| 140 ((vsync_timebase_ - base::TimeTicks()) / vsync_interval_); | 145 ((vsync_timebase_ - base::TimeTicks()) / vsync_interval_); |
| 141 } | 146 } |
| 142 } | 147 } |
| 143 | 148 |
| 144 void ImageTransportSurfaceOverlayMac::SendAcceleratedSurfaceBuffersSwapped( | 149 void ImageTransportSurfaceOverlayMac::SendAcceleratedSurfaceBuffersSwapped( |
| 145 gpu::SurfaceHandle surface_handle, | 150 gpu::SurfaceHandle surface_handle, |
| 146 CAContextID ca_context_id, | 151 CAContextID ca_context_id, |
| 152 bool fullscreen_low_power_ca_context_valid, |
| 153 CAContextID fullscreen_low_power_ca_context_id, |
| 147 const gfx::ScopedRefCountedIOSurfaceMachPort& io_surface, | 154 const gfx::ScopedRefCountedIOSurfaceMachPort& io_surface, |
| 148 const gfx::Size& size, | 155 const gfx::Size& size, |
| 149 float scale_factor, | 156 float scale_factor, |
| 150 std::vector<ui::LatencyInfo> latency_info) { | 157 std::vector<ui::LatencyInfo> latency_info) { |
| 151 // TRACE_EVENT for gpu tests: | 158 // TRACE_EVENT for gpu tests: |
| 152 TRACE_EVENT_INSTANT2("test_gpu", "SwapBuffers", TRACE_EVENT_SCOPE_THREAD, | 159 TRACE_EVENT_INSTANT2("test_gpu", "SwapBuffers", TRACE_EVENT_SCOPE_THREAD, |
| 153 "GLImpl", static_cast<int>(gfx::GetGLImplementation()), | 160 "GLImpl", static_cast<int>(gfx::GetGLImplementation()), |
| 154 "width", size.width()); | 161 "width", size.width()); |
| 155 manager_->delegate()->SendAcceleratedSurfaceBuffersSwapped( | 162 manager_->delegate()->SendAcceleratedSurfaceBuffersSwapped( |
| 156 surface_handle, ca_context_id, io_surface, size, scale_factor, | 163 surface_handle, ca_context_id, fullscreen_low_power_ca_context_valid, |
| 164 fullscreen_low_power_ca_context_id, io_surface, size, scale_factor, |
| 157 std::move(latency_info)); | 165 std::move(latency_info)); |
| 158 } | 166 } |
| 159 | 167 |
| 160 gfx::SwapResult ImageTransportSurfaceOverlayMac::SwapBuffersInternal( | 168 gfx::SwapResult ImageTransportSurfaceOverlayMac::SwapBuffersInternal( |
| 161 const gfx::Rect& pixel_damage_rect) { | 169 const gfx::Rect& pixel_damage_rect) { |
| 162 TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::SwapBuffersInternal"); | 170 TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::SwapBuffersInternal"); |
| 163 | 171 |
| 164 // A glFlush is necessary to ensure correct content appears. A glFinish | 172 // A glFlush is necessary to ensure correct content appears. A glFinish |
| 165 // appears empirically to be the best way to get maximum performance when | 173 // appears empirically to be the best way to get maximum performance when |
| 166 // GPU bound. | 174 // GPU bound. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 184 for (auto latency_info : latency_info_) { | 192 for (auto latency_info : latency_info_) { |
| 185 latency_info.AddLatencyNumberWithTimestamp( | 193 latency_info.AddLatencyNumberWithTimestamp( |
| 186 ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT, 0, 0, finish_time, 1); | 194 ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT, 0, 0, finish_time, 1); |
| 187 latency_info.AddLatencyNumberWithTimestamp( | 195 latency_info.AddLatencyNumberWithTimestamp( |
| 188 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0, | 196 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0, |
| 189 finish_time, 1); | 197 finish_time, 1); |
| 190 } | 198 } |
| 191 | 199 |
| 192 // Send acknowledgement to the browser. | 200 // Send acknowledgement to the browser. |
| 193 CAContextID ca_context_id = 0; | 201 CAContextID ca_context_id = 0; |
| 202 CAContextID fullscreen_low_power_ca_context_id = 0; |
| 194 gfx::ScopedRefCountedIOSurfaceMachPort io_surface_mach_port; | 203 gfx::ScopedRefCountedIOSurfaceMachPort io_surface_mach_port; |
| 195 if (use_remote_layer_api_) { | 204 if (use_remote_layer_api_) { |
| 196 ca_context_id = [ca_context_ contextId]; | 205 ca_context_id = [ca_context_ contextId]; |
| 206 fullscreen_low_power_ca_context_id = |
| 207 [fullscreen_low_power_ca_context_ contextId]; |
| 197 } else { | 208 } else { |
| 198 IOSurfaceRef io_surface = | 209 IOSurfaceRef io_surface = |
| 199 ca_layer_tree_coordinator_->GetIOSurfaceForDisplay(); | 210 ca_layer_tree_coordinator_->GetIOSurfaceForDisplay(); |
| 200 if (io_surface) | 211 if (io_surface) |
| 201 io_surface_mach_port.reset(IOSurfaceCreateMachPort(io_surface)); | 212 io_surface_mach_port.reset(IOSurfaceCreateMachPort(io_surface)); |
| 202 } | 213 } |
| 203 SendAcceleratedSurfaceBuffersSwapped(handle_, ca_context_id, | 214 SendAcceleratedSurfaceBuffersSwapped( |
| 204 io_surface_mach_port, pixel_size_, | 215 handle_, ca_context_id, fullscreen_low_power_layer_valid, |
| 205 scale_factor_, std::move(latency_info_)); | 216 fullscreen_low_power_ca_context_id, io_surface_mach_port, pixel_size_, |
| 217 scale_factor_, std::move(latency_info_)); |
| 206 | 218 |
| 207 // Reset all state for the next frame. | 219 // Reset all state for the next frame. |
| 208 latency_info_.clear(); | 220 latency_info_.clear(); |
| 209 return gfx::SwapResult::SWAP_ACK; | 221 return gfx::SwapResult::SWAP_ACK; |
| 210 } | 222 } |
| 211 | 223 |
| 212 gfx::SwapResult ImageTransportSurfaceOverlayMac::SwapBuffers() { | 224 gfx::SwapResult ImageTransportSurfaceOverlayMac::SwapBuffers() { |
| 213 return SwapBuffersInternal( | 225 return SwapBuffersInternal( |
| 214 gfx::Rect(0, 0, pixel_size_.width(), pixel_size_.height())); | 226 gfx::Rect(0, 0, pixel_size_.width(), pixel_size_.height())); |
| 215 } | 227 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 gl_renderer_id_ = context_renderer_id & kCGLRendererIDMatchingMask; | 328 gl_renderer_id_ = context_renderer_id & kCGLRendererIDMatchingMask; |
| 317 | 329 |
| 318 // Post a task holding a reference to the new GL context. The reason for | 330 // Post a task holding a reference to the new GL context. The reason for |
| 319 // this is to avoid creating-then-destroying the context for every image | 331 // this is to avoid creating-then-destroying the context for every image |
| 320 // transport surface that is observing the GPU switch. | 332 // transport surface that is observing the GPU switch. |
| 321 base::MessageLoop::current()->PostTask( | 333 base::MessageLoop::current()->PostTask( |
| 322 FROM_HERE, base::Bind(&IOSurfaceContextNoOp, context_on_new_gpu)); | 334 FROM_HERE, base::Bind(&IOSurfaceContextNoOp, context_on_new_gpu)); |
| 323 } | 335 } |
| 324 | 336 |
| 325 } // namespace gpu | 337 } // namespace gpu |
| OLD | NEW |