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

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

Issue 1962493002: Make Mac swap code like other platforms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporate review feedback Created 4 years, 7 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/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"
35 #include "ui/gfx/swap_result.h"
34 #include "ui/gfx/transform.h" 36 #include "ui/gfx/transform.h"
35 #include "ui/gl/gl_context.h" 37 #include "ui/gl/gl_context.h"
36 #include "ui/gl/gl_fence.h" 38 #include "ui/gl/gl_fence.h"
37 #include "ui/gl/gl_image_io_surface.h" 39 #include "ui/gl/gl_image_io_surface.h"
38 #include "ui/gl/gpu_switching_manager.h" 40 #include "ui/gl/gpu_switching_manager.h"
39 #include "ui/gl/scoped_api.h" 41 #include "ui/gl/scoped_api.h"
40 #include "ui/gl/scoped_cgl.h" 42 #include "ui/gl/scoped_cgl.h"
41 43
42 namespace { 44 namespace {
43 45
44 void CheckGLErrors(const char* msg) { 46 void CheckGLErrors(const char* msg) {
45 GLenum gl_error; 47 GLenum gl_error;
46 while ((gl_error = glGetError()) != GL_NO_ERROR) { 48 while ((gl_error = glGetError()) != GL_NO_ERROR) {
47 LOG(ERROR) << "OpenGL error hit " << msg << ": " << gl_error; 49 LOG(ERROR) << "OpenGL error hit " << msg << ": " << gl_error;
48 } 50 }
49 } 51 }
50 52
51 void IOSurfaceContextNoOp(scoped_refptr<ui::IOSurfaceContext>) { 53 void IOSurfaceContextNoOp(scoped_refptr<ui::IOSurfaceContext>) {
52 } 54 }
53 55
54 } // namespace 56 } // namespace
55 57
56 namespace gpu { 58 namespace gpu {
57 59
58 scoped_refptr<gfx::GLSurface> ImageTransportSurfaceCreateNativeSurface( 60 scoped_refptr<gfx::GLSurface> ImageTransportSurfaceCreateNativeSurface(
59 GpuChannelManager* manager, 61 GpuChannelManager* manager,
60 GpuCommandBufferStub* stub, 62 GpuCommandBufferStub* stub,
61 SurfaceHandle handle) { 63 SurfaceHandle handle) {
62 return new ImageTransportSurfaceOverlayMac(manager, stub, handle); 64 return new ImageTransportSurfaceOverlayMac(stub, handle);
63 } 65 }
64 66
65 ImageTransportSurfaceOverlayMac::ImageTransportSurfaceOverlayMac( 67 ImageTransportSurfaceOverlayMac::ImageTransportSurfaceOverlayMac(
66 GpuChannelManager* manager,
67 GpuCommandBufferStub* stub, 68 GpuCommandBufferStub* stub,
68 SurfaceHandle handle) 69 SurfaceHandle handle)
69 : manager_(manager), 70 : stub_(stub->AsWeakPtr()),
70 stub_(stub->AsWeakPtr()),
71 handle_(handle), 71 handle_(handle),
72 use_remote_layer_api_(ui::RemoteLayerAPISupported()), 72 use_remote_layer_api_(ui::RemoteLayerAPISupported()),
73 scale_factor_(1), 73 scale_factor_(1),
74 gl_renderer_id_(0), 74 gl_renderer_id_(0) {
75 vsync_parameters_valid_(false) {
76 manager_->AddBufferPresentedCallback(
77 handle_, base::Bind(&ImageTransportSurfaceOverlayMac::BufferPresented,
78 base::Unretained(this)));
79 ui::GpuSwitchingManager::GetInstance()->AddObserver(this); 75 ui::GpuSwitchingManager::GetInstance()->AddObserver(this);
80 ca_layer_tree_coordinator_.reset( 76 ca_layer_tree_coordinator_.reset(
81 new ui::CALayerTreeCoordinator(use_remote_layer_api_)); 77 new ui::CALayerTreeCoordinator(use_remote_layer_api_));
82 } 78 }
83 79
84 ImageTransportSurfaceOverlayMac::~ImageTransportSurfaceOverlayMac() { 80 ImageTransportSurfaceOverlayMac::~ImageTransportSurfaceOverlayMac() {
85 ui::GpuSwitchingManager::GetInstance()->RemoveObserver(this); 81 ui::GpuSwitchingManager::GetInstance()->RemoveObserver(this);
86 if (stub_.get()) { 82 if (stub_.get()) {
87 stub_->SetLatencyInfoCallback( 83 stub_->SetLatencyInfoCallback(
88 base::Callback<void(const std::vector<ui::LatencyInfo>&)>()); 84 base::Callback<void(const std::vector<ui::LatencyInfo>&)>());
89 } 85 }
90 Destroy(); 86 Destroy();
91 manager_->RemoveBufferPresentedCallback(handle_);
92 } 87 }
93 88
94 bool ImageTransportSurfaceOverlayMac::Initialize( 89 bool ImageTransportSurfaceOverlayMac::Initialize(
95 gfx::GLSurface::Format format) { 90 gfx::GLSurface::Format format) {
96 if (!stub_.get() || !stub_->decoder()) 91 if (!stub_.get() || !stub_->decoder())
97 return false; 92 return false;
98 93
99 stub_->SetLatencyInfoCallback( 94 stub_->SetLatencyInfoCallback(
100 base::Bind(&ImageTransportSurfaceOverlayMac::SetLatencyInfo, 95 base::Bind(&ImageTransportSurfaceOverlayMac::SetLatencyInfo,
101 base::Unretained(this))); 96 base::Unretained(this)));
(...skipping 21 matching lines...) Expand all
123 bool ImageTransportSurfaceOverlayMac::IsOffscreen() { 118 bool ImageTransportSurfaceOverlayMac::IsOffscreen() {
124 return false; 119 return false;
125 } 120 }
126 121
127 void ImageTransportSurfaceOverlayMac::SetLatencyInfo( 122 void ImageTransportSurfaceOverlayMac::SetLatencyInfo(
128 const std::vector<ui::LatencyInfo>& latency_info) { 123 const std::vector<ui::LatencyInfo>& latency_info) {
129 latency_info_.insert(latency_info_.end(), latency_info.begin(), 124 latency_info_.insert(latency_info_.end(), latency_info.begin(),
130 latency_info.end()); 125 latency_info.end());
131 } 126 }
132 127
133 void ImageTransportSurfaceOverlayMac::BufferPresented(
134 gpu::SurfaceHandle surface_handle,
135 const base::TimeTicks& vsync_timebase,
136 const base::TimeDelta& vsync_interval) {
137 vsync_timebase_ = vsync_timebase;
138 vsync_interval_ = vsync_interval;
139 vsync_parameters_valid_ = !vsync_interval_.is_zero();
140
141 // Compute |vsync_timebase_| to be the first vsync after time zero.
142 if (vsync_parameters_valid_) {
143 vsync_timebase_ -=
144 vsync_interval_ *
145 ((vsync_timebase_ - base::TimeTicks()) / vsync_interval_);
146 }
147 }
148
149 void ImageTransportSurfaceOverlayMac::SendAcceleratedSurfaceBuffersSwapped( 128 void ImageTransportSurfaceOverlayMac::SendAcceleratedSurfaceBuffersSwapped(
150 gpu::SurfaceHandle surface_handle, 129 gpu::SurfaceHandle surface_handle,
151 CAContextID ca_context_id, 130 CAContextID ca_context_id,
152 bool fullscreen_low_power_ca_context_valid, 131 bool fullscreen_low_power_ca_context_valid,
153 CAContextID fullscreen_low_power_ca_context_id, 132 CAContextID fullscreen_low_power_ca_context_id,
154 const gfx::ScopedRefCountedIOSurfaceMachPort& io_surface, 133 const gfx::ScopedRefCountedIOSurfaceMachPort& io_surface,
155 const gfx::Size& size, 134 const gfx::Size& size,
156 float scale_factor, 135 float scale_factor,
157 std::vector<ui::LatencyInfo> latency_info) { 136 std::vector<ui::LatencyInfo> latency_info) {
158 // TRACE_EVENT for gpu tests: 137 // TRACE_EVENT for gpu tests:
159 TRACE_EVENT_INSTANT2("test_gpu", "SwapBuffers", TRACE_EVENT_SCOPE_THREAD, 138 TRACE_EVENT_INSTANT2("test_gpu", "SwapBuffers", TRACE_EVENT_SCOPE_THREAD,
160 "GLImpl", static_cast<int>(gfx::GetGLImplementation()), 139 "GLImpl", static_cast<int>(gfx::GetGLImplementation()),
161 "width", size.width()); 140 "width", size.width());
162 manager_->delegate()->SendAcceleratedSurfaceBuffersSwapped( 141
163 surface_handle, ca_context_id, fullscreen_low_power_ca_context_valid, 142 GpuCommandBufferMsg_SwapBuffersCompleted_Params params;
164 fullscreen_low_power_ca_context_id, io_surface, size, scale_factor, 143 params.surface_handle = surface_handle;
165 std::move(latency_info)); 144 params.ca_context_id = ca_context_id;
145 params.fullscreen_low_power_ca_context_valid =
146 fullscreen_low_power_ca_context_valid;
147 params.fullscreen_low_power_ca_context_id =
148 fullscreen_low_power_ca_context_id;
149 params.io_surface = io_surface;
150 params.pixel_size = size;
151 params.scale_factor = scale_factor;
152 params.latency_info = std::move(latency_info);
153 params.result = gfx::SwapResult::SWAP_ACK;
154 stub_->SendSwapBuffersCompleted(params);
166 } 155 }
167 156
168 gfx::SwapResult ImageTransportSurfaceOverlayMac::SwapBuffersInternal( 157 gfx::SwapResult ImageTransportSurfaceOverlayMac::SwapBuffersInternal(
169 const gfx::Rect& pixel_damage_rect) { 158 const gfx::Rect& pixel_damage_rect) {
170 TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::SwapBuffersInternal"); 159 TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::SwapBuffersInternal");
171 160
172 // A glFlush is necessary to ensure correct content appears. A glFinish 161 // A glFlush is necessary to ensure correct content appears. A glFinish
173 // appears empirically to be the best way to get maximum performance when 162 // appears empirically to be the best way to get maximum performance when
174 // GPU bound. 163 // GPU bound.
175 { 164 {
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 gl_renderer_id_ = context_renderer_id & kCGLRendererIDMatchingMask; 317 gl_renderer_id_ = context_renderer_id & kCGLRendererIDMatchingMask;
329 318
330 // Post a task holding a reference to the new GL context. The reason for 319 // Post a task holding a reference to the new GL context. The reason for
331 // this is to avoid creating-then-destroying the context for every image 320 // this is to avoid creating-then-destroying the context for every image
332 // transport surface that is observing the GPU switch. 321 // transport surface that is observing the GPU switch.
333 base::MessageLoop::current()->PostTask( 322 base::MessageLoop::current()->PostTask(
334 FROM_HERE, base::Bind(&IOSurfaceContextNoOp, context_on_new_gpu)); 323 FROM_HERE, base::Bind(&IOSurfaceContextNoOp, context_on_new_gpu));
335 } 324 }
336 325
337 } // namespace gpu 326 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/ipc/service/image_transport_surface_overlay_mac.h ('k') | gpu/ipc/service/pass_through_image_transport_surface.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698