Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / browser / compositor / buffer_queue.h
blob170b7bd3232b169f9face6176a2f05848a5369bb
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_BUFFER_QUEUE_H_
6 #define CONTENT_BROWSER_COMPOSITOR_BUFFER_QUEUE_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/geometry/rect.h"
15 #include "ui/gfx/geometry/size.h"
17 namespace cc {
18 class ContextProvider;
21 namespace content {
23 class BrowserGpuMemoryBufferManager;
24 class GLHelper;
26 // Provides a surface that manages its own buffers, backed by GpuMemoryBuffers
27 // created using CHROMIUM_gpu_memory_buffer_image. Double/triple buffering is
28 // implemented internally. Doublebuffering occurs if PageFlipComplete is called
29 // before the next BindFramebuffer call, otherwise it creates extra buffers.
30 class CONTENT_EXPORT BufferQueue {
31 public:
32 BufferQueue(scoped_refptr<cc::ContextProvider> context_provider,
33 unsigned int texture_target,
34 unsigned int internalformat,
35 GLHelper* gl_helper,
36 BrowserGpuMemoryBufferManager* gpu_memory_buffer_manager,
37 int surface_id);
38 virtual ~BufferQueue();
40 void Initialize();
42 void BindFramebuffer();
43 void SwapBuffers(const gfx::Rect& damage);
44 void PageFlipComplete();
45 void Reshape(const gfx::Size& size, float scale_factor);
47 void RecreateBuffers();
49 unsigned int current_texture_id() const { return current_surface_.texture; }
50 unsigned int fbo() const { return fbo_; }
52 private:
53 friend class BufferQueueTest;
55 struct AllocatedSurface {
56 AllocatedSurface() : texture(0), image(0) {}
57 AllocatedSurface(unsigned int texture,
58 unsigned int image,
59 const gfx::Rect& rect)
60 : texture(texture), image(image), damage(rect) {}
61 unsigned int texture;
62 unsigned int image;
63 gfx::Rect damage; // This is the damage for this frame from the previous.
66 void FreeAllSurfaces();
68 void FreeSurface(AllocatedSurface* surface);
70 // Copy everything that is in |copy_rect|, except for what is in
71 // |exclude_rect| from |source_texture| to |texture|.
72 virtual void CopyBufferDamage(int texture,
73 int source_texture,
74 const gfx::Rect& new_damage,
75 const gfx::Rect& old_damage);
77 void UpdateBufferDamage(const gfx::Rect& damage);
79 // Return a surface, available to be drawn into.
80 AllocatedSurface GetNextSurface();
82 AllocatedSurface RecreateBuffer(AllocatedSurface* surface);
84 gfx::Size size_;
85 scoped_refptr<cc::ContextProvider> context_provider_;
86 unsigned int fbo_;
87 size_t allocated_count_;
88 unsigned int texture_target_;
89 unsigned int internal_format_;
90 AllocatedSurface current_surface_; // This surface is currently bound.
91 AllocatedSurface displayed_surface_; // The surface currently on the screen.
92 std::vector<AllocatedSurface> available_surfaces_; // These are free for use.
93 std::deque<AllocatedSurface> in_flight_surfaces_;
94 GLHelper* gl_helper_;
95 BrowserGpuMemoryBufferManager* gpu_memory_buffer_manager_;
96 int surface_id_;
98 DISALLOW_COPY_AND_ASSIGN(BufferQueue);
101 } // namespace content
103 #endif // CONTENT_BROWSER_COMPOSITOR_BUFFER_QUEUE_H_