| 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 "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 "components/display_compositor/gl_helper.h" | 10 #include "components/display_compositor/gl_helper.h" |
| 11 #include "gpu/GLES2/gl2extchromium.h" | 11 #include "gpu/GLES2/gl2extchromium.h" |
| 12 #include "gpu/command_buffer/client/gles2_interface.h" | 12 #include "gpu/command_buffer/client/gles2_interface.h" |
| 13 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" | 13 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" |
| 14 #include "gpu/command_buffer/common/gpu_memory_buffer_support.h" | 14 #include "gpu/command_buffer/common/gpu_memory_buffer_support.h" |
| 15 #include "third_party/skia/include/core/SkRect.h" | 15 #include "third_party/skia/include/core/SkRect.h" |
| 16 #include "third_party/skia/include/core/SkRegion.h" | 16 #include "third_party/skia/include/core/SkRegion.h" |
| 17 #include "ui/gfx/gpu_memory_buffer.h" | 17 #include "ui/gfx/gpu_memory_buffer.h" |
| 18 #include "ui/gfx/skia_util.h" | 18 #include "ui/gfx/skia_util.h" |
| 19 | 19 |
| 20 namespace display_compositor { | 20 namespace display_compositor { |
| 21 | 21 |
| 22 BufferQueue::BufferQueue(gpu::gles2::GLES2Interface* gl, | 22 BufferQueue::BufferQueue(gpu::gles2::GLES2Interface* gl, |
| 23 unsigned int texture_target, | 23 uint32_t texture_target, |
| 24 unsigned int internalformat, | 24 uint32_t internal_format, |
| 25 GLHelper* gl_helper, | 25 GLHelper* gl_helper, |
| 26 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 26 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 27 gpu::SurfaceHandle surface_handle) | 27 gpu::SurfaceHandle surface_handle) |
| 28 : gl_(gl), | 28 : gl_(gl), |
| 29 fbo_(0), | 29 fbo_(0), |
| 30 allocated_count_(0), | 30 allocated_count_(0), |
| 31 texture_target_(texture_target), | 31 texture_target_(texture_target), |
| 32 internal_format_(internalformat), | 32 internal_format_(internal_format), |
| 33 gl_helper_(gl_helper), | 33 gl_helper_(gl_helper), |
| 34 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), | 34 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), |
| 35 surface_handle_(surface_handle) {} | 35 surface_handle_(surface_handle) {} |
| 36 | 36 |
| 37 BufferQueue::~BufferQueue() { | 37 BufferQueue::~BufferQueue() { |
| 38 FreeAllSurfaces(); | 38 FreeAllSurfaces(); |
| 39 | 39 |
| 40 if (fbo_) | 40 if (fbo_) |
| 41 gl_->DeleteFramebuffers(1, &fbo_); | 41 gl_->DeleteFramebuffers(1, &fbo_); |
| 42 } | 42 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 surface->damage.Union(damage); | 76 surface->damage.Union(damage); |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 | 79 |
| 80 void BufferQueue::SwapBuffers(const gfx::Rect& damage) { | 80 void BufferQueue::SwapBuffers(const gfx::Rect& damage) { |
| 81 if (current_surface_) { | 81 if (current_surface_) { |
| 82 if (damage != gfx::Rect(size_)) { | 82 if (damage != gfx::Rect(size_)) { |
| 83 // Copy damage from the most recently swapped buffer. In the event that | 83 // Copy damage from the most recently swapped buffer. In the event that |
| 84 // the buffer was destroyed and failed to recreate, pick from the most | 84 // the buffer was destroyed and failed to recreate, pick from the most |
| 85 // recently available buffer. | 85 // recently available buffer. |
| 86 unsigned int texture_id = 0; | 86 uint32_t texture_id = 0; |
| 87 for (auto& surface : base::Reversed(in_flight_surfaces_)) { | 87 for (auto& surface : base::Reversed(in_flight_surfaces_)) { |
| 88 if (surface) { | 88 if (surface) { |
| 89 texture_id = surface->texture; | 89 texture_id = surface->texture; |
| 90 break; | 90 break; |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 if (!texture_id && displayed_surface_) | 93 if (!texture_id && displayed_surface_) |
| 94 texture_id = displayed_surface_->texture; | 94 texture_id = displayed_surface_->texture; |
| 95 | 95 |
| 96 if (texture_id) { | 96 if (texture_id) { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 std::unique_ptr<gfx::GpuMemoryBuffer> buffer( | 212 std::unique_ptr<gfx::GpuMemoryBuffer> buffer( |
| 213 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( | 213 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( |
| 214 size_, gpu::DefaultBufferFormatForImageFormat(internal_format_), | 214 size_, gpu::DefaultBufferFormatForImageFormat(internal_format_), |
| 215 gfx::BufferUsage::SCANOUT, surface_handle_)); | 215 gfx::BufferUsage::SCANOUT, surface_handle_)); |
| 216 if (!buffer.get()) { | 216 if (!buffer.get()) { |
| 217 gl_->DeleteTextures(1, &texture); | 217 gl_->DeleteTextures(1, &texture); |
| 218 DLOG(ERROR) << "Failed to allocate GPU memory buffer"; | 218 DLOG(ERROR) << "Failed to allocate GPU memory buffer"; |
| 219 return nullptr; | 219 return nullptr; |
| 220 } | 220 } |
| 221 | 221 |
| 222 unsigned int id = | 222 uint32_t id = |
| 223 gl_->CreateImageCHROMIUM(buffer->AsClientBuffer(), size_.width(), | 223 gl_->CreateImageCHROMIUM(buffer->AsClientBuffer(), size_.width(), |
| 224 size_.height(), internal_format_); | 224 size_.height(), internal_format_); |
| 225 if (!id) { | 225 if (!id) { |
| 226 LOG(ERROR) << "Failed to allocate backing image surface"; | 226 LOG(ERROR) << "Failed to allocate backing image surface"; |
| 227 gl_->DeleteTextures(1, &texture); | 227 gl_->DeleteTextures(1, &texture); |
| 228 return nullptr; | 228 return nullptr; |
| 229 } | 229 } |
| 230 | 230 |
| 231 allocated_count_++; | 231 allocated_count_++; |
| 232 gl_->BindTexture(texture_target_, texture); | 232 gl_->BindTexture(texture_target_, texture); |
| 233 gl_->BindTexImage2DCHROMIUM(texture_target_, id); | 233 gl_->BindTexImage2DCHROMIUM(texture_target_, id); |
| 234 return base::WrapUnique(new AllocatedSurface(this, std::move(buffer), texture, | 234 return base::WrapUnique(new AllocatedSurface(this, std::move(buffer), texture, |
| 235 id, gfx::Rect(size_))); | 235 id, gfx::Rect(size_))); |
| 236 } | 236 } |
| 237 | 237 |
| 238 BufferQueue::AllocatedSurface::AllocatedSurface( | 238 BufferQueue::AllocatedSurface::AllocatedSurface( |
| 239 BufferQueue* buffer_queue, | 239 BufferQueue* buffer_queue, |
| 240 std::unique_ptr<gfx::GpuMemoryBuffer> buffer, | 240 std::unique_ptr<gfx::GpuMemoryBuffer> buffer, |
| 241 unsigned int texture, | 241 uint32_t texture, |
| 242 unsigned int image, | 242 uint32_t image, |
| 243 const gfx::Rect& rect) | 243 const gfx::Rect& rect) |
| 244 : buffer_queue(buffer_queue), | 244 : buffer_queue(buffer_queue), |
| 245 buffer(buffer.release()), | 245 buffer(buffer.release()), |
| 246 texture(texture), | 246 texture(texture), |
| 247 image(image), | 247 image(image), |
| 248 damage(rect) {} | 248 damage(rect) {} |
| 249 | 249 |
| 250 BufferQueue::AllocatedSurface::~AllocatedSurface() { | 250 BufferQueue::AllocatedSurface::~AllocatedSurface() { |
| 251 buffer_queue->FreeSurfaceResources(this); | 251 buffer_queue->FreeSurfaceResources(this); |
| 252 } | 252 } |
| 253 | 253 |
| 254 } // namespace display_compositor | 254 } // namespace display_compositor |
| OLD | NEW |