OLD | NEW |
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 "content/browser/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 "cc/output/context_provider.h" |
11 #include "content/browser/compositor/gl_helper.h" | 11 #include "components/display_compositor/gl_helper.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" | 14 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" |
15 #include "gpu/command_buffer/common/gpu_memory_buffer_support.h" | 15 #include "gpu/command_buffer/common/gpu_memory_buffer_support.h" |
16 #include "third_party/skia/include/core/SkRect.h" | 16 #include "third_party/skia/include/core/SkRect.h" |
17 #include "third_party/skia/include/core/SkRegion.h" | 17 #include "third_party/skia/include/core/SkRegion.h" |
18 #include "ui/gfx/gpu_memory_buffer.h" | 18 #include "ui/gfx/gpu_memory_buffer.h" |
19 #include "ui/gfx/skia_util.h" | 19 #include "ui/gfx/skia_util.h" |
20 | 20 |
21 namespace content { | 21 namespace display_compositor { |
22 | 22 |
23 BufferQueue::BufferQueue(scoped_refptr<cc::ContextProvider> context_provider, | 23 BufferQueue::BufferQueue(scoped_refptr<cc::ContextProvider> context_provider, |
24 unsigned int texture_target, | 24 unsigned int texture_target, |
25 unsigned int internalformat, | 25 unsigned int internalformat, |
26 GLHelper* gl_helper, | 26 GLHelper* gl_helper, |
27 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 27 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
28 int surface_id) | 28 int surface_id) |
29 : context_provider_(context_provider), | 29 : context_provider_(context_provider), |
30 fbo_(0), | 30 fbo_(0), |
31 allocated_count_(0), | 31 allocated_count_(0), |
(...skipping 26 matching lines...) Expand all Loading... |
58 if (current_surface_) { | 58 if (current_surface_) { |
59 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | 59 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
60 texture_target_, current_surface_->texture, 0); | 60 texture_target_, current_surface_->texture, 0); |
61 } | 61 } |
62 } | 62 } |
63 | 63 |
64 void BufferQueue::CopyBufferDamage(int texture, | 64 void BufferQueue::CopyBufferDamage(int texture, |
65 int source_texture, | 65 int source_texture, |
66 const gfx::Rect& new_damage, | 66 const gfx::Rect& new_damage, |
67 const gfx::Rect& old_damage) { | 67 const gfx::Rect& old_damage) { |
68 gl_helper_->CopySubBufferDamage( | 68 gl_helper_->CopySubBufferDamage(texture_target_, texture, source_texture, |
69 texture_target_, texture, source_texture, | 69 SkRegion(gfx::RectToSkIRect(new_damage)), |
70 SkRegion(gfx::RectToSkIRect(new_damage)), | 70 SkRegion(gfx::RectToSkIRect(old_damage))); |
71 SkRegion(gfx::RectToSkIRect(old_damage))); | |
72 } | 71 } |
73 | 72 |
74 void BufferQueue::UpdateBufferDamage(const gfx::Rect& damage) { | 73 void BufferQueue::UpdateBufferDamage(const gfx::Rect& damage) { |
75 if (displayed_surface_) | 74 if (displayed_surface_) |
76 displayed_surface_->damage.Union(damage); | 75 displayed_surface_->damage.Union(damage); |
77 for (auto& surface : available_surfaces_) | 76 for (auto& surface : available_surfaces_) |
78 surface->damage.Union(damage); | 77 surface->damage.Union(damage); |
79 for (auto& surface : in_flight_surfaces_) { | 78 for (auto& surface : in_flight_surfaces_) { |
80 if (surface) | 79 if (surface) |
81 surface->damage.Union(damage); | 80 surface->damage.Union(damage); |
(...skipping 26 matching lines...) Expand all Loading... |
108 UpdateBufferDamage(damage); | 107 UpdateBufferDamage(damage); |
109 in_flight_surfaces_.push_back(std::move(current_surface_)); | 108 in_flight_surfaces_.push_back(std::move(current_surface_)); |
110 // Some things reset the framebuffer (CopySubBufferDamage, some GLRenderer | 109 // Some things reset the framebuffer (CopySubBufferDamage, some GLRenderer |
111 // paths), so ensure we restore it here. | 110 // paths), so ensure we restore it here. |
112 context_provider_->ContextGL()->BindFramebuffer(GL_FRAMEBUFFER, fbo_); | 111 context_provider_->ContextGL()->BindFramebuffer(GL_FRAMEBUFFER, fbo_); |
113 } | 112 } |
114 | 113 |
115 void BufferQueue::Reshape(const gfx::Size& size, float scale_factor) { | 114 void BufferQueue::Reshape(const gfx::Size& size, float scale_factor) { |
116 if (size == size_) | 115 if (size == size_) |
117 return; | 116 return; |
| 117 #if !defined(OS_MACOSX) |
118 // 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 |
119 // is cause for concern or if it is benign. | 119 // is cause for concern or if it is benign. |
120 // http://crbug.com/524624 | 120 // http://crbug.com/524624 |
121 #if !defined(OS_MACOSX) | |
122 DCHECK(!current_surface_); | 121 DCHECK(!current_surface_); |
123 #endif | 122 #endif |
124 size_ = size; | 123 size_ = size; |
125 | 124 |
126 // TODO: add stencil buffer when needed. | 125 // TODO: add stencil buffer when needed. |
127 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); | 126 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); |
128 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_); | 127 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_); |
129 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | 128 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
130 texture_target_, 0, 0); | 129 texture_target_, 0, 0); |
131 | 130 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 std::unique_ptr<gfx::GpuMemoryBuffer> buffer( | 222 std::unique_ptr<gfx::GpuMemoryBuffer> buffer( |
224 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( | 223 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( |
225 size_, gpu::DefaultBufferFormatForImageFormat(internal_format_), | 224 size_, gpu::DefaultBufferFormatForImageFormat(internal_format_), |
226 gfx::BufferUsage::SCANOUT, surface_id_)); | 225 gfx::BufferUsage::SCANOUT, surface_id_)); |
227 if (!buffer.get()) { | 226 if (!buffer.get()) { |
228 gl->DeleteTextures(1, &texture); | 227 gl->DeleteTextures(1, &texture); |
229 DLOG(ERROR) << "Failed to allocate GPU memory buffer"; | 228 DLOG(ERROR) << "Failed to allocate GPU memory buffer"; |
230 return nullptr; | 229 return nullptr; |
231 } | 230 } |
232 | 231 |
233 unsigned int id = gl->CreateImageCHROMIUM( | 232 unsigned int id = |
234 buffer->AsClientBuffer(), size_.width(), size_.height(), | 233 gl->CreateImageCHROMIUM(buffer->AsClientBuffer(), size_.width(), |
235 internal_format_); | 234 size_.height(), internal_format_); |
236 if (!id) { | 235 if (!id) { |
237 LOG(ERROR) << "Failed to allocate backing image surface"; | 236 LOG(ERROR) << "Failed to allocate backing image surface"; |
238 gl->DeleteTextures(1, &texture); | 237 gl->DeleteTextures(1, &texture); |
239 return nullptr; | 238 return nullptr; |
240 } | 239 } |
241 | 240 |
242 allocated_count_++; | 241 allocated_count_++; |
243 gl->BindTexture(texture_target_, texture); | 242 gl->BindTexture(texture_target_, texture); |
244 gl->BindTexImage2DCHROMIUM(texture_target_, id); | 243 gl->BindTexImage2DCHROMIUM(texture_target_, id); |
245 return base::WrapUnique(new AllocatedSurface(this, std::move(buffer), texture, | 244 return base::WrapUnique(new AllocatedSurface(this, std::move(buffer), texture, |
246 id, gfx::Rect(size_))); | 245 id, gfx::Rect(size_))); |
247 } | 246 } |
248 | 247 |
249 BufferQueue::AllocatedSurface::AllocatedSurface( | 248 BufferQueue::AllocatedSurface::AllocatedSurface( |
250 BufferQueue* buffer_queue, | 249 BufferQueue* buffer_queue, |
251 std::unique_ptr<gfx::GpuMemoryBuffer> buffer, | 250 std::unique_ptr<gfx::GpuMemoryBuffer> buffer, |
252 unsigned int texture, | 251 unsigned int texture, |
253 unsigned int image, | 252 unsigned int image, |
254 const gfx::Rect& rect) | 253 const gfx::Rect& rect) |
255 : buffer_queue(buffer_queue), | 254 : buffer_queue(buffer_queue), |
256 buffer(buffer.release()), | 255 buffer(buffer.release()), |
257 texture(texture), | 256 texture(texture), |
258 image(image), | 257 image(image), |
259 damage(rect) {} | 258 damage(rect) {} |
260 | 259 |
261 BufferQueue::AllocatedSurface::~AllocatedSurface() { | 260 BufferQueue::AllocatedSurface::~AllocatedSurface() { |
262 buffer_queue->FreeSurfaceResources(this); | 261 buffer_queue->FreeSurfaceResources(this); |
263 } | 262 } |
264 | 263 |
265 } // namespace content | 264 } // namespace display_compositor |
OLD | NEW |