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

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

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

Powered by Google App Engine
This is Rietveld 408576698