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

Side by Side Diff: components/mus/surfaces/direct_output_surface_ozone.cc

Issue 2002303002: Consolidate OutputSurface constructors into GL vs Vulkan. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: outputsurface-constructors: rebase-and-fixcrash 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/mus/surfaces/direct_output_surface_ozone.h" 5 #include "components/mus/surfaces/direct_output_surface_ozone.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "cc/output/compositor_frame.h" 10 #include "cc/output/compositor_frame.h"
11 #include "cc/output/context_provider.h" 11 #include "cc/output/context_provider.h"
12 #include "cc/output/output_surface_client.h" 12 #include "cc/output/output_surface_client.h"
13 #include "components/display_compositor/buffer_queue.h" 13 #include "components/display_compositor/buffer_queue.h"
14 #include "components/mus/gles2/mojo_gpu_memory_buffer_manager.h" 14 #include "components/mus/gles2/mojo_gpu_memory_buffer_manager.h"
15 #include "components/mus/surfaces/surfaces_context_provider.h" 15 #include "components/mus/surfaces/surfaces_context_provider.h"
16 #include "gpu/command_buffer/client/context_support.h" 16 #include "gpu/command_buffer/client/context_support.h"
17 #include "gpu/command_buffer/client/gles2_interface.h" 17 #include "gpu/command_buffer/client/gles2_interface.h"
18 18
19 using display_compositor::BufferQueue; 19 using display_compositor::BufferQueue;
20 20
21 namespace mus { 21 namespace mus {
22 22
23 DirectOutputSurfaceOzone::DirectOutputSurfaceOzone( 23 DirectOutputSurfaceOzone::DirectOutputSurfaceOzone(
24 const scoped_refptr<SurfacesContextProvider>& context_provider, 24 scoped_refptr<SurfacesContextProvider> context_provider,
25 gfx::AcceleratedWidget widget, 25 gfx::AcceleratedWidget widget,
26 base::SingleThreadTaskRunner* task_runner, 26 base::SingleThreadTaskRunner* task_runner,
27 uint32_t target, 27 uint32_t target,
28 uint32_t internalformat) 28 uint32_t internalformat)
29 : cc::OutputSurface(context_provider), 29 : cc::OutputSurface(context_provider, nullptr, nullptr),
30 gl_helper_(context_provider->ContextGL(), 30 gl_helper_(context_provider->ContextGL(),
31 context_provider->ContextSupport()), 31 context_provider->ContextSupport()),
32 output_surface_(new BufferQueue(context_provider, 32 buffer_queue_(new BufferQueue(context_provider->ContextGL(),
33 target, 33 target,
34 internalformat, 34 internalformat,
35 &gl_helper_, 35 &gl_helper_,
36 &gpu_memory_buffer_manager_, 36 &gpu_memory_buffer_manager_,
37 widget)), 37 widget)),
38 synthetic_begin_frame_source_(new cc::SyntheticBeginFrameSource( 38 synthetic_begin_frame_source_(new cc::SyntheticBeginFrameSource(
39 task_runner, 39 task_runner,
40 cc::BeginFrameArgs::DefaultInterval())), 40 cc::BeginFrameArgs::DefaultInterval())),
41 weak_ptr_factory_(this) { 41 weak_ptr_factory_(this) {
42 capabilities_.uses_default_gl_framebuffer = false; 42 capabilities_.uses_default_gl_framebuffer = false;
43 capabilities_.flipped_output_surface = true; 43 capabilities_.flipped_output_surface = true;
44 // Set |max_frames_pending| to 2 for surfaceless, which aligns scheduling 44 // Set |max_frames_pending| to 2 for surfaceless, which aligns scheduling
45 // more closely with the previous surfaced behavior. 45 // more closely with the previous surfaced behavior.
46 // With a surface, swap buffer ack used to return early, before actually 46 // With a surface, swap buffer ack used to return early, before actually
47 // presenting the back buffer, enabling the browser compositor to run ahead. 47 // presenting the back buffer, enabling the browser compositor to run ahead.
48 // Surfaceless implementation acks at the time of actual buffer swap, which 48 // Surfaceless implementation acks at the time of actual buffer swap, which
49 // shifts the start of the new frame forward relative to the old 49 // shifts the start of the new frame forward relative to the old
50 // implementation. 50 // implementation.
51 capabilities_.max_frames_pending = 2; 51 capabilities_.max_frames_pending = 2;
52 52
53 output_surface_->Initialize(); 53 buffer_queue_->Initialize();
54 54
55 context_provider->SetSwapBuffersCompletionCallback( 55 context_provider->SetSwapBuffersCompletionCallback(
56 base::Bind(&DirectOutputSurfaceOzone::OnGpuSwapBuffersCompleted, 56 base::Bind(&DirectOutputSurfaceOzone::OnGpuSwapBuffersCompleted,
57 base::Unretained(this))); 57 base::Unretained(this)));
58 } 58 }
59 59
60 DirectOutputSurfaceOzone::~DirectOutputSurfaceOzone() { 60 DirectOutputSurfaceOzone::~DirectOutputSurfaceOzone() {
61 // TODO(rjkroege): Support cleanup. 61 // TODO(rjkroege): Support cleanup.
62 } 62 }
63 63
64 bool DirectOutputSurfaceOzone::IsDisplayedAsOverlayPlane() const { 64 bool DirectOutputSurfaceOzone::IsDisplayedAsOverlayPlane() const {
65 // TODO(rjkroege): implement remaining overlay functionality. 65 // TODO(rjkroege): implement remaining overlay functionality.
66 return true; 66 return true;
67 } 67 }
68 68
69 unsigned DirectOutputSurfaceOzone::GetOverlayTextureId() const { 69 unsigned DirectOutputSurfaceOzone::GetOverlayTextureId() const {
70 DCHECK(output_surface_); 70 DCHECK(buffer_queue_);
71 return output_surface_->current_texture_id(); 71 return buffer_queue_->current_texture_id();
72 } 72 }
73 73
74 void DirectOutputSurfaceOzone::SwapBuffers(cc::CompositorFrame* frame) { 74 void DirectOutputSurfaceOzone::SwapBuffers(cc::CompositorFrame* frame) {
75 DCHECK(output_surface_); 75 DCHECK(buffer_queue_);
76 DCHECK(frame->gl_frame_data); 76 DCHECK(frame->gl_frame_data);
77 77
78 output_surface_->SwapBuffers(frame->gl_frame_data->sub_buffer_rect); 78 buffer_queue_->SwapBuffers(frame->gl_frame_data->sub_buffer_rect);
79 79
80 // Code combining GpuBrowserCompositorOutputSurface + DirectOutputSurface 80 // Code combining GpuBrowserCompositorOutputSurface + DirectOutputSurface
81 if (frame->gl_frame_data->sub_buffer_rect == 81 if (frame->gl_frame_data->sub_buffer_rect ==
82 gfx::Rect(frame->gl_frame_data->size)) { 82 gfx::Rect(frame->gl_frame_data->size)) {
83 context_provider_->ContextSupport()->Swap(); 83 context_provider_->ContextSupport()->Swap();
84 } else { 84 } else {
85 context_provider_->ContextSupport()->PartialSwapBuffers( 85 context_provider_->ContextSupport()->PartialSwapBuffers(
86 frame->gl_frame_data->sub_buffer_rect); 86 frame->gl_frame_data->sub_buffer_rect);
87 } 87 }
88 88
(...skipping 22 matching lines...) Expand all
111 111
112 void DirectOutputSurfaceOzone::OnUpdateVSyncParametersFromGpu( 112 void DirectOutputSurfaceOzone::OnUpdateVSyncParametersFromGpu(
113 base::TimeTicks timebase, 113 base::TimeTicks timebase,
114 base::TimeDelta interval) { 114 base::TimeDelta interval) {
115 DCHECK(HasClient()); 115 DCHECK(HasClient());
116 synthetic_begin_frame_source_->OnUpdateVSyncParameters(timebase, interval); 116 synthetic_begin_frame_source_->OnUpdateVSyncParameters(timebase, interval);
117 } 117 }
118 118
119 void DirectOutputSurfaceOzone::OnGpuSwapBuffersCompleted( 119 void DirectOutputSurfaceOzone::OnGpuSwapBuffersCompleted(
120 gfx::SwapResult result) { 120 gfx::SwapResult result) {
121 DCHECK(output_surface_); 121 DCHECK(buffer_queue_);
122 bool force_swap = false; 122 bool force_swap = false;
123 if (result == gfx::SwapResult::SWAP_NAK_RECREATE_BUFFERS) { 123 if (result == gfx::SwapResult::SWAP_NAK_RECREATE_BUFFERS) {
124 // Even through the swap failed, this is a fixable error so we can pretend 124 // Even through the swap failed, this is a fixable error so we can pretend
125 // it succeeded to the rest of the system. 125 // it succeeded to the rest of the system.
126 result = gfx::SwapResult::SWAP_ACK; 126 result = gfx::SwapResult::SWAP_ACK;
127 output_surface_->RecreateBuffers(); 127 buffer_queue_->RecreateBuffers();
128 force_swap = true; 128 force_swap = true;
129 } 129 }
130 130
131 output_surface_->PageFlipComplete(); 131 buffer_queue_->PageFlipComplete();
132 OnSwapBuffersComplete(); 132 OnSwapBuffersComplete();
133 133
134 if (force_swap) 134 if (force_swap)
135 client_->SetNeedsRedrawRect(gfx::Rect(SurfaceSize())); 135 client_->SetNeedsRedrawRect(gfx::Rect(SurfaceSize()));
136 } 136 }
137 137
138 void DirectOutputSurfaceOzone::BindFramebuffer() { 138 void DirectOutputSurfaceOzone::BindFramebuffer() {
139 DCHECK(output_surface_); 139 DCHECK(buffer_queue_);
140 output_surface_->BindFramebuffer(); 140 buffer_queue_->BindFramebuffer();
141 } 141 }
142 142
143 // We call this on every frame but changing the size once we've allocated 143 // We call this on every frame but changing the size once we've allocated
144 // backing NativePixmapOzone instances will cause a DCHECK because 144 // backing NativePixmapOzone instances will cause a DCHECK because
145 // Chrome never Reshape(s) after the first one from (0,0). NB: this implies 145 // Chrome never Reshape(s) after the first one from (0,0). NB: this implies
146 // that screen size changes need to be plumbed differently. In particular, we 146 // that screen size changes need to be plumbed differently. In particular, we
147 // must create the native window in the size that the hardware reports. 147 // must create the native window in the size that the hardware reports.
148 void DirectOutputSurfaceOzone::Reshape(const gfx::Size& size, 148 void DirectOutputSurfaceOzone::Reshape(const gfx::Size& size,
149 float scale_factor, 149 float scale_factor,
150 bool alpha) { 150 bool alpha) {
151 OutputSurface::Reshape(size, scale_factor, alpha); 151 OutputSurface::Reshape(size, scale_factor, alpha);
152 DCHECK(output_surface_); 152 DCHECK(buffer_queue_);
153 output_surface_->Reshape(SurfaceSize(), scale_factor); 153 buffer_queue_->Reshape(SurfaceSize(), scale_factor);
154 } 154 }
155 155
156 } // namespace mus 156 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/surfaces/direct_output_surface_ozone.h ('k') | content/browser/compositor/browser_compositor_output_surface.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698