Index: content/common/gpu/image_transport_surface_overlay_mac.mm |
diff --git a/content/common/gpu/image_transport_surface_overlay_mac.mm b/content/common/gpu/image_transport_surface_overlay_mac.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f2cca01a0de9c52365c071179ea9cd78024ffad8 |
--- /dev/null |
+++ b/content/common/gpu/image_transport_surface_overlay_mac.mm |
@@ -0,0 +1,139 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/common/gpu/image_transport_surface_overlay_mac.h" |
+ |
+#include "content/common/gpu/gpu_messages.h" |
+#include "ui/accelerated_widget_mac/surface_handle_types.h" |
+#include "ui/base/cocoa/animation_utils.h" |
+#include "ui/gfx/geometry/dip_util.h" |
+#include "ui/gl/gl_image_io_surface.h" |
+ |
+namespace content { |
+ |
+ImageTransportSurfaceOverlayMac::ImageTransportSurfaceOverlayMac( |
+ GpuChannelManager* manager, |
+ GpuCommandBufferStub* stub, |
+ gfx::PluginWindowHandle handle) |
+ : scale_factor_(1), pending_overlay_image_(NULL) { |
+ helper_.reset(new ImageTransportHelper(this, manager, stub, handle)); |
+} |
+ |
+ImageTransportSurfaceOverlayMac::~ImageTransportSurfaceOverlayMac() {} |
+ |
+bool ImageTransportSurfaceOverlayMac::Initialize() { |
+ if (!helper_->Initialize()) |
+ return false; |
+ |
+ layer_.reset([[CALayer alloc] init]); |
+ [layer_ setBackgroundColor:CGColorGetConstantColor(kCGColorBlack)]; |
+ |
+ base::scoped_nsobject<NSDictionary> dict([[NSDictionary alloc] init]); |
+ CGSConnectionID connection_id = CGSMainConnectionID(); |
+ ca_context_.reset( |
+ [CAContext contextWithCGSConnection:connection_id options:dict]); |
+ [ca_context_ retain]; |
+ [ca_context_ setLayer:layer_]; |
+ return true; |
+} |
+ |
+void ImageTransportSurfaceOverlayMac::Destroy() {} |
+ |
+bool ImageTransportSurfaceOverlayMac::IsOffscreen() { |
+ return false; |
+} |
+ |
+gfx::SwapResult ImageTransportSurfaceOverlayMac::SwapBuffers() { |
+ TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::SwapBuffers"); |
+ |
+ // A flush is required to ensure that all content appears in the layer. |
+ { |
+ TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::glFlush"); |
+ glFlush(); |
+ } |
+ |
+ // There should exist only one overlay image, and it should cover the whole |
+ // surface. |
+ DCHECK(pending_overlay_image_); |
+ { |
+ TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::setContents"); |
+ ScopedCAActionDisabler disabler; |
+ gfx::Rect dip_bounds = gfx::ConvertRectToDIP( |
+ scale_factor_, gfx::Rect(pixel_size_)); |
+ gfx::RectF crop_rect(0, 0, 1, 1); |
+ pending_overlay_image_->ScheduleOverlayPlane( |
+ static_cast<gfx::AcceleratedWidget>(layer_.get()), |
+ 0, gfx::OVERLAY_TRANSFORM_NONE, dip_bounds, crop_rect); |
+ pending_overlay_image_ = NULL; |
+ } |
+ |
+ GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; |
+ params.surface_handle = |
+ ui::SurfaceHandleFromCAContextID([ca_context_ contextId]); |
+ params.size = pixel_size_; |
+ params.scale_factor = scale_factor_; |
+ params.latency_info.swap(latency_info_); |
+ helper_->SendAcceleratedSurfaceBuffersSwapped(params); |
+ return gfx::SwapResult::SWAP_ACK; |
+} |
+ |
+gfx::SwapResult ImageTransportSurfaceOverlayMac::PostSubBuffer(int x, |
+ int y, |
+ int width, |
+ int height) { |
+ return SwapBuffers(); |
+} |
+ |
+bool ImageTransportSurfaceOverlayMac::SupportsPostSubBuffer() { |
+ return true; |
+} |
+ |
+gfx::Size ImageTransportSurfaceOverlayMac::GetSize() { |
+ return gfx::Size(); |
+} |
+ |
+void* ImageTransportSurfaceOverlayMac::GetHandle() { |
+ return NULL; |
+} |
+ |
+bool ImageTransportSurfaceOverlayMac::ScheduleOverlayPlane( |
+ int z_order, |
+ gfx::OverlayTransform transform, |
+ gfx::GLImage* image, |
+ const gfx::Rect& bounds_rect, |
+ const gfx::RectF& crop_rect) { |
+ // For now we allow only the one full-surface overlay plane. |
+ // TODO(ccameron): This will need to be updated when support for multiple |
+ // planes is enabled. |
+ DCHECK_EQ(z_order, 0); |
+ DCHECK_EQ(bounds_rect.ToString(), gfx::Rect(pixel_size_).ToString()); |
+ DCHECK_EQ(crop_rect.ToString(), gfx::RectF(0, 0, 1, 1).ToString()); |
+ DCHECK_EQ(transform, gfx::OVERLAY_TRANSFORM_NONE); |
+ DCHECK(!pending_overlay_image_); |
+ pending_overlay_image_ = image; |
ccameron
2015/07/22 05:26:22
So, is it legit to keep this weak pointer around u
|
+ return true; |
+} |
+ |
+bool ImageTransportSurfaceOverlayMac::IsSurfaceless() const { |
+ return true; |
+} |
+ |
+void ImageTransportSurfaceOverlayMac::OnBufferPresented( |
+ const AcceleratedSurfaceMsg_BufferPresented_Params& params) {} |
+ |
+void ImageTransportSurfaceOverlayMac::OnResize(gfx::Size pixel_size, |
+ float scale_factor) { |
+ pixel_size_ = pixel_size; |
+ scale_factor_ = scale_factor; |
+} |
+ |
+void ImageTransportSurfaceOverlayMac::SetLatencyInfo( |
+ const std::vector<ui::LatencyInfo>& latency_info) { |
+ for (size_t i = 0; i < latency_info.size(); i++) |
+ latency_info_.push_back(latency_info[i]); |
+} |
+ |
+void ImageTransportSurfaceOverlayMac::WakeUpGpu() {} |
+ |
+} // namespace content |