| 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" |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 return nullptr; | 255 return nullptr; |
| 256 } | 256 } |
| 257 | 257 |
| 258 allocated_count_++; | 258 allocated_count_++; |
| 259 gl_->BindTexture(texture_target_, texture); | 259 gl_->BindTexture(texture_target_, texture); |
| 260 gl_->BindTexImage2DCHROMIUM(texture_target_, id); | 260 gl_->BindTexImage2DCHROMIUM(texture_target_, id); |
| 261 return base::MakeUnique<AllocatedSurface>(this, std::move(buffer), texture, | 261 return base::MakeUnique<AllocatedSurface>(this, std::move(buffer), texture, |
| 262 id, stencil, gfx::Rect(size_)); | 262 id, stencil, gfx::Rect(size_)); |
| 263 } | 263 } |
| 264 | 264 |
| 265 void BufferQueue::ReadbackDisplayedFramebuffer( |
| 266 SkBitmap* bitmap, |
| 267 const base::Callback<void(bool)>& callback) { |
| 268 if (!displayed_surface_) { |
| 269 callback.Run(false); |
| 270 return; |
| 271 } |
| 272 GLuint texture = gl_helper_->CreateTexture(); |
| 273 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); |
| 274 gl_->CopyTextureCHROMIUM(displayed_surface_->texture, 0, GL_TEXTURE_2D, |
| 275 texture, 0, GL_RGBA, GL_UNSIGNED_BYTE, false, false, |
| 276 false); |
| 277 bitmap->allocN32Pixels(size_.width(), size_.height()); |
| 278 gl_helper_->ReadbackTextureAsync( |
| 279 texture, size_, static_cast<unsigned char*>(bitmap->getPixels()), |
| 280 kRGBA_8888_SkColorType, callback); |
| 281 gl_helper_->DeleteTexture(texture); |
| 282 } |
| 283 |
| 265 BufferQueue::AllocatedSurface::AllocatedSurface( | 284 BufferQueue::AllocatedSurface::AllocatedSurface( |
| 266 BufferQueue* buffer_queue, | 285 BufferQueue* buffer_queue, |
| 267 std::unique_ptr<gfx::GpuMemoryBuffer> buffer, | 286 std::unique_ptr<gfx::GpuMemoryBuffer> buffer, |
| 268 uint32_t texture, | 287 uint32_t texture, |
| 269 uint32_t image, | 288 uint32_t image, |
| 270 uint32_t stencil, | 289 uint32_t stencil, |
| 271 const gfx::Rect& rect) | 290 const gfx::Rect& rect) |
| 272 : buffer_queue(buffer_queue), | 291 : buffer_queue(buffer_queue), |
| 273 buffer(buffer.release()), | 292 buffer(buffer.release()), |
| 274 texture(texture), | 293 texture(texture), |
| 275 image(image), | 294 image(image), |
| 276 stencil(stencil), | 295 stencil(stencil), |
| 277 damage(rect) {} | 296 damage(rect) {} |
| 278 | 297 |
| 279 BufferQueue::AllocatedSurface::~AllocatedSurface() { | 298 BufferQueue::AllocatedSurface::~AllocatedSurface() { |
| 280 buffer_queue->FreeSurfaceResources(this); | 299 buffer_queue->FreeSurfaceResources(this); |
| 281 } | 300 } |
| 282 | 301 |
| 283 } // namespace display_compositor | 302 } // namespace display_compositor |
| OLD | NEW |