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

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

Issue 2492583002: Decouple PassThroughImageTransportSurface from GpuCommandBufferStub (Closed)
Patch Set: Addressed Antoine's comments Created 4 years, 1 month 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/command_line.h" 25 #include "base/command_line.h"
26 #include "base/metrics/histogram_macros.h" 26 #include "base/metrics/histogram_macros.h"
27 #include "base/threading/thread_task_runner_handle.h" 27 #include "base/threading/thread_task_runner_handle.h"
28 #include "base/trace_event/trace_event.h" 28 #include "base/trace_event/trace_event.h"
29 #include "gpu/ipc/common/gpu_messages.h"
30 #include "gpu/ipc/service/gpu_channel_manager.h" 29 #include "gpu/ipc/service/gpu_channel_manager.h"
31 #include "gpu/ipc/service/gpu_channel_manager_delegate.h" 30 #include "gpu/ipc/service/gpu_channel_manager_delegate.h"
32 #include "ui/accelerated_widget_mac/ca_layer_tree_coordinator.h" 31 #include "ui/accelerated_widget_mac/ca_layer_tree_coordinator.h"
33 #include "ui/accelerated_widget_mac/io_surface_context.h" 32 #include "ui/accelerated_widget_mac/io_surface_context.h"
34 #include "ui/base/cocoa/animation_utils.h" 33 #include "ui/base/cocoa/animation_utils.h"
35 #include "ui/base/cocoa/remote_layer_api.h" 34 #include "ui/base/cocoa/remote_layer_api.h"
36 #include "ui/base/ui_base_switches.h" 35 #include "ui/base/ui_base_switches.h"
37 #include "ui/gfx/geometry/rect_conversions.h" 36 #include "ui/gfx/geometry/rect_conversions.h"
38 #include "ui/gfx/swap_result.h" 37 #include "ui/gfx/swap_result.h"
39 #include "ui/gfx/transform.h" 38 #include "ui/gfx/transform.h"
(...skipping 15 matching lines...) Expand all
55 } 54 }
56 55
57 void IOSurfaceContextNoOp(scoped_refptr<ui::IOSurfaceContext>) { 56 void IOSurfaceContextNoOp(scoped_refptr<ui::IOSurfaceContext>) {
58 } 57 }
59 58
60 } // namespace 59 } // namespace
61 60
62 namespace gpu { 61 namespace gpu {
63 62
64 ImageTransportSurfaceOverlayMac::ImageTransportSurfaceOverlayMac( 63 ImageTransportSurfaceOverlayMac::ImageTransportSurfaceOverlayMac(
65 GpuCommandBufferStub* stub) 64 base::WeakPtr<ImageTransportSurfaceDelegate> delegate)
66 : stub_(stub->AsWeakPtr()), 65 : delegate_(delegate),
67 use_remote_layer_api_(ui::RemoteLayerAPISupported()), 66 use_remote_layer_api_(ui::RemoteLayerAPISupported()),
68 scale_factor_(1), 67 scale_factor_(1),
69 gl_renderer_id_(0) { 68 gl_renderer_id_(0) {
70 ui::GpuSwitchingManager::GetInstance()->AddObserver(this); 69 ui::GpuSwitchingManager::GetInstance()->AddObserver(this);
71 70
72 static bool av_disabled_at_command_line = 71 static bool av_disabled_at_command_line =
73 base::CommandLine::ForCurrentProcess()->HasSwitch( 72 base::CommandLine::ForCurrentProcess()->HasSwitch(
74 switches::kDisableAVFoundationOverlays); 73 switches::kDisableAVFoundationOverlays);
75 74
76 bool allow_av_sample_buffer_display_layer = 75 bool allow_av_sample_buffer_display_layer =
77 !av_disabled_at_command_line && 76 !av_disabled_at_command_line &&
78 !stub_->GetFeatureInfo() 77 !delegate_->GetFeatureInfo()
79 ->workarounds() 78 ->workarounds()
80 .disable_av_sample_buffer_display_layer; 79 .disable_av_sample_buffer_display_layer;
81 80
82 ca_layer_tree_coordinator_.reset(new ui::CALayerTreeCoordinator( 81 ca_layer_tree_coordinator_.reset(new ui::CALayerTreeCoordinator(
83 use_remote_layer_api_, allow_av_sample_buffer_display_layer)); 82 use_remote_layer_api_, allow_av_sample_buffer_display_layer));
84 } 83 }
85 84
86 ImageTransportSurfaceOverlayMac::~ImageTransportSurfaceOverlayMac() { 85 ImageTransportSurfaceOverlayMac::~ImageTransportSurfaceOverlayMac() {
87 ui::GpuSwitchingManager::GetInstance()->RemoveObserver(this); 86 ui::GpuSwitchingManager::GetInstance()->RemoveObserver(this);
88 if (stub_.get()) { 87 if (delegate_.get()) {
89 stub_->SetLatencyInfoCallback( 88 delegate_->SetLatencyInfoCallback(
90 base::Callback<void(const std::vector<ui::LatencyInfo>&)>()); 89 base::Callback<void(const std::vector<ui::LatencyInfo>&)>());
91 } 90 }
92 Destroy(); 91 Destroy();
93 } 92 }
94 93
95 bool ImageTransportSurfaceOverlayMac::Initialize(gl::GLSurface::Format format) { 94 bool ImageTransportSurfaceOverlayMac::Initialize(gl::GLSurface::Format format) {
96 if (!stub_.get() || !stub_->decoder()) 95 delegate_->SetLatencyInfoCallback(
97 return false;
98
99 stub_->SetLatencyInfoCallback(
100 base::Bind(&ImageTransportSurfaceOverlayMac::SetLatencyInfo, 96 base::Bind(&ImageTransportSurfaceOverlayMac::SetLatencyInfo,
101 base::Unretained(this))); 97 base::Unretained(this)));
102 98
103 // Create the CAContext to send this to the GPU process, and the layer for 99 // Create the CAContext to send this to the GPU process, and the layer for
104 // the context. 100 // the context.
105 if (use_remote_layer_api_) { 101 if (use_remote_layer_api_) {
106 CGSConnectionID connection_id = CGSMainConnectionID(); 102 CGSConnectionID connection_id = CGSMainConnectionID();
107 ca_context_.reset([ 103 ca_context_.reset([
108 [CAContext contextWithCGSConnection:connection_id options:@{}] retain]); 104 [CAContext contextWithCGSConnection:connection_id options:@{}] retain]);
109 [ca_context_ setLayer:ca_layer_tree_coordinator_->GetCALayerForDisplay()]; 105 [ca_context_ setLayer:ca_layer_tree_coordinator_->GetCALayerForDisplay()];
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 CAContextID fullscreen_low_power_ca_context_id, 140 CAContextID fullscreen_low_power_ca_context_id,
145 const gfx::ScopedRefCountedIOSurfaceMachPort& io_surface, 141 const gfx::ScopedRefCountedIOSurfaceMachPort& io_surface,
146 const gfx::Size& size, 142 const gfx::Size& size,
147 float scale_factor, 143 float scale_factor,
148 std::vector<ui::LatencyInfo> latency_info) { 144 std::vector<ui::LatencyInfo> latency_info) {
149 // TRACE_EVENT for gpu tests: 145 // TRACE_EVENT for gpu tests:
150 TRACE_EVENT_INSTANT2("test_gpu", "SwapBuffers", TRACE_EVENT_SCOPE_THREAD, 146 TRACE_EVENT_INSTANT2("test_gpu", "SwapBuffers", TRACE_EVENT_SCOPE_THREAD,
151 "GLImpl", static_cast<int>(gl::GetGLImplementation()), 147 "GLImpl", static_cast<int>(gl::GetGLImplementation()),
152 "width", size.width()); 148 "width", size.width());
153 149
154 GpuCommandBufferMsg_SwapBuffersCompleted_Params params; 150 SwapBuffersCompleteParams params;
155 params.ca_context_id = ca_context_id; 151 params.ca_context_id = ca_context_id;
156 params.fullscreen_low_power_ca_context_valid = 152 params.fullscreen_low_power_ca_context_valid =
157 fullscreen_low_power_ca_context_valid; 153 fullscreen_low_power_ca_context_valid;
158 params.fullscreen_low_power_ca_context_id = 154 params.fullscreen_low_power_ca_context_id =
159 fullscreen_low_power_ca_context_id; 155 fullscreen_low_power_ca_context_id;
160 params.io_surface = io_surface; 156 params.io_surface = io_surface;
161 params.pixel_size = size; 157 params.pixel_size = size;
162 params.scale_factor = scale_factor; 158 params.scale_factor = scale_factor;
163 params.latency_info = std::move(latency_info); 159 params.latency_info = std::move(latency_info);
164 params.result = gfx::SwapResult::SWAP_ACK; 160 params.result = gfx::SwapResult::SWAP_ACK;
165 161
166 for (auto& query : ca_layer_in_use_queries_) { 162 for (auto& query : ca_layer_in_use_queries_) {
167 gpu::TextureInUseResponse response; 163 gpu::TextureInUseResponse response;
168 response.texture = query.texture; 164 response.texture = query.texture;
169 bool in_use = false; 165 bool in_use = false;
170 gl::GLImageIOSurface* io_surface_image = 166 gl::GLImageIOSurface* io_surface_image =
171 gl::GLImageIOSurface::FromGLImage(query.image.get()); 167 gl::GLImageIOSurface::FromGLImage(query.image.get());
172 if (io_surface_image) { 168 if (io_surface_image) {
173 in_use = io_surface_image->CanCheckIOSurfaceIsInUse() && 169 in_use = io_surface_image->CanCheckIOSurfaceIsInUse() &&
174 IOSurfaceIsInUse(io_surface_image->io_surface()); 170 IOSurfaceIsInUse(io_surface_image->io_surface());
175 } 171 }
176 response.in_use = in_use; 172 response.in_use = in_use;
177 params.in_use_responses.push_back(std::move(response)); 173 params.in_use_responses.push_back(std::move(response));
178 } 174 }
179 ca_layer_in_use_queries_.clear(); 175 ca_layer_in_use_queries_.clear();
180 176
181 stub_->SendSwapBuffersCompleted(params); 177 delegate_->DidSwapBuffersComplete(std::move(params));
182 } 178 }
183 179
184 gfx::SwapResult ImageTransportSurfaceOverlayMac::SwapBuffersInternal( 180 gfx::SwapResult ImageTransportSurfaceOverlayMac::SwapBuffersInternal(
185 const gfx::Rect& pixel_damage_rect) { 181 const gfx::Rect& pixel_damage_rect) {
186 TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::SwapBuffersInternal"); 182 TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::SwapBuffersInternal");
187 183
188 base::TimeTicks before_flush_time; 184 base::TimeTicks before_flush_time;
189 base::TimeTicks after_flush_before_commit_time; 185 base::TimeTicks after_flush_before_commit_time;
190 186
191 // If supported, use GLFence to ensure that we haven't gotten more than one 187 // If supported, use GLFence to ensure that we haven't gotten more than one
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 gl_renderer_id_ = context_renderer_id & kCGLRendererIDMatchingMask; 388 gl_renderer_id_ = context_renderer_id & kCGLRendererIDMatchingMask;
393 389
394 // Post a task holding a reference to the new GL context. The reason for 390 // Post a task holding a reference to the new GL context. The reason for
395 // this is to avoid creating-then-destroying the context for every image 391 // this is to avoid creating-then-destroying the context for every image
396 // transport surface that is observing the GPU switch. 392 // transport surface that is observing the GPU switch.
397 base::ThreadTaskRunnerHandle::Get()->PostTask( 393 base::ThreadTaskRunnerHandle::Get()->PostTask(
398 FROM_HERE, base::Bind(&IOSurfaceContextNoOp, context_on_new_gpu)); 394 FROM_HERE, base::Bind(&IOSurfaceContextNoOp, context_on_new_gpu));
399 } 395 }
400 396
401 } // namespace gpu 397 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/ipc/service/image_transport_surface_overlay_mac.h ('k') | gpu/ipc/service/image_transport_surface_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698