Add ICU message format support
[chromium-blink-merge.git] / content / common / gpu / image_transport_surface_overlay_mac.mm
blob1a528333529330c9b8872a8f6c71be59970c170b
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
3 // found in the LICENSE file.
5 #include "content/common/gpu/image_transport_surface_overlay_mac.h"
7 #include <OpenGL/gl.h>
9 #include "content/common/gpu/gpu_messages.h"
10 #include "ui/accelerated_widget_mac/surface_handle_types.h"
11 #include "ui/base/cocoa/animation_utils.h"
12 #include "ui/base/cocoa/remote_layer_api.h"
13 #include "ui/gfx/geometry/dip_util.h"
14 #include "ui/gl/gl_image_io_surface.h"
16 namespace content {
18 ImageTransportSurfaceOverlayMac::ImageTransportSurfaceOverlayMac(
19     GpuChannelManager* manager,
20     GpuCommandBufferStub* stub,
21     gfx::PluginWindowHandle handle)
22     : scale_factor_(1), pending_overlay_image_(nullptr) {
23   helper_.reset(new ImageTransportHelper(this, manager, stub, handle));
26 ImageTransportSurfaceOverlayMac::~ImageTransportSurfaceOverlayMac() {
27   gfx::GLImageIOSurface::SetLayerForWidget(widget_, nil);
30 bool ImageTransportSurfaceOverlayMac::Initialize() {
31   if (!helper_->Initialize())
32     return false;
34   // Create the CAContext to send this to the GPU process, and the layer for
35   // the context.
36   CGSConnectionID connection_id = CGSMainConnectionID();
37   ca_context_.reset(
38       [[CAContext contextWithCGSConnection:connection_id options:@{}] retain]);
39   layer_.reset([[CALayer alloc] init]);
40   [ca_context_ setLayer:layer_];
42   // Register the CALayer so that it can be picked up in GLImageIOSurface.
43   static intptr_t previous_widget = 0;
44   previous_widget += 1;
45   widget_ = reinterpret_cast<gfx::AcceleratedWidget>(previous_widget);
46   gfx::GLImageIOSurface::SetLayerForWidget(widget_, layer_);
48   return true;
51 void ImageTransportSurfaceOverlayMac::Destroy() {}
53 bool ImageTransportSurfaceOverlayMac::IsOffscreen() {
54   return false;
57 gfx::SwapResult ImageTransportSurfaceOverlayMac::SwapBuffers() {
58   TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::SwapBuffers");
60   // A flush is required to ensure that all content appears in the layer.
61   {
62     TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::glFlush");
63     glFlush();
64   }
66   // There should exist only one overlay image, and it should cover the whole
67   // surface.
68   DCHECK(pending_overlay_image_);
69   if (pending_overlay_image_) {
70     TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::setContents");
71     ScopedCAActionDisabler disabler;
72     gfx::Rect dip_bounds = gfx::ConvertRectToDIP(
73         scale_factor_, gfx::Rect(pixel_size_));
74     gfx::RectF crop_rect(0, 0, 1, 1);
75     pending_overlay_image_->ScheduleOverlayPlane(
76         widget_, 0, gfx::OVERLAY_TRANSFORM_NONE, dip_bounds, crop_rect);
77     pending_overlay_image_ = nullptr;
78   }
80   GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params;
81   params.surface_handle =
82       ui::SurfaceHandleFromCAContextID([ca_context_ contextId]);
83   params.size = pixel_size_;
84   params.scale_factor = scale_factor_;
85   params.latency_info.swap(latency_info_);
86   helper_->SendAcceleratedSurfaceBuffersSwapped(params);
87   return gfx::SwapResult::SWAP_ACK;
90 gfx::SwapResult ImageTransportSurfaceOverlayMac::PostSubBuffer(int x,
91                                                                int y,
92                                                                int width,
93                                                                int height) {
94   return SwapBuffers();
97 bool ImageTransportSurfaceOverlayMac::SupportsPostSubBuffer() {
98   return true;
101 gfx::Size ImageTransportSurfaceOverlayMac::GetSize() {
102   return gfx::Size();
105 void* ImageTransportSurfaceOverlayMac::GetHandle() {
106   return nullptr;
109 bool ImageTransportSurfaceOverlayMac::ScheduleOverlayPlane(
110     int z_order,
111     gfx::OverlayTransform transform,
112     gfx::GLImage* image,
113     const gfx::Rect& bounds_rect,
114     const gfx::RectF& crop_rect) {
115   // For now we allow only the one full-surface overlay plane.
116   // TODO(ccameron): This will need to be updated when support for multiple
117   // planes is enabled.
118   DCHECK_EQ(z_order, 0);
119   DCHECK_EQ(bounds_rect.ToString(), gfx::Rect(pixel_size_).ToString());
120   DCHECK_EQ(crop_rect.ToString(), gfx::RectF(0, 0, 1, 1).ToString());
121   DCHECK_EQ(transform, gfx::OVERLAY_TRANSFORM_NONE);
122   DCHECK(!pending_overlay_image_);
123   pending_overlay_image_ = image;
124   return true;
127 bool ImageTransportSurfaceOverlayMac::IsSurfaceless() const {
128   return true;
131 void ImageTransportSurfaceOverlayMac::OnBufferPresented(
132     const AcceleratedSurfaceMsg_BufferPresented_Params& params) {}
134 void ImageTransportSurfaceOverlayMac::OnResize(gfx::Size pixel_size,
135                                                float scale_factor) {
136   pixel_size_ = pixel_size;
137   scale_factor_ = scale_factor;
140 void ImageTransportSurfaceOverlayMac::SetLatencyInfo(
141     const std::vector<ui::LatencyInfo>& latency_info) {
142   latency_info_.insert(
143       latency_info_.end(), latency_info.begin(), latency_info.end());
146 void ImageTransportSurfaceOverlayMac::WakeUpGpu() {}
148 }  // namespace content