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
;
23 // Provides a surface that manages its own buffers, backed by GpuMemoryBuffers
24 // created using CHROMIUM_gpu_memory_buffer_image. Double/triple buffering is
25 // implemented internally. Doublebuffering occurs if PageFlipComplete is called
26 // before the next BindFramebuffer call, otherwise it creates extra buffers.
27 class CONTENT_EXPORT BufferQueue
{
29 BufferQueue(scoped_refptr
<cc::ContextProvider
> context_provider
,
30 unsigned int internalformat
);
31 virtual ~BufferQueue();
35 void BindFramebuffer();
36 void SwapBuffers(const gfx::Rect
& damage
);
37 void PageFlipComplete();
38 void Reshape(const gfx::Size
& size
, float scale_factor
);
40 unsigned int current_texture_id() { return current_surface_
.texture
; }
43 friend class BufferQueueTest
;
45 struct AllocatedSurface
{
46 AllocatedSurface() : texture(0), image(0) {}
47 AllocatedSurface(unsigned int texture
,
49 const gfx::Rect
& rect
)
50 : texture(texture
), image(image
), damage(rect
) {}
53 gfx::Rect damage
; // This is the damage for this frame from the previous.
56 void FreeAllSurfaces();
58 void FreeSurface(AllocatedSurface
* surface
);
60 // Copy everything that is in |copy_rect|, except for what is in
61 // |exclude_rect| from |source_texture| to |texture|.
62 virtual void CopyBufferDamage(int texture
,
64 const gfx::Rect
& new_damage
,
65 const gfx::Rect
& old_damage
);
67 void UpdateBufferDamage(const gfx::Rect
& damage
);
69 // Return a surface, available to be drawn into.
70 AllocatedSurface
GetNextSurface();
73 scoped_refptr
<cc::ContextProvider
> context_provider_
;
75 size_t allocated_count_
;
76 unsigned int internalformat_
;
77 AllocatedSurface current_surface_
; // This surface is currently bound.
78 std::vector
<AllocatedSurface
> available_surfaces_
; // These are free for use.
79 std::deque
<AllocatedSurface
> in_flight_surfaces_
;
81 DISALLOW_COPY_AND_ASSIGN(BufferQueue
);
84 } // namespace content
86 #endif // CONTENT_BROWSER_COMPOSITOR_BUFFERED_OUTPUT_SURFACE_H_