Chromium Code Reviews| Index: content/browser/compositor/buffer_queue.cc |
| diff --git a/content/browser/compositor/buffer_queue.cc b/content/browser/compositor/buffer_queue.cc |
| index 8809972ed359cdc55d314acbcd77ddca60654b85..561a11b0fb7badd40d6a7331cd344ef7fd29ebf0 100644 |
| --- a/content/browser/compositor/buffer_queue.cc |
| +++ b/content/browser/compositor/buffer_queue.cc |
| @@ -4,9 +4,13 @@ |
| #include "content/browser/compositor/buffer_queue.h" |
| +#include "content/browser/compositor/image_transport_factory.h" |
| #include "content/common/gpu/client/context_provider_command_buffer.h" |
| +#include "content/common/gpu/client/gl_helper.h" |
| #include "gpu/GLES2/gl2extchromium.h" |
| #include "gpu/command_buffer/client/gles2_interface.h" |
| +#include "third_party/skia/include/core/SkRect.h" |
| +#include "third_party/skia/include/core/SkRegion.h" |
| namespace content { |
| @@ -46,8 +50,51 @@ void BufferQueue::BindFramebuffer() { |
| } |
| } |
| -void BufferQueue::SwapBuffers() { |
| - in_flight_surfaces_.push(current_surface_); |
| +void BufferQueue::CopyBufferDamage(int texture, |
| + int source_texture, |
| + const gfx::Rect& new_damage, |
| + const gfx::Rect& old_damage) { |
| + ImageTransportFactory::GetInstance()->GetGLHelper()->CopySubBufferDamage( |
| + texture, |
| + source_texture, |
| + SkRegion(SkIRect::MakeXYWH(new_damage.x(), |
| + new_damage.y(), |
| + new_damage.width(), |
| + new_damage.height())), |
| + SkRegion(SkIRect::MakeXYWH(old_damage.x(), |
| + old_damage.y(), |
| + old_damage.width(), |
| + old_damage.height()))); |
| +} |
| + |
| +void BufferQueue::UpdateBufferDamage(const gfx::Rect& damage) { |
| + for (size_t i = 0; i < available_surfaces_.size(); i++) |
| + available_surfaces_[i].damage.Union(damage); |
| + for (std::deque<AllocatedSurface>::iterator it = |
| + in_flight_surfaces_.begin(); |
| + it != in_flight_surfaces_.end(); |
| + ++it) |
| + it->damage.Union(damage); |
| +} |
| + |
| +void BufferQueue::SwapBuffers(const gfx::Rect& damage) { |
| + if (damage != gfx::Rect(size_)) { |
| + // We must have a frame available to copy from. |
| + DCHECK(!in_flight_surfaces_.empty()); |
| + |
| + if (!damage.Contains(current_surface_.damage)) { |
| + CopyBufferDamage(current_surface_.texture, |
| + in_flight_surfaces_.back().texture, |
| + damage, |
| + current_surface_.damage); |
| + // Because we copied everything except |damage| to this texture, |
|
alexst (slow to review)
2014/09/18 16:57:16
I think it should be "from this texture"
achaulk
2014/09/18 17:27:51
Sure. That's more consistent
|
| + // the cumulative damage for this frame is only |damage| now. |
| + in_flight_surfaces_.back().damage = damage; |
| + } |
| + } |
| + UpdateBufferDamage(damage); |
| + current_surface_.damage = gfx::Rect(); |
| + in_flight_surfaces_.push_back(current_surface_); |
| current_surface_.texture = 0; |
| current_surface_.image = 0; |
| } |
| @@ -70,7 +117,7 @@ void BufferQueue::Reshape(const gfx::Size& size, float scale_factor) { |
| void BufferQueue::PageFlipComplete() { |
| if (in_flight_surfaces_.size() > 1) { |
| available_surfaces_.push_back(in_flight_surfaces_.front()); |
| - in_flight_surfaces_.pop(); |
| + in_flight_surfaces_.pop_front(); |
| } |
| } |
| @@ -78,7 +125,7 @@ void BufferQueue::FreeAllSurfaces() { |
| FreeSurface(¤t_surface_); |
| while (!in_flight_surfaces_.empty()) { |
| FreeSurface(&in_flight_surfaces_.front()); |
| - in_flight_surfaces_.pop(); |
| + in_flight_surfaces_.pop_front(); |
| } |
| for (size_t i = 0; i < available_surfaces_.size(); i++) |
| FreeSurface(&available_surfaces_[i]); |
| @@ -100,9 +147,9 @@ void BufferQueue::FreeSurface(AllocatedSurface* surface) { |
| BufferQueue::AllocatedSurface BufferQueue::GetNextSurface() { |
| if (!available_surfaces_.empty()) { |
| - AllocatedSurface id = available_surfaces_.back(); |
| + AllocatedSurface surface = available_surfaces_.back(); |
| available_surfaces_.pop_back(); |
| - return id; |
| + return surface; |
| } |
| unsigned int texture = 0; |
| @@ -122,7 +169,7 @@ BufferQueue::AllocatedSurface BufferQueue::GetNextSurface() { |
| allocated_count_++; |
| gl->BindTexture(GL_TEXTURE_2D, texture); |
| gl->BindTexImage2DCHROMIUM(GL_TEXTURE_2D, id); |
| - return AllocatedSurface(texture, id); |
| + return AllocatedSurface(texture, id, gfx::Rect(size_)); |
| } |
| } // namespace content |