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

Side by Side Diff: components/display_compositor/buffer_queue.cc

Issue 2009443002: Revert of Consolidate OutputSurface constructors into GL vs Vulkan. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/display_compositor/buffer_queue.h" 5 #include "components/display_compositor/buffer_queue.h"
6 6
7 #include "base/containers/adapters.h" 7 #include "base/containers/adapters.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "cc/output/context_provider.h"
10 #include "components/display_compositor/gl_helper.h" 11 #include "components/display_compositor/gl_helper.h"
11 #include "gpu/GLES2/gl2extchromium.h" 12 #include "gpu/GLES2/gl2extchromium.h"
12 #include "gpu/command_buffer/client/gles2_interface.h" 13 #include "gpu/command_buffer/client/gles2_interface.h"
13 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" 14 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h"
14 #include "gpu/command_buffer/common/gpu_memory_buffer_support.h" 15 #include "gpu/command_buffer/common/gpu_memory_buffer_support.h"
15 #include "third_party/skia/include/core/SkRect.h" 16 #include "third_party/skia/include/core/SkRect.h"
16 #include "third_party/skia/include/core/SkRegion.h" 17 #include "third_party/skia/include/core/SkRegion.h"
17 #include "ui/gfx/gpu_memory_buffer.h" 18 #include "ui/gfx/gpu_memory_buffer.h"
18 #include "ui/gfx/skia_util.h" 19 #include "ui/gfx/skia_util.h"
19 20
20 namespace display_compositor { 21 namespace display_compositor {
21 22
22 BufferQueue::BufferQueue(gpu::gles2::GLES2Interface* gl, 23 BufferQueue::BufferQueue(scoped_refptr<cc::ContextProvider> context_provider,
23 unsigned int texture_target, 24 unsigned int texture_target,
24 unsigned int internalformat, 25 unsigned int internalformat,
25 GLHelper* gl_helper, 26 GLHelper* gl_helper,
26 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, 27 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
27 gpu::SurfaceHandle surface_handle) 28 gpu::SurfaceHandle surface_handle)
28 : gl_(gl), 29 : context_provider_(context_provider),
29 fbo_(0), 30 fbo_(0),
30 allocated_count_(0), 31 allocated_count_(0),
31 texture_target_(texture_target), 32 texture_target_(texture_target),
32 internal_format_(internalformat), 33 internal_format_(internalformat),
33 gl_helper_(gl_helper), 34 gl_helper_(gl_helper),
34 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), 35 gpu_memory_buffer_manager_(gpu_memory_buffer_manager),
35 surface_handle_(surface_handle) {} 36 surface_handle_(surface_handle) {}
36 37
37 BufferQueue::~BufferQueue() { 38 BufferQueue::~BufferQueue() {
38 FreeAllSurfaces(); 39 FreeAllSurfaces();
39 40
41 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL();
40 if (fbo_) 42 if (fbo_)
41 gl_->DeleteFramebuffers(1, &fbo_); 43 gl->DeleteFramebuffers(1, &fbo_);
42 } 44 }
43 45
44 void BufferQueue::Initialize() { 46 void BufferQueue::Initialize() {
45 gl_->GenFramebuffers(1, &fbo_); 47 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL();
48 gl->GenFramebuffers(1, &fbo_);
46 } 49 }
47 50
48 void BufferQueue::BindFramebuffer() { 51 void BufferQueue::BindFramebuffer() {
49 gl_->BindFramebuffer(GL_FRAMEBUFFER, fbo_); 52 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL();
53 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_);
50 54
51 if (!current_surface_) 55 if (!current_surface_)
52 current_surface_ = GetNextSurface(); 56 current_surface_ = GetNextSurface();
53 57
54 if (current_surface_) { 58 if (current_surface_) {
55 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 59 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
56 texture_target_, current_surface_->texture, 0); 60 texture_target_, current_surface_->texture, 0);
57 } 61 }
58 } 62 }
59 63
60 void BufferQueue::CopyBufferDamage(int texture, 64 void BufferQueue::CopyBufferDamage(int texture,
61 int source_texture, 65 int source_texture,
62 const gfx::Rect& new_damage, 66 const gfx::Rect& new_damage,
63 const gfx::Rect& old_damage) { 67 const gfx::Rect& old_damage) {
64 gl_helper_->CopySubBufferDamage(texture_target_, texture, source_texture, 68 gl_helper_->CopySubBufferDamage(texture_target_, texture, source_texture,
65 SkRegion(gfx::RectToSkIRect(new_damage)), 69 SkRegion(gfx::RectToSkIRect(new_damage)),
66 SkRegion(gfx::RectToSkIRect(old_damage))); 70 SkRegion(gfx::RectToSkIRect(old_damage)));
(...skipping 30 matching lines...) Expand all
97 CopyBufferDamage(current_surface_->texture, texture_id, damage, 101 CopyBufferDamage(current_surface_->texture, texture_id, damage,
98 current_surface_->damage); 102 current_surface_->damage);
99 } 103 }
100 } 104 }
101 current_surface_->damage = gfx::Rect(); 105 current_surface_->damage = gfx::Rect();
102 } 106 }
103 UpdateBufferDamage(damage); 107 UpdateBufferDamage(damage);
104 in_flight_surfaces_.push_back(std::move(current_surface_)); 108 in_flight_surfaces_.push_back(std::move(current_surface_));
105 // Some things reset the framebuffer (CopySubBufferDamage, some GLRenderer 109 // Some things reset the framebuffer (CopySubBufferDamage, some GLRenderer
106 // paths), so ensure we restore it here. 110 // paths), so ensure we restore it here.
107 gl_->BindFramebuffer(GL_FRAMEBUFFER, fbo_); 111 context_provider_->ContextGL()->BindFramebuffer(GL_FRAMEBUFFER, fbo_);
108 } 112 }
109 113
110 void BufferQueue::Reshape(const gfx::Size& size, float scale_factor) { 114 void BufferQueue::Reshape(const gfx::Size& size, float scale_factor) {
111 if (size == size_) 115 if (size == size_)
112 return; 116 return;
113 #if !defined(OS_MACOSX) 117 #if !defined(OS_MACOSX)
114 // TODO(ccameron): This assert is being hit on Mac try jobs. Determine if that 118 // TODO(ccameron): This assert is being hit on Mac try jobs. Determine if that
115 // is cause for concern or if it is benign. 119 // is cause for concern or if it is benign.
116 // http://crbug.com/524624 120 // http://crbug.com/524624
117 DCHECK(!current_surface_); 121 DCHECK(!current_surface_);
118 #endif 122 #endif
119 size_ = size; 123 size_ = size;
120 124
121 // TODO: add stencil buffer when needed. 125 // TODO: add stencil buffer when needed.
122 gl_->BindFramebuffer(GL_FRAMEBUFFER, fbo_); 126 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL();
123 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 127 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_);
124 texture_target_, 0, 0); 128 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
129 texture_target_, 0, 0);
125 130
126 FreeAllSurfaces(); 131 FreeAllSurfaces();
127 } 132 }
128 133
129 void BufferQueue::RecreateBuffers() { 134 void BufferQueue::RecreateBuffers() {
130 // We need to recreate the buffers, for whatever reason the old ones are not 135 // We need to recreate the buffers, for whatever reason the old ones are not
131 // presentable on the device anymore. 136 // presentable on the device anymore.
132 // Unused buffers can be freed directly, they will be re-allocated as needed. 137 // Unused buffers can be freed directly, they will be re-allocated as needed.
133 // Any in flight, current or displayed surface must be replaced. 138 // Any in flight, current or displayed surface must be replaced.
134 available_surfaces_.clear(); 139 available_surfaces_.clear();
135 140
136 // Recreate all in-flight surfaces and put the recreated copies in the queue. 141 // Recreate all in-flight surfaces and put the recreated copies in the queue.
137 for (auto& surface : in_flight_surfaces_) 142 for (auto& surface : in_flight_surfaces_)
138 surface = RecreateBuffer(std::move(surface)); 143 surface = RecreateBuffer(std::move(surface));
139 144
140 current_surface_ = RecreateBuffer(std::move(current_surface_)); 145 current_surface_ = RecreateBuffer(std::move(current_surface_));
141 displayed_surface_ = RecreateBuffer(std::move(displayed_surface_)); 146 displayed_surface_ = RecreateBuffer(std::move(displayed_surface_));
142 147
143 if (current_surface_) { 148 if (current_surface_) {
144 // If we have a texture bound, we will need to re-bind it. 149 // If we have a texture bound, we will need to re-bind it.
145 gl_->BindFramebuffer(GL_FRAMEBUFFER, fbo_); 150 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL();
146 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 151 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_);
147 texture_target_, current_surface_->texture, 0); 152 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
153 texture_target_, current_surface_->texture, 0);
148 } 154 }
149 } 155 }
150 156
151 std::unique_ptr<BufferQueue::AllocatedSurface> BufferQueue::RecreateBuffer( 157 std::unique_ptr<BufferQueue::AllocatedSurface> BufferQueue::RecreateBuffer(
152 std::unique_ptr<AllocatedSurface> surface) { 158 std::unique_ptr<AllocatedSurface> surface) {
153 if (!surface) 159 if (!surface)
154 return nullptr; 160 return nullptr;
155 161
156 std::unique_ptr<AllocatedSurface> new_surface(GetNextSurface()); 162 std::unique_ptr<AllocatedSurface> new_surface(GetNextSurface());
157 if (!new_surface) 163 if (!new_surface)
(...skipping 22 matching lines...) Expand all
180 // expected to arrive. 186 // expected to arrive.
181 for (auto& surface : in_flight_surfaces_) 187 for (auto& surface : in_flight_surfaces_)
182 surface = nullptr; 188 surface = nullptr;
183 available_surfaces_.clear(); 189 available_surfaces_.clear();
184 } 190 }
185 191
186 void BufferQueue::FreeSurfaceResources(AllocatedSurface* surface) { 192 void BufferQueue::FreeSurfaceResources(AllocatedSurface* surface) {
187 if (!surface->texture) 193 if (!surface->texture)
188 return; 194 return;
189 195
190 gl_->BindTexture(texture_target_, surface->texture); 196 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL();
191 gl_->ReleaseTexImage2DCHROMIUM(texture_target_, surface->image); 197 gl->BindTexture(texture_target_, surface->texture);
192 gl_->DeleteTextures(1, &surface->texture); 198 gl->ReleaseTexImage2DCHROMIUM(texture_target_, surface->image);
193 gl_->DestroyImageCHROMIUM(surface->image); 199 gl->DeleteTextures(1, &surface->texture);
200 gl->DestroyImageCHROMIUM(surface->image);
194 surface->buffer.reset(); 201 surface->buffer.reset();
195 allocated_count_--; 202 allocated_count_--;
196 } 203 }
197 204
198 std::unique_ptr<BufferQueue::AllocatedSurface> BufferQueue::GetNextSurface() { 205 std::unique_ptr<BufferQueue::AllocatedSurface> BufferQueue::GetNextSurface() {
199 if (!available_surfaces_.empty()) { 206 if (!available_surfaces_.empty()) {
200 std::unique_ptr<AllocatedSurface> surface = 207 std::unique_ptr<AllocatedSurface> surface =
201 std::move(available_surfaces_.back()); 208 std::move(available_surfaces_.back());
202 available_surfaces_.pop_back(); 209 available_surfaces_.pop_back();
203 return surface; 210 return surface;
204 } 211 }
205 212
206 GLuint texture; 213 unsigned int texture = 0;
207 gl_->GenTextures(1, &texture); 214 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL();
215 gl->GenTextures(1, &texture);
216 if (!texture)
217 return nullptr;
208 218
209 // We don't want to allow anything more than triple buffering. 219 // We don't want to allow anything more than triple buffering.
210 DCHECK_LT(allocated_count_, 4U); 220 DCHECK_LT(allocated_count_, 4U);
211 221
212 std::unique_ptr<gfx::GpuMemoryBuffer> buffer( 222 std::unique_ptr<gfx::GpuMemoryBuffer> buffer(
213 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( 223 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer(
214 size_, gpu::DefaultBufferFormatForImageFormat(internal_format_), 224 size_, gpu::DefaultBufferFormatForImageFormat(internal_format_),
215 gfx::BufferUsage::SCANOUT, surface_handle_)); 225 gfx::BufferUsage::SCANOUT, surface_handle_));
216 if (!buffer.get()) { 226 if (!buffer.get()) {
217 gl_->DeleteTextures(1, &texture); 227 gl->DeleteTextures(1, &texture);
218 DLOG(ERROR) << "Failed to allocate GPU memory buffer"; 228 DLOG(ERROR) << "Failed to allocate GPU memory buffer";
219 return nullptr; 229 return nullptr;
220 } 230 }
221 231
222 unsigned int id = 232 unsigned int id =
223 gl_->CreateImageCHROMIUM(buffer->AsClientBuffer(), size_.width(), 233 gl->CreateImageCHROMIUM(buffer->AsClientBuffer(), size_.width(),
224 size_.height(), internal_format_); 234 size_.height(), internal_format_);
225 if (!id) { 235 if (!id) {
226 LOG(ERROR) << "Failed to allocate backing image surface"; 236 LOG(ERROR) << "Failed to allocate backing image surface";
227 gl_->DeleteTextures(1, &texture); 237 gl->DeleteTextures(1, &texture);
228 return nullptr; 238 return nullptr;
229 } 239 }
230 240
231 allocated_count_++; 241 allocated_count_++;
232 gl_->BindTexture(texture_target_, texture); 242 gl->BindTexture(texture_target_, texture);
233 gl_->BindTexImage2DCHROMIUM(texture_target_, id); 243 gl->BindTexImage2DCHROMIUM(texture_target_, id);
234 return base::WrapUnique(new AllocatedSurface(this, std::move(buffer), texture, 244 return base::WrapUnique(new AllocatedSurface(this, std::move(buffer), texture,
235 id, gfx::Rect(size_))); 245 id, gfx::Rect(size_)));
236 } 246 }
237 247
238 BufferQueue::AllocatedSurface::AllocatedSurface( 248 BufferQueue::AllocatedSurface::AllocatedSurface(
239 BufferQueue* buffer_queue, 249 BufferQueue* buffer_queue,
240 std::unique_ptr<gfx::GpuMemoryBuffer> buffer, 250 std::unique_ptr<gfx::GpuMemoryBuffer> buffer,
241 unsigned int texture, 251 unsigned int texture,
242 unsigned int image, 252 unsigned int image,
243 const gfx::Rect& rect) 253 const gfx::Rect& rect)
244 : buffer_queue(buffer_queue), 254 : buffer_queue(buffer_queue),
245 buffer(buffer.release()), 255 buffer(buffer.release()),
246 texture(texture), 256 texture(texture),
247 image(image), 257 image(image),
248 damage(rect) {} 258 damage(rect) {}
249 259
250 BufferQueue::AllocatedSurface::~AllocatedSurface() { 260 BufferQueue::AllocatedSurface::~AllocatedSurface() {
251 buffer_queue->FreeSurfaceResources(this); 261 buffer_queue->FreeSurfaceResources(this);
252 } 262 }
253 263
254 } // namespace display_compositor 264 } // namespace display_compositor
OLDNEW
« no previous file with comments | « components/display_compositor/buffer_queue.h ('k') | components/display_compositor/buffer_queue_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698