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> |
11 #include <OpenGL/gl.h> | 11 #include <OpenGL/gl.h> |
12 #include <stddef.h> | 12 #include <stddef.h> |
13 | 13 |
14 #include <algorithm> | 14 #include <algorithm> |
15 | 15 |
16 // This type consistently causes problem on Mac, and needs to be dealt with | 16 // This type consistently causes problem on Mac, and needs to be dealt with |
17 // in a systemic way. | 17 // in a systemic way. |
18 // http://crbug.com/517208 | 18 // http://crbug.com/517208 |
19 #ifndef GL_OES_EGL_image | 19 #ifndef GL_OES_EGL_image |
20 typedef void* GLeglImageOES; | 20 typedef void* GLeglImageOES; |
21 #endif | 21 #endif |
22 | 22 |
23 #include "base/bind.h" | 23 #include "base/bind.h" |
24 #include "base/bind_helpers.h" | 24 #include "base/bind_helpers.h" |
| 25 #include "base/mac/scoped_cftyperef.h" |
25 #include "base/trace_event/trace_event.h" | 26 #include "base/trace_event/trace_event.h" |
26 #include "gpu/ipc/common/gpu_messages.h" | 27 #include "gpu/ipc/common/gpu_messages.h" |
27 #include "gpu/ipc/service/gpu_channel_manager.h" | 28 #include "gpu/ipc/service/gpu_channel_manager.h" |
28 #include "gpu/ipc/service/gpu_channel_manager_delegate.h" | 29 #include "gpu/ipc/service/gpu_channel_manager_delegate.h" |
29 #include "ui/accelerated_widget_mac/ca_layer_tree_coordinator.h" | 30 #include "ui/accelerated_widget_mac/ca_layer_tree_coordinator.h" |
30 #include "ui/accelerated_widget_mac/io_surface_context.h" | 31 #include "ui/accelerated_widget_mac/io_surface_context.h" |
31 #include "ui/base/cocoa/animation_utils.h" | 32 #include "ui/base/cocoa/animation_utils.h" |
32 #include "ui/base/cocoa/remote_layer_api.h" | 33 #include "ui/base/cocoa/remote_layer_api.h" |
33 #include "ui/gfx/geometry/rect_conversions.h" | 34 #include "ui/gfx/geometry/rect_conversions.h" |
34 #include "ui/gfx/swap_result.h" | 35 #include "ui/gfx/swap_result.h" |
35 #include "ui/gfx/transform.h" | 36 #include "ui/gfx/transform.h" |
36 #include "ui/gl/ca_renderer_layer_params.h" | |
37 #include "ui/gl/gl_context.h" | 37 #include "ui/gl/gl_context.h" |
38 #include "ui/gl/gl_fence.h" | 38 #include "ui/gl/gl_fence.h" |
39 #include "ui/gl/gl_image_io_surface.h" | 39 #include "ui/gl/gl_image_io_surface.h" |
40 #include "ui/gl/gpu_switching_manager.h" | 40 #include "ui/gl/gpu_switching_manager.h" |
41 #include "ui/gl/scoped_api.h" | 41 #include "ui/gl/scoped_api.h" |
42 #include "ui/gl/scoped_cgl.h" | 42 #include "ui/gl/scoped_cgl.h" |
43 | 43 |
44 namespace { | 44 namespace { |
45 | 45 |
46 void CheckGLErrors(const char* msg) { | 46 void CheckGLErrors(const char* msg) { |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 gl::GLImageIOSurface::FromGLImage(image); | 324 gl::GLImageIOSurface::FromGLImage(image); |
325 if (!io_surface_image) { | 325 if (!io_surface_image) { |
326 DLOG(ERROR) << "Not an IOSurface image."; | 326 DLOG(ERROR) << "Not an IOSurface image."; |
327 return false; | 327 return false; |
328 } | 328 } |
329 return ca_layer_tree_coordinator_->SetPendingGLRendererBackbuffer( | 329 return ca_layer_tree_coordinator_->SetPendingGLRendererBackbuffer( |
330 io_surface_image->io_surface()); | 330 io_surface_image->io_surface()); |
331 } | 331 } |
332 | 332 |
333 bool ImageTransportSurfaceOverlayMac::ScheduleCALayer( | 333 bool ImageTransportSurfaceOverlayMac::ScheduleCALayer( |
334 const ui::CARendererLayerParams& params) { | 334 gl::GLImage* contents_image, |
335 gl::GLImageIOSurface* io_surface_image = | 335 const gfx::RectF& contents_rect, |
336 gl::GLImageIOSurface::FromGLImage(params.image); | 336 float opacity, |
337 if (!io_surface_image) { | 337 unsigned background_color, |
338 DLOG(ERROR) << "Cannot schedule CALayer with non-IOSurface GLImage"; | 338 unsigned edge_aa_mask, |
339 return false; | 339 const gfx::RectF& rect, |
| 340 bool is_clipped, |
| 341 const gfx::RectF& clip_rect, |
| 342 const gfx::Transform& transform, |
| 343 int sorting_context_id, |
| 344 unsigned filter) { |
| 345 base::ScopedCFTypeRef<IOSurfaceRef> io_surface; |
| 346 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer; |
| 347 if (contents_image) { |
| 348 gl::GLImageIOSurface* io_surface_image = |
| 349 gl::GLImageIOSurface::FromGLImage(contents_image); |
| 350 if (!io_surface_image) { |
| 351 DLOG(ERROR) << "Cannot schedule CALayer with non-IOSurface GLImage"; |
| 352 return false; |
| 353 } |
| 354 io_surface = io_surface_image->io_surface(); |
| 355 cv_pixel_buffer = io_surface_image->cv_pixel_buffer(); |
340 } | 356 } |
341 return ca_layer_tree_coordinator_->GetPendingCARendererLayerTree() | 357 return ca_layer_tree_coordinator_->GetPendingCARendererLayerTree() |
342 ->ScheduleCALayer(params); | 358 ->ScheduleCALayer(is_clipped, gfx::ToEnclosingRect(clip_rect), |
| 359 sorting_context_id, transform, io_surface, |
| 360 cv_pixel_buffer, contents_rect, |
| 361 gfx::ToEnclosingRect(rect), background_color, |
| 362 edge_aa_mask, opacity, filter); |
343 } | 363 } |
344 | 364 |
345 void ImageTransportSurfaceOverlayMac::ScheduleCALayerInUseQuery( | 365 void ImageTransportSurfaceOverlayMac::ScheduleCALayerInUseQuery( |
346 std::vector<CALayerInUseQuery> queries) { | 366 std::vector<CALayerInUseQuery> queries) { |
347 ca_layer_in_use_queries_.swap(queries); | 367 ca_layer_in_use_queries_.swap(queries); |
348 } | 368 } |
349 | 369 |
350 bool ImageTransportSurfaceOverlayMac::IsSurfaceless() const { | 370 bool ImageTransportSurfaceOverlayMac::IsSurfaceless() const { |
351 return true; | 371 return true; |
352 } | 372 } |
(...skipping 23 matching lines...) Expand all Loading... |
376 gl_renderer_id_ = context_renderer_id & kCGLRendererIDMatchingMask; | 396 gl_renderer_id_ = context_renderer_id & kCGLRendererIDMatchingMask; |
377 | 397 |
378 // Post a task holding a reference to the new GL context. The reason for | 398 // Post a task holding a reference to the new GL context. The reason for |
379 // this is to avoid creating-then-destroying the context for every image | 399 // this is to avoid creating-then-destroying the context for every image |
380 // transport surface that is observing the GPU switch. | 400 // transport surface that is observing the GPU switch. |
381 base::MessageLoop::current()->PostTask( | 401 base::MessageLoop::current()->PostTask( |
382 FROM_HERE, base::Bind(&IOSurfaceContextNoOp, context_on_new_gpu)); | 402 FROM_HERE, base::Bind(&IOSurfaceContextNoOp, context_on_new_gpu)); |
383 } | 403 } |
384 | 404 |
385 } // namespace gpu | 405 } // namespace gpu |
OLD | NEW |