Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Side by Side Diff: gpu/ipc/service/image_transport_surface_overlay_mac.mm

Issue 1917723002: Move logic from ImageTransportSurfaceOverlayMac into ui/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix grammar Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/mac/scoped_cftyperef.h"
26 #include "base/trace_event/trace_event.h" 26 #include "base/trace_event/trace_event.h"
27 #include "gpu/ipc/service/gpu_channel_manager.h" 27 #include "gpu/ipc/service/gpu_channel_manager.h"
28 #include "gpu/ipc/service/gpu_channel_manager_delegate.h" 28 #include "gpu/ipc/service/gpu_channel_manager_delegate.h"
29 #include "ui/accelerated_widget_mac/ca_layer_partial_damage_tree_mac.h" 29 #include "ui/accelerated_widget_mac/ca_layer_tree_coordinator.h"
30 #include "ui/accelerated_widget_mac/ca_layer_tree_mac.h"
31 #include "ui/accelerated_widget_mac/io_surface_context.h" 30 #include "ui/accelerated_widget_mac/io_surface_context.h"
32 #include "ui/base/cocoa/animation_utils.h" 31 #include "ui/base/cocoa/animation_utils.h"
33 #include "ui/base/cocoa/remote_layer_api.h" 32 #include "ui/base/cocoa/remote_layer_api.h"
34 #include "ui/gfx/geometry/rect_conversions.h" 33 #include "ui/gfx/geometry/rect_conversions.h"
35 #include "ui/gfx/transform.h" 34 #include "ui/gfx/transform.h"
36 #include "ui/gl/gl_context.h" 35 #include "ui/gl/gl_context.h"
37 #include "ui/gl/gl_fence.h" 36 #include "ui/gl/gl_fence.h"
38 #include "ui/gl/gl_image_io_surface.h" 37 #include "ui/gl/gl_image_io_surface.h"
39 #include "ui/gl/gpu_switching_manager.h" 38 #include "ui/gl/gpu_switching_manager.h"
40 #include "ui/gl/scoped_api.h" 39 #include "ui/gl/scoped_api.h"
(...skipping 30 matching lines...) Expand all
71 stub_(stub->AsWeakPtr()), 70 stub_(stub->AsWeakPtr()),
72 handle_(handle), 71 handle_(handle),
73 use_remote_layer_api_(ui::RemoteLayerAPISupported()), 72 use_remote_layer_api_(ui::RemoteLayerAPISupported()),
74 scale_factor_(1), 73 scale_factor_(1),
75 gl_renderer_id_(0), 74 gl_renderer_id_(0),
76 vsync_parameters_valid_(false) { 75 vsync_parameters_valid_(false) {
77 manager_->AddBufferPresentedCallback( 76 manager_->AddBufferPresentedCallback(
78 handle_, base::Bind(&ImageTransportSurfaceOverlayMac::BufferPresented, 77 handle_, base::Bind(&ImageTransportSurfaceOverlayMac::BufferPresented,
79 base::Unretained(this))); 78 base::Unretained(this)));
80 ui::GpuSwitchingManager::GetInstance()->AddObserver(this); 79 ui::GpuSwitchingManager::GetInstance()->AddObserver(this);
80 ca_layer_tree_coordinator_.reset(
81 new ui::CALayerTreeCoordinator(use_remote_layer_api_));
81 } 82 }
82 83
83 ImageTransportSurfaceOverlayMac::~ImageTransportSurfaceOverlayMac() { 84 ImageTransportSurfaceOverlayMac::~ImageTransportSurfaceOverlayMac() {
84 ui::GpuSwitchingManager::GetInstance()->RemoveObserver(this); 85 ui::GpuSwitchingManager::GetInstance()->RemoveObserver(this);
85 if (stub_.get()) { 86 if (stub_.get()) {
86 stub_->SetLatencyInfoCallback( 87 stub_->SetLatencyInfoCallback(
87 base::Callback<void(const std::vector<ui::LatencyInfo>&)>()); 88 base::Callback<void(const std::vector<ui::LatencyInfo>&)>());
88 } 89 }
89 Destroy(); 90 Destroy();
90 manager_->RemoveBufferPresentedCallback(handle_); 91 manager_->RemoveBufferPresentedCallback(handle_);
91 } 92 }
92 93
93 bool ImageTransportSurfaceOverlayMac::Initialize( 94 bool ImageTransportSurfaceOverlayMac::Initialize(
94 gfx::GLSurface::Format format) { 95 gfx::GLSurface::Format format) {
95 if (!stub_.get() || !stub_->decoder()) 96 if (!stub_.get() || !stub_->decoder())
96 return false; 97 return false;
97 98
98 stub_->SetLatencyInfoCallback( 99 stub_->SetLatencyInfoCallback(
99 base::Bind(&ImageTransportSurfaceOverlayMac::SetLatencyInfo, 100 base::Bind(&ImageTransportSurfaceOverlayMac::SetLatencyInfo,
100 base::Unretained(this))); 101 base::Unretained(this)));
101 102
102 // Create the CAContext to send this to the GPU process, and the layer for 103 // Create the CAContext to send this to the GPU process, and the layer for
103 // the context. 104 // the context.
104 if (use_remote_layer_api_) { 105 if (use_remote_layer_api_) {
105 CGSConnectionID connection_id = CGSMainConnectionID(); 106 CGSConnectionID connection_id = CGSMainConnectionID();
106 ca_context_.reset([ 107 ca_context_.reset([
107 [CAContext contextWithCGSConnection:connection_id options:@{}] retain]); 108 [CAContext contextWithCGSConnection:connection_id options:@{}] retain]);
108 ca_root_layer_.reset([[CALayer alloc] init]); 109 [ca_context_ setLayer:ca_layer_tree_coordinator_->GetCALayerForDisplay()];
109 [ca_root_layer_ setGeometryFlipped:YES];
110 [ca_root_layer_ setOpaque:YES];
111 [ca_context_ setLayer:ca_root_layer_];
112 } 110 }
113 return true; 111 return true;
114 } 112 }
115 113
116 void ImageTransportSurfaceOverlayMac::Destroy() { 114 void ImageTransportSurfaceOverlayMac::Destroy() {
117 current_partial_damage_tree_.reset(); 115 ca_layer_tree_coordinator_.reset();
118 current_ca_layer_tree_.reset();
119 } 116 }
120 117
121 bool ImageTransportSurfaceOverlayMac::IsOffscreen() { 118 bool ImageTransportSurfaceOverlayMac::IsOffscreen() {
122 return false; 119 return false;
123 } 120 }
124 121
125 void ImageTransportSurfaceOverlayMac::SetLatencyInfo( 122 void ImageTransportSurfaceOverlayMac::SetLatencyInfo(
126 const std::vector<ui::LatencyInfo>& latency_info) { 123 const std::vector<ui::LatencyInfo>& latency_info) {
127 latency_info_.insert(latency_info_.end(), latency_info.begin(), 124 latency_info_.insert(latency_info_.end(), latency_info.begin(),
128 latency_info.end()); 125 latency_info.end());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 { 169 {
173 gfx::ScopedSetGLToRealGLApi scoped_set_gl_api; 170 gfx::ScopedSetGLToRealGLApi scoped_set_gl_api;
174 TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::glFinish"); 171 TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::glFinish");
175 CheckGLErrors("Before finish"); 172 CheckGLErrors("Before finish");
176 glFinish(); 173 glFinish();
177 CheckGLErrors("After finish"); 174 CheckGLErrors("After finish");
178 } 175 }
179 176
180 base::TimeTicks finish_time = base::TimeTicks::Now(); 177 base::TimeTicks finish_time = base::TimeTicks::Now();
181 178
182 // Update the CALayer hierarchy. 179 ca_layer_tree_coordinator_->CommitPendingTreesToCA(pixel_damage_rect);
183 {
184 ScopedCAActionDisabler disabler;
185 if (pending_ca_layer_tree_) {
186 pending_ca_layer_tree_->CommitScheduledCALayers(
187 ca_root_layer_.get(), std::move(current_ca_layer_tree_),
188 scale_factor_);
189 current_ca_layer_tree_.swap(pending_ca_layer_tree_);
190 current_partial_damage_tree_.reset();
191 } else if (pending_partial_damage_tree_) {
192 pending_partial_damage_tree_->CommitCALayers(
193 ca_root_layer_.get(), std::move(current_partial_damage_tree_),
194 scale_factor_, pixel_damage_rect);
195 current_partial_damage_tree_.swap(pending_partial_damage_tree_);
196 current_ca_layer_tree_.reset();
197 } else {
198 TRACE_EVENT0("gpu", "Blank frame: No overlays or CALayers");
199 [ca_root_layer_ setSublayers:nil];
200 current_partial_damage_tree_.reset();
201 current_ca_layer_tree_.reset();
202 }
203 }
204 180
205 // Update the latency info to reflect the swap time. 181 // Update the latency info to reflect the swap time.
206 for (auto latency_info : latency_info_) { 182 for (auto latency_info : latency_info_) {
207 latency_info.AddLatencyNumberWithTimestamp( 183 latency_info.AddLatencyNumberWithTimestamp(
208 ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT, 0, 0, finish_time, 1); 184 ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT, 0, 0, finish_time, 1);
209 latency_info.AddLatencyNumberWithTimestamp( 185 latency_info.AddLatencyNumberWithTimestamp(
210 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0, 186 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0,
211 finish_time, 1); 187 finish_time, 1);
212 } 188 }
213 189
214 // Send acknowledgement to the browser. 190 // Send acknowledgement to the browser.
215 CAContextID ca_context_id = 0; 191 CAContextID ca_context_id = 0;
216 gfx::ScopedRefCountedIOSurfaceMachPort io_surface; 192 gfx::ScopedRefCountedIOSurfaceMachPort io_surface_mach_port;
217 if (use_remote_layer_api_) { 193 if (use_remote_layer_api_) {
218 ca_context_id = [ca_context_ contextId]; 194 ca_context_id = [ca_context_ contextId];
219 } else if (current_partial_damage_tree_) { 195 } else {
220 io_surface.reset(IOSurfaceCreateMachPort( 196 IOSurfaceRef io_surface =
221 current_partial_damage_tree_->RootLayerIOSurface())); 197 ca_layer_tree_coordinator_->GetIOSurfaceForDisplay();
198 if (io_surface)
199 io_surface_mach_port.reset(IOSurfaceCreateMachPort(io_surface));
222 } 200 }
223 SendAcceleratedSurfaceBuffersSwapped(handle_, ca_context_id, io_surface, 201 SendAcceleratedSurfaceBuffersSwapped(handle_, ca_context_id,
224 pixel_size_, scale_factor_, 202 io_surface_mach_port, pixel_size_,
225 std::move(latency_info_)); 203 scale_factor_, std::move(latency_info_));
226 204
227 // Reset all state for the next frame. 205 // Reset all state for the next frame.
228 latency_info_.clear(); 206 latency_info_.clear();
229 pending_ca_layer_tree_.reset();
230 pending_partial_damage_tree_.reset();
231 return gfx::SwapResult::SWAP_ACK; 207 return gfx::SwapResult::SWAP_ACK;
232 } 208 }
233 209
234 gfx::SwapResult ImageTransportSurfaceOverlayMac::SwapBuffers() { 210 gfx::SwapResult ImageTransportSurfaceOverlayMac::SwapBuffers() {
235 return SwapBuffersInternal( 211 return SwapBuffersInternal(
236 gfx::Rect(0, 0, pixel_size_.width(), pixel_size_.height())); 212 gfx::Rect(0, 0, pixel_size_.width(), pixel_size_.height()));
237 } 213 }
238 214
239 gfx::SwapResult ImageTransportSurfaceOverlayMac::PostSubBuffer(int x, 215 gfx::SwapResult ImageTransportSurfaceOverlayMac::PostSubBuffer(int x,
240 int y, 216 int y,
(...skipping 29 matching lines...) Expand all
270 const gfx::Rect& pixel_frame_rect, 246 const gfx::Rect& pixel_frame_rect,
271 const gfx::RectF& crop_rect) { 247 const gfx::RectF& crop_rect) {
272 if (transform != gfx::OVERLAY_TRANSFORM_NONE) { 248 if (transform != gfx::OVERLAY_TRANSFORM_NONE) {
273 DLOG(ERROR) << "Invalid overlay plane transform."; 249 DLOG(ERROR) << "Invalid overlay plane transform.";
274 return false; 250 return false;
275 } 251 }
276 if (z_order) { 252 if (z_order) {
277 DLOG(ERROR) << "Invalid non-zero Z order."; 253 DLOG(ERROR) << "Invalid non-zero Z order.";
278 return false; 254 return false;
279 } 255 }
280 if (pending_partial_damage_tree_) { 256 return ca_layer_tree_coordinator_->SetPendingGLRendererBackbuffer(
281 DLOG(ERROR) << "Only one overlay per swap is allowed."; 257 static_cast<gl::GLImageIOSurface*>(image)->io_surface());
282 return false;
283 }
284 pending_partial_damage_tree_.reset(new ui::CALayerPartialDamageTree(
285 use_remote_layer_api_,
286 static_cast<gl::GLImageIOSurface*>(image)->io_surface(),
287 pixel_frame_rect));
288 return true;
289 } 258 }
290 259
291 bool ImageTransportSurfaceOverlayMac::ScheduleCALayer( 260 bool ImageTransportSurfaceOverlayMac::ScheduleCALayer(
292 gl::GLImage* contents_image, 261 gl::GLImage* contents_image,
293 const gfx::RectF& contents_rect, 262 const gfx::RectF& contents_rect,
294 float opacity, 263 float opacity,
295 unsigned background_color, 264 unsigned background_color,
296 unsigned edge_aa_mask, 265 unsigned edge_aa_mask,
297 const gfx::RectF& rect, 266 const gfx::RectF& rect,
298 bool is_clipped, 267 bool is_clipped,
299 const gfx::RectF& clip_rect, 268 const gfx::RectF& clip_rect,
300 const gfx::Transform& transform, 269 const gfx::Transform& transform,
301 int sorting_context_id, 270 int sorting_context_id,
302 unsigned filter) { 271 unsigned filter) {
303 base::ScopedCFTypeRef<IOSurfaceRef> io_surface; 272 base::ScopedCFTypeRef<IOSurfaceRef> io_surface;
304 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer; 273 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer;
305 if (contents_image) { 274 if (contents_image) {
306 gl::GLImageIOSurface* io_surface_image = 275 gl::GLImageIOSurface* io_surface_image =
307 static_cast<gl::GLImageIOSurface*>(contents_image); 276 static_cast<gl::GLImageIOSurface*>(contents_image);
308 io_surface = io_surface_image->io_surface(); 277 io_surface = io_surface_image->io_surface();
309 cv_pixel_buffer = io_surface_image->cv_pixel_buffer(); 278 cv_pixel_buffer = io_surface_image->cv_pixel_buffer();
310 } 279 }
311 if (!pending_ca_layer_tree_) 280 return ca_layer_tree_coordinator_->GetPendingCARendererLayerTree()
312 pending_ca_layer_tree_.reset(new ui::CALayerTree); 281 ->ScheduleCALayer(
313 return pending_ca_layer_tree_->ScheduleCALayer( 282 is_clipped, gfx::ToEnclosingRect(clip_rect), sorting_context_id,
314 is_clipped, gfx::ToEnclosingRect(clip_rect), sorting_context_id, 283 transform, io_surface, cv_pixel_buffer, contents_rect,
315 transform, io_surface, cv_pixel_buffer, contents_rect, 284 gfx::ToEnclosingRect(rect), background_color, edge_aa_mask, opacity);
316 gfx::ToEnclosingRect(rect), background_color, edge_aa_mask, opacity);
317 } 285 }
318 286
319 bool ImageTransportSurfaceOverlayMac::IsSurfaceless() const { 287 bool ImageTransportSurfaceOverlayMac::IsSurfaceless() const {
320 return true; 288 return true;
321 } 289 }
322 290
323 bool ImageTransportSurfaceOverlayMac::Resize(const gfx::Size& pixel_size, 291 bool ImageTransportSurfaceOverlayMac::Resize(const gfx::Size& pixel_size,
324 float scale_factor, 292 float scale_factor,
325 bool has_alpha) { 293 bool has_alpha) {
326 // Flush through any pending frames.
327 pixel_size_ = pixel_size; 294 pixel_size_ = pixel_size;
328 scale_factor_ = scale_factor; 295 scale_factor_ = scale_factor;
296 ca_layer_tree_coordinator_->Resize(pixel_size, scale_factor);
329 return true; 297 return true;
330 } 298 }
331 299
332 void ImageTransportSurfaceOverlayMac::OnGpuSwitched() { 300 void ImageTransportSurfaceOverlayMac::OnGpuSwitched() {
333 // Create a new context, and use the GL renderer ID that the new context gets. 301 // Create a new context, and use the GL renderer ID that the new context gets.
334 scoped_refptr<ui::IOSurfaceContext> context_on_new_gpu = 302 scoped_refptr<ui::IOSurfaceContext> context_on_new_gpu =
335 ui::IOSurfaceContext::Get(ui::IOSurfaceContext::kCALayerContext); 303 ui::IOSurfaceContext::Get(ui::IOSurfaceContext::kCALayerContext);
336 if (!context_on_new_gpu) 304 if (!context_on_new_gpu)
337 return; 305 return;
338 GLint context_renderer_id = -1; 306 GLint context_renderer_id = -1;
339 if (CGLGetParameter(context_on_new_gpu->cgl_context(), 307 if (CGLGetParameter(context_on_new_gpu->cgl_context(),
340 kCGLCPCurrentRendererID, 308 kCGLCPCurrentRendererID,
341 &context_renderer_id) != kCGLNoError) { 309 &context_renderer_id) != kCGLNoError) {
342 LOG(ERROR) << "Failed to create test context after GPU switch"; 310 LOG(ERROR) << "Failed to create test context after GPU switch";
343 return; 311 return;
344 } 312 }
345 gl_renderer_id_ = context_renderer_id & kCGLRendererIDMatchingMask; 313 gl_renderer_id_ = context_renderer_id & kCGLRendererIDMatchingMask;
346 314
347 // Post a task holding a reference to the new GL context. The reason for 315 // Post a task holding a reference to the new GL context. The reason for
348 // this is to avoid creating-then-destroying the context for every image 316 // this is to avoid creating-then-destroying the context for every image
349 // transport surface that is observing the GPU switch. 317 // transport surface that is observing the GPU switch.
350 base::MessageLoop::current()->PostTask( 318 base::MessageLoop::current()->PostTask(
351 FROM_HERE, base::Bind(&IOSurfaceContextNoOp, context_on_new_gpu)); 319 FROM_HERE, base::Bind(&IOSurfaceContextNoOp, context_on_new_gpu));
352 } 320 }
353 321
354 } // namespace gpu 322 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/ipc/service/image_transport_surface_overlay_mac.h ('k') | ui/accelerated_widget_mac/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698