Chromecast: extracts Linux window creation code to a common place.
[chromium-blink-merge.git] / content / browser / compositor / buffer_queue.h
blob4e300f0755976770f35ab947eb155000aef89e5e
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_
8 #include <queue>
9 #include <vector>
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"
17 namespace cc {
18 class ContextProvider;
21 namespace content {
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 {
28 public:
29 BufferQueue(scoped_refptr<cc::ContextProvider> context_provider,
30 unsigned int internalformat);
31 virtual ~BufferQueue();
33 bool Initialize();
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; }
42 private:
43 friend class BufferQueueTest;
45 struct AllocatedSurface {
46 AllocatedSurface() : texture(0), image(0) {}
47 AllocatedSurface(unsigned int texture,
48 unsigned int image,
49 const gfx::Rect& rect)
50 : texture(texture), image(image), damage(rect) {}
51 unsigned int texture;
52 unsigned int image;
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,
63 int source_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();
72 gfx::Size size_;
73 scoped_refptr<cc::ContextProvider> context_provider_;
74 unsigned int fbo_;
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_