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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_COMPOSITOR_BUFFERED_OUTPUT_SURFACE_H_
6 #define CONTENT_BROWSER_COMPOSITOR_BUFFERED_OUTPUT_SURFACE_H_
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "content/common/content_export.h"
14 #include "ui/gfx/rect.h"
15 #include "ui/gfx/size.h"
18 class ContextProvider
;
25 // Provides a surface that manages its own buffers, backed by GpuMemoryBuffers
26 // created using CHROMIUM_gpu_memory_buffer_image. Double/triple buffering is
27 // implemented internally. Doublebuffering occurs if PageFlipComplete is called
28 // before the next BindFramebuffer call, otherwise it creates extra buffers.
29 class CONTENT_EXPORT BufferQueue
{
31 BufferQueue(scoped_refptr
<cc::ContextProvider
> context_provider
,
32 unsigned int internalformat
,
34 virtual ~BufferQueue();
38 void BindFramebuffer();
39 void SwapBuffers(const gfx::Rect
& damage
);
40 void PageFlipComplete();
41 void Reshape(const gfx::Size
& size
, float scale_factor
);
43 unsigned int current_texture_id() { return current_surface_
.texture
; }
46 friend class BufferQueueTest
;
48 struct AllocatedSurface
{
49 AllocatedSurface() : texture(0), image(0) {}
50 AllocatedSurface(unsigned int texture
,
52 const gfx::Rect
& rect
)
53 : texture(texture
), image(image
), damage(rect
) {}
56 gfx::Rect damage
; // This is the damage for this frame from the previous.
59 void FreeAllSurfaces();
61 void FreeSurface(AllocatedSurface
* surface
);
63 // Copy everything that is in |copy_rect|, except for what is in
64 // |exclude_rect| from |source_texture| to |texture|.
65 virtual void CopyBufferDamage(int texture
,
67 const gfx::Rect
& new_damage
,
68 const gfx::Rect
& old_damage
);
70 void UpdateBufferDamage(const gfx::Rect
& damage
);
72 // Return a surface, available to be drawn into.
73 AllocatedSurface
GetNextSurface();
76 scoped_refptr
<cc::ContextProvider
> context_provider_
;
78 size_t allocated_count_
;
79 unsigned int internalformat_
;
80 AllocatedSurface current_surface_
; // This surface is currently bound.
81 std::vector
<AllocatedSurface
> available_surfaces_
; // These are free for use.
82 std::deque
<AllocatedSurface
> in_flight_surfaces_
;
85 DISALLOW_COPY_AND_ASSIGN(BufferQueue
);
88 } // namespace content
90 #endif // CONTENT_BROWSER_COMPOSITOR_BUFFERED_OUTPUT_SURFACE_H_