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

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

Issue 1881793002: SurfacelessSurfaces for Mus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix build Created 4 years, 8 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 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 "content/browser/compositor/buffer_queue.h" 5 #include "components/mus/surfaces/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"
10 #include "cc/output/context_provider.h" 9 #include "cc/output/context_provider.h"
11 #include "content/browser/compositor/gl_helper.h" 10 #include "components/mus/gles2/gl_helper.h"
11 #include "components/mus/gles2/ozone_gpu_memory_buffer.h"
12 #include "gpu/GLES2/gl2extchromium.h" 12 #include "gpu/GLES2/gl2extchromium.h"
13 #include "gpu/command_buffer/client/gles2_interface.h" 13 #include "gpu/command_buffer/client/gles2_interface.h"
14 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h"
15 #include "gpu/command_buffer/common/gpu_memory_buffer_support.h" 14 #include "gpu/command_buffer/common/gpu_memory_buffer_support.h"
16 #include "gpu/command_buffer/service/image_factory.h"
17 #include "third_party/skia/include/core/SkRect.h" 15 #include "third_party/skia/include/core/SkRect.h"
18 #include "third_party/skia/include/core/SkRegion.h" 16 #include "third_party/skia/include/core/SkRegion.h"
19 #include "ui/gfx/gpu_memory_buffer.h" 17 #include "ui/gfx/gpu_memory_buffer.h"
20 #include "ui/gfx/skia_util.h" 18 #include "ui/gfx/skia_util.h"
21 19
22 namespace content { 20 namespace mus {
23 21
24 BufferQueue::BufferQueue(scoped_refptr<cc::ContextProvider> context_provider, 22 BufferQueue::BufferQueue(scoped_refptr<cc::ContextProvider> context_provider,
25 unsigned int texture_target, 23 unsigned int texture_target,
26 unsigned int internalformat, 24 unsigned int internalformat,
27 GLHelper* gl_helper, 25 gfx::AcceleratedWidget widget)
28 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
29 int surface_id)
30 : context_provider_(context_provider), 26 : context_provider_(context_provider),
31 fbo_(0), 27 fbo_(0),
32 allocated_count_(0), 28 allocated_count_(0),
33 texture_target_(texture_target), 29 texture_target_(texture_target),
34 internal_format_(internalformat), 30 internal_format_(internalformat),
35 gl_helper_(gl_helper), 31 widget_(widget) {}
36 gpu_memory_buffer_manager_(gpu_memory_buffer_manager),
37 surface_id_(surface_id) {}
38 32
39 BufferQueue::~BufferQueue() { 33 BufferQueue::~BufferQueue() {
40 FreeAllSurfaces(); 34 FreeAllSurfaces();
41 35
42 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); 36 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL();
43 if (fbo_) 37 if (fbo_)
44 gl->DeleteFramebuffers(1, &fbo_); 38 gl->DeleteFramebuffers(1, &fbo_);
45 } 39 }
46 40
47 void BufferQueue::Initialize() { 41 void BufferQueue::Initialize() {
42 DCHECK(context_provider_);
48 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); 43 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL();
44 DCHECK(gl);
49 gl->GenFramebuffers(1, &fbo_); 45 gl->GenFramebuffers(1, &fbo_);
50 } 46 }
51 47
52 void BufferQueue::BindFramebuffer() { 48 void BufferQueue::BindFramebuffer() {
53 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); 49 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL();
54 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_); 50 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_);
55 51
56 if (!current_surface_) 52 if (!current_surface_)
57 current_surface_ = GetNextSurface(); 53 current_surface_ = GetNextSurface();
58 54
59 if (current_surface_) { 55 if (current_surface_) {
60 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 56 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
61 texture_target_, current_surface_->texture, 0); 57 texture_target_, current_surface_->texture, 0);
62 } 58 }
63 } 59 }
64 60
65 void BufferQueue::CopyBufferDamage(int texture, 61 void BufferQueue::CopyBufferDamage(int texture,
66 int source_texture, 62 int source_texture,
67 const gfx::Rect& new_damage, 63 const gfx::Rect& new_damage,
68 const gfx::Rect& old_damage) { 64 const gfx::Rect& old_damage) {
69 gl_helper_->CopySubBufferDamage( 65 GLCopySubBufferDamage(context_provider_->ContextGL(), texture_target_,
70 texture_target_, texture, source_texture, 66 texture, source_texture,
71 SkRegion(gfx::RectToSkIRect(new_damage)), 67 SkRegion(gfx::RectToSkIRect(new_damage)),
72 SkRegion(gfx::RectToSkIRect(old_damage))); 68 SkRegion(gfx::RectToSkIRect(old_damage)));
73 } 69 }
74 70
75 void BufferQueue::UpdateBufferDamage(const gfx::Rect& damage) { 71 void BufferQueue::UpdateBufferDamage(const gfx::Rect& damage) {
76 if (displayed_surface_) 72 if (displayed_surface_)
77 displayed_surface_->damage.Union(damage); 73 displayed_surface_->damage.Union(damage);
78 for (auto& surface : available_surfaces_) 74 for (auto& surface : available_surfaces_)
79 surface->damage.Union(damage); 75 surface->damage.Union(damage);
80 for (auto& surface : in_flight_surfaces_) { 76 for (auto& surface : in_flight_surfaces_) {
81 if (surface) 77 if (surface)
82 surface->damage.Union(damage); 78 surface->damage.Union(damage);
(...skipping 26 matching lines...) Expand all
109 UpdateBufferDamage(damage); 105 UpdateBufferDamage(damage);
110 in_flight_surfaces_.push_back(std::move(current_surface_)); 106 in_flight_surfaces_.push_back(std::move(current_surface_));
111 // Some things reset the framebuffer (CopySubBufferDamage, some GLRenderer 107 // Some things reset the framebuffer (CopySubBufferDamage, some GLRenderer
112 // paths), so ensure we restore it here. 108 // paths), so ensure we restore it here.
113 context_provider_->ContextGL()->BindFramebuffer(GL_FRAMEBUFFER, fbo_); 109 context_provider_->ContextGL()->BindFramebuffer(GL_FRAMEBUFFER, fbo_);
114 } 110 }
115 111
116 void BufferQueue::Reshape(const gfx::Size& size, float scale_factor) { 112 void BufferQueue::Reshape(const gfx::Size& size, float scale_factor) {
117 if (size == size_) 113 if (size == size_)
118 return; 114 return;
119 // TODO(ccameron): This assert is being hit on Mac try jobs. Determine if that 115
120 // is cause for concern or if it is benign.
121 // http://crbug.com/524624
122 #if !defined(OS_MACOSX)
123 DCHECK(!current_surface_);
124 #endif
125 size_ = size; 116 size_ = size;
126 117
127 // TODO: add stencil buffer when needed. 118 // TODO: add stencil buffer when needed.
128 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); 119 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL();
129 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_); 120 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_);
130 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 121 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
131 texture_target_, 0, 0); 122 texture_target_, 0, 0);
132 123
133 FreeAllSurfaces(); 124 FreeAllSurfaces();
134 } 125 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 } 183 }
193 184
194 void BufferQueue::FreeSurfaceResources(AllocatedSurface* surface) { 185 void BufferQueue::FreeSurfaceResources(AllocatedSurface* surface) {
195 if (!surface->texture) 186 if (!surface->texture)
196 return; 187 return;
197 188
198 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); 189 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL();
199 gl->BindTexture(texture_target_, surface->texture); 190 gl->BindTexture(texture_target_, surface->texture);
200 gl->ReleaseTexImage2DCHROMIUM(texture_target_, surface->image); 191 gl->ReleaseTexImage2DCHROMIUM(texture_target_, surface->image);
201 gl->DeleteTextures(1, &surface->texture); 192 gl->DeleteTextures(1, &surface->texture);
193 // TODO(rjk): Implement image deletion.
202 gl->DestroyImageCHROMIUM(surface->image); 194 gl->DestroyImageCHROMIUM(surface->image);
203 surface->buffer.reset(); 195 surface->buffer.reset();
204 allocated_count_--; 196 allocated_count_--;
205 } 197 }
206 198
207 std::unique_ptr<BufferQueue::AllocatedSurface> BufferQueue::GetNextSurface() { 199 std::unique_ptr<BufferQueue::AllocatedSurface> BufferQueue::GetNextSurface() {
208 if (!available_surfaces_.empty()) { 200 if (!available_surfaces_.empty()) {
209 std::unique_ptr<AllocatedSurface> surface = 201 std::unique_ptr<AllocatedSurface> surface =
210 std::move(available_surfaces_.back()); 202 std::move(available_surfaces_.back());
211 available_surfaces_.pop_back(); 203 available_surfaces_.pop_back();
212 return surface; 204 return surface;
213 } 205 }
214 206
215 unsigned int texture = 0; 207 unsigned int texture = 0;
216 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); 208 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL();
217 gl->GenTextures(1, &texture); 209 gl->GenTextures(1, &texture);
218 if (!texture) 210 if (!texture)
219 return nullptr; 211 return nullptr;
220 212
221 // We don't want to allow anything more than triple buffering. 213 // We don't want to allow anything more than triple buffering.
222 DCHECK_LT(allocated_count_, 4U); 214 DCHECK_LT(allocated_count_, 4U);
223 215
224 std::unique_ptr<gfx::GpuMemoryBuffer> buffer( 216 std::unique_ptr<gfx::GpuMemoryBuffer> buffer(
225 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( 217 OzoneGpuMemoryBuffer::CreateOzoneGpuMemoryBuffer(
226 size_, gpu::DefaultBufferFormatForImageFormat(internal_format_), 218 size_, gpu::DefaultBufferFormatForImageFormat(internal_format_),
227 gfx::BufferUsage::SCANOUT, surface_id_)); 219 gfx::BufferUsage::SCANOUT, widget_));
220
228 if (!buffer.get()) { 221 if (!buffer.get()) {
229 gl->DeleteTextures(1, &texture); 222 gl->DeleteTextures(1, &texture);
230 DLOG(ERROR) << "Failed to allocate GPU memory buffer"; 223 DLOG(ERROR) << "Failed to allocate GPU memory buffer";
231 return nullptr; 224 return nullptr;
232 } 225 }
233 226
234 unsigned int id = gl->CreateImageCHROMIUM( 227 // This ends up calling back into the CommandBufferLocal via its
235 buffer->AsClientBuffer(), size_.width(), size_.height(), 228 // implementation of the GpuControl interface. In that case, we need to handle
236 internal_format_); 229 // the given buffer pointer there.
230 unsigned int id =
231 gl->CreateImageCHROMIUM(buffer->AsClientBuffer(), size_.width(),
232 size_.height(), internal_format_);
237 if (!id) { 233 if (!id) {
238 LOG(ERROR) << "Failed to allocate backing image surface"; 234 LOG(ERROR) << "Failed to allocate backing image surface";
239 gl->DeleteTextures(1, &texture); 235 gl->DeleteTextures(1, &texture);
240 return nullptr; 236 return nullptr;
241 } 237 }
242 238
243 allocated_count_++; 239 allocated_count_++;
244 gl->BindTexture(texture_target_, texture); 240 gl->BindTexture(texture_target_, texture);
245 gl->BindTexImage2DCHROMIUM(texture_target_, id); 241 gl->BindTexImage2DCHROMIUM(texture_target_, id);
242 // It doesn't end up in the queue to re-use until we handle the page flip.
246 return base::WrapUnique(new AllocatedSurface(this, std::move(buffer), texture, 243 return base::WrapUnique(new AllocatedSurface(this, std::move(buffer), texture,
247 id, gfx::Rect(size_))); 244 id, gfx::Rect(size_)));
248 } 245 }
249 246
250 BufferQueue::AllocatedSurface::AllocatedSurface( 247 BufferQueue::AllocatedSurface::AllocatedSurface(
251 BufferQueue* buffer_queue, 248 BufferQueue* buffer_queue,
252 std::unique_ptr<gfx::GpuMemoryBuffer> buffer, 249 std::unique_ptr<gfx::GpuMemoryBuffer> buffer,
253 unsigned int texture, 250 unsigned int texture,
254 unsigned int image, 251 unsigned int image,
255 const gfx::Rect& rect) 252 const gfx::Rect& rect)
256 : buffer_queue(buffer_queue), 253 : buffer_queue(buffer_queue),
257 buffer(buffer.release()), 254 buffer(buffer.release()),
258 texture(texture), 255 texture(texture),
259 image(image), 256 image(image),
260 damage(rect) {} 257 damage(rect) {}
261 258
262 BufferQueue::AllocatedSurface::~AllocatedSurface() { 259 BufferQueue::AllocatedSurface::~AllocatedSurface() {
263 buffer_queue->FreeSurfaceResources(this); 260 buffer_queue->FreeSurfaceResources(this);
264 } 261 }
265 262
266 } // namespace content 263 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/surfaces/buffer_queue.h ('k') | components/mus/surfaces/direct_output_surface_ozone.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698