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 23 matching lines...) Expand all Loading... |
34 #include "ui/base/cocoa/remote_layer_api.h" | 34 #include "ui/base/cocoa/remote_layer_api.h" |
35 #include "ui/base/ui_base_switches.h" | 35 #include "ui/base/ui_base_switches.h" |
36 #include "ui/gfx/geometry/rect_conversions.h" | 36 #include "ui/gfx/geometry/rect_conversions.h" |
37 #include "ui/gfx/swap_result.h" | 37 #include "ui/gfx/swap_result.h" |
38 #include "ui/gfx/transform.h" | 38 #include "ui/gfx/transform.h" |
39 #include "ui/gl/ca_renderer_layer_params.h" | 39 #include "ui/gl/ca_renderer_layer_params.h" |
40 #include "ui/gl/gl_context.h" | 40 #include "ui/gl/gl_context.h" |
41 #include "ui/gl/gl_fence.h" | 41 #include "ui/gl/gl_fence.h" |
42 #include "ui/gl/gl_image_io_surface.h" | 42 #include "ui/gl/gl_image_io_surface.h" |
43 #include "ui/gl/gpu_switching_manager.h" | 43 #include "ui/gl/gpu_switching_manager.h" |
44 #include "ui/gl/scoped_api.h" | |
45 #include "ui/gl/scoped_cgl.h" | 44 #include "ui/gl/scoped_cgl.h" |
46 | 45 |
47 namespace { | 46 namespace { |
48 | 47 |
49 void CheckGLErrors(const char* msg) { | 48 void CheckGLErrors(const char* msg) { |
50 GLenum gl_error; | 49 GLenum gl_error; |
51 while ((gl_error = glGetError()) != GL_NO_ERROR) { | 50 while ((gl_error = glGetError()) != GL_NO_ERROR) { |
52 LOG(ERROR) << "OpenGL error hit " << msg << ": " << gl_error; | 51 LOG(ERROR) << "OpenGL error hit " << msg << ": " << gl_error; |
53 } | 52 } |
54 } | 53 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 [CAContext contextWithCGSConnection:connection_id options:@{}] retain]); | 107 [CAContext contextWithCGSConnection:connection_id options:@{}] retain]); |
109 [fullscreen_low_power_ca_context_ setLayer: | 108 [fullscreen_low_power_ca_context_ setLayer: |
110 ca_layer_tree_coordinator_->GetFullscreenLowPowerLayerForDisplay()]; | 109 ca_layer_tree_coordinator_->GetFullscreenLowPowerLayerForDisplay()]; |
111 } | 110 } |
112 return true; | 111 return true; |
113 } | 112 } |
114 | 113 |
115 void ImageTransportSurfaceOverlayMac::Destroy() { | 114 void ImageTransportSurfaceOverlayMac::Destroy() { |
116 ca_layer_tree_coordinator_.reset(); | 115 ca_layer_tree_coordinator_.reset(); |
117 if (previous_frame_fence_) { | 116 if (previous_frame_fence_) { |
118 gl::ScopedSetGLToRealGLApi scoped_set_gl_api; | |
119 // Ensure we are using the context with which the fence was created. | 117 // Ensure we are using the context with which the fence was created. |
120 gl::ScopedCGLSetCurrentContext scoped_set_current(fence_context_obj_); | 118 gl::ScopedCGLSetCurrentContext scoped_set_current(fence_context_obj_); |
121 CheckGLErrors("Before destroy fence"); | 119 CheckGLErrors("Before destroy fence"); |
122 previous_frame_fence_.reset(); | 120 previous_frame_fence_.reset(); |
123 CheckGLErrors("After destroy fence"); | 121 CheckGLErrors("After destroy fence"); |
124 } | 122 } |
125 } | 123 } |
126 | 124 |
127 bool ImageTransportSurfaceOverlayMac::IsOffscreen() { | 125 bool ImageTransportSurfaceOverlayMac::IsOffscreen() { |
128 return false; | 126 return false; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 gfx::SwapResult ImageTransportSurfaceOverlayMac::SwapBuffersInternal( | 178 gfx::SwapResult ImageTransportSurfaceOverlayMac::SwapBuffersInternal( |
181 const gfx::Rect& pixel_damage_rect) { | 179 const gfx::Rect& pixel_damage_rect) { |
182 TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::SwapBuffersInternal"); | 180 TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::SwapBuffersInternal"); |
183 | 181 |
184 base::TimeTicks before_flush_time; | 182 base::TimeTicks before_flush_time; |
185 base::TimeTicks after_flush_before_commit_time; | 183 base::TimeTicks after_flush_before_commit_time; |
186 | 184 |
187 // If supported, use GLFence to ensure that we haven't gotten more than one | 185 // If supported, use GLFence to ensure that we haven't gotten more than one |
188 // frame ahead of GL. | 186 // frame ahead of GL. |
189 if (gl::GLFence::IsSupported()) { | 187 if (gl::GLFence::IsSupported()) { |
190 gl::ScopedSetGLToRealGLApi scoped_set_gl_api; | |
191 CheckGLErrors("Before fence/flush"); | 188 CheckGLErrors("Before fence/flush"); |
192 | 189 |
193 // If we have gotten more than one frame ahead of GL, wait for the previous | 190 // If we have gotten more than one frame ahead of GL, wait for the previous |
194 // frame to complete. | 191 // frame to complete. |
195 if (previous_frame_fence_) { | 192 if (previous_frame_fence_) { |
196 TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::ClientWait"); | 193 TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::ClientWait"); |
197 | 194 |
198 // Ensure we are using the context with which the fence was created. | 195 // Ensure we are using the context with which the fence was created. |
199 gl::ScopedCGLSetCurrentContext scoped_set_current(fence_context_obj_); | 196 gl::ScopedCGLSetCurrentContext scoped_set_current(fence_context_obj_); |
200 | 197 |
(...skipping 26 matching lines...) Expand all Loading... |
227 // A glFlush is necessary to ensure correct content appears. | 224 // A glFlush is necessary to ensure correct content appears. |
228 glFlush(); | 225 glFlush(); |
229 CheckGLErrors("After fence/flush"); | 226 CheckGLErrors("After fence/flush"); |
230 | 227 |
231 after_flush_before_commit_time = base::TimeTicks::Now(); | 228 after_flush_before_commit_time = base::TimeTicks::Now(); |
232 UMA_HISTOGRAM_TIMES("GPU.IOSurface.GLFlushTime", | 229 UMA_HISTOGRAM_TIMES("GPU.IOSurface.GLFlushTime", |
233 after_flush_before_commit_time - before_flush_time); | 230 after_flush_before_commit_time - before_flush_time); |
234 } else { | 231 } else { |
235 // GLFence isn't supported - issue a glFinish on each frame to ensure | 232 // GLFence isn't supported - issue a glFinish on each frame to ensure |
236 // there is backpressure from GL. | 233 // there is backpressure from GL. |
237 gl::ScopedSetGLToRealGLApi scoped_set_gl_api; | |
238 TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::glFinish"); | 234 TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::glFinish"); |
239 CheckGLErrors("Before finish"); | 235 CheckGLErrors("Before finish"); |
240 glFinish(); | 236 glFinish(); |
241 CheckGLErrors("After finish"); | 237 CheckGLErrors("After finish"); |
242 after_flush_before_commit_time = base::TimeTicks::Now(); | 238 after_flush_before_commit_time = base::TimeTicks::Now(); |
243 } | 239 } |
244 | 240 |
245 bool fullscreen_low_power_layer_valid = false; | 241 bool fullscreen_low_power_layer_valid = false; |
246 ca_layer_tree_coordinator_->CommitPendingTreesToCA( | 242 ca_layer_tree_coordinator_->CommitPendingTreesToCA( |
247 pixel_damage_rect, &fullscreen_low_power_layer_valid); | 243 pixel_damage_rect, &fullscreen_low_power_layer_valid); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 gl_renderer_id_ = context_renderer_id & kCGLRendererIDMatchingMask; | 384 gl_renderer_id_ = context_renderer_id & kCGLRendererIDMatchingMask; |
389 | 385 |
390 // Post a task holding a reference to the new GL context. The reason for | 386 // Post a task holding a reference to the new GL context. The reason for |
391 // this is to avoid creating-then-destroying the context for every image | 387 // this is to avoid creating-then-destroying the context for every image |
392 // transport surface that is observing the GPU switch. | 388 // transport surface that is observing the GPU switch. |
393 base::ThreadTaskRunnerHandle::Get()->PostTask( | 389 base::ThreadTaskRunnerHandle::Get()->PostTask( |
394 FROM_HERE, base::Bind(&IOSurfaceContextNoOp, context_on_new_gpu)); | 390 FROM_HERE, base::Bind(&IOSurfaceContextNoOp, context_on_new_gpu)); |
395 } | 391 } |
396 | 392 |
397 } // namespace gpu | 393 } // namespace gpu |
OLD | NEW |