OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "content/common/gpu/image_transport_surface_overlay_mac.h" | |
6 | |
7 #include "content/common/gpu/gpu_messages.h" | |
8 #include "ui/accelerated_widget_mac/surface_handle_types.h" | |
9 #include "ui/base/cocoa/animation_utils.h" | |
10 #include "ui/gfx/geometry/dip_util.h" | |
11 #include "ui/gl/gl_image_io_surface.h" | |
12 | |
13 namespace content { | |
14 | |
15 ImageTransportSurfaceOverlayMac::ImageTransportSurfaceOverlayMac( | |
16 GpuChannelManager* manager, | |
17 GpuCommandBufferStub* stub, | |
18 gfx::PluginWindowHandle handle) | |
19 : scale_factor_(1), pending_overlay_image_(NULL) { | |
20 helper_.reset(new ImageTransportHelper(this, manager, stub, handle)); | |
21 } | |
22 | |
23 ImageTransportSurfaceOverlayMac::~ImageTransportSurfaceOverlayMac() {} | |
24 | |
25 bool ImageTransportSurfaceOverlayMac::Initialize() { | |
26 if (!helper_->Initialize()) | |
27 return false; | |
28 | |
29 layer_.reset([[CALayer alloc] init]); | |
30 [layer_ setBackgroundColor:CGColorGetConstantColor(kCGColorBlack)]; | |
31 | |
32 base::scoped_nsobject<NSDictionary> dict([[NSDictionary alloc] init]); | |
33 CGSConnectionID connection_id = CGSMainConnectionID(); | |
34 ca_context_.reset( | |
35 [CAContext contextWithCGSConnection:connection_id options:dict]); | |
36 [ca_context_ retain]; | |
37 [ca_context_ setLayer:layer_]; | |
38 return true; | |
39 } | |
40 | |
41 void ImageTransportSurfaceOverlayMac::Destroy() {} | |
42 | |
43 bool ImageTransportSurfaceOverlayMac::IsOffscreen() { | |
44 return false; | |
45 } | |
46 | |
47 gfx::SwapResult ImageTransportSurfaceOverlayMac::SwapBuffers() { | |
48 TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::SwapBuffers"); | |
49 | |
50 // A flush is required to ensure that all content appears in the layer. | |
51 { | |
52 TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::glFlush"); | |
53 glFlush(); | |
54 } | |
55 | |
56 // There should exist only one overlay image, and it should cover the whole | |
57 // surface. | |
58 DCHECK(pending_overlay_image_); | |
59 { | |
60 TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::setContents"); | |
61 ScopedCAActionDisabler disabler; | |
62 gfx::Rect dip_bounds = gfx::ConvertRectToDIP( | |
63 scale_factor_, gfx::Rect(pixel_size_)); | |
64 gfx::RectF crop_rect(0, 0, 1, 1); | |
65 pending_overlay_image_->ScheduleOverlayPlane( | |
66 static_cast<gfx::AcceleratedWidget>(layer_.get()), | |
67 0, gfx::OVERLAY_TRANSFORM_NONE, dip_bounds, crop_rect); | |
68 pending_overlay_image_ = NULL; | |
69 } | |
70 | |
71 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | |
72 params.surface_handle = | |
73 ui::SurfaceHandleFromCAContextID([ca_context_ contextId]); | |
74 params.size = pixel_size_; | |
75 params.scale_factor = scale_factor_; | |
76 params.latency_info.swap(latency_info_); | |
77 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | |
78 return gfx::SwapResult::SWAP_ACK; | |
79 } | |
80 | |
81 gfx::SwapResult ImageTransportSurfaceOverlayMac::PostSubBuffer(int x, | |
82 int y, | |
83 int width, | |
84 int height) { | |
85 return SwapBuffers(); | |
86 } | |
87 | |
88 bool ImageTransportSurfaceOverlayMac::SupportsPostSubBuffer() { | |
89 return true; | |
90 } | |
91 | |
92 gfx::Size ImageTransportSurfaceOverlayMac::GetSize() { | |
93 return gfx::Size(); | |
94 } | |
95 | |
96 void* ImageTransportSurfaceOverlayMac::GetHandle() { | |
97 return NULL; | |
98 } | |
99 | |
100 bool ImageTransportSurfaceOverlayMac::ScheduleOverlayPlane( | |
101 int z_order, | |
102 gfx::OverlayTransform transform, | |
103 gfx::GLImage* image, | |
104 const gfx::Rect& bounds_rect, | |
105 const gfx::RectF& crop_rect) { | |
106 // For now we allow only the one full-surface overlay plane. | |
107 // TODO(ccameron): This will need to be updated when support for multiple | |
108 // planes is enabled. | |
109 DCHECK_EQ(z_order, 0); | |
110 DCHECK_EQ(bounds_rect.ToString(), gfx::Rect(pixel_size_).ToString()); | |
111 DCHECK_EQ(crop_rect.ToString(), gfx::RectF(0, 0, 1, 1).ToString()); | |
112 DCHECK_EQ(transform, gfx::OVERLAY_TRANSFORM_NONE); | |
113 DCHECK(!pending_overlay_image_); | |
114 pending_overlay_image_ = image; | |
ccameron
2015/07/22 05:26:22
So, is it legit to keep this weak pointer around u
| |
115 return true; | |
116 } | |
117 | |
118 bool ImageTransportSurfaceOverlayMac::IsSurfaceless() const { | |
119 return true; | |
120 } | |
121 | |
122 void ImageTransportSurfaceOverlayMac::OnBufferPresented( | |
123 const AcceleratedSurfaceMsg_BufferPresented_Params& params) {} | |
124 | |
125 void ImageTransportSurfaceOverlayMac::OnResize(gfx::Size pixel_size, | |
126 float scale_factor) { | |
127 pixel_size_ = pixel_size; | |
128 scale_factor_ = scale_factor; | |
129 } | |
130 | |
131 void ImageTransportSurfaceOverlayMac::SetLatencyInfo( | |
132 const std::vector<ui::LatencyInfo>& latency_info) { | |
133 for (size_t i = 0; i < latency_info.size(); i++) | |
134 latency_info_.push_back(latency_info[i]); | |
135 } | |
136 | |
137 void ImageTransportSurfaceOverlayMac::WakeUpGpu() {} | |
138 | |
139 } // namespace content | |
OLD | NEW |