Change next_proto member type.
[chromium-blink-merge.git] / content / browser / compositor / buffer_queue.h
blob3e6727eaf61e79ca6a71c9dd486fbc108a914b4f
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 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 internalformat,
34 GLHelper* gl_helper,
35 BrowserGpuMemoryBufferManager* gpu_memory_buffer_manager,
36 int surface_id);
37 virtual ~BufferQueue();
39 bool Initialize();
41 void BindFramebuffer();
42 void SwapBuffers(const gfx::Rect& damage);
43 void PageFlipComplete();
44 void Reshape(const gfx::Size& size, float scale_factor);
46 unsigned int current_texture_id() { return current_surface_.texture; }
48 private:
49 friend class BufferQueueTest;
51 struct AllocatedSurface {
52 AllocatedSurface() : texture(0), image(0) {}
53 AllocatedSurface(unsigned int texture,
54 unsigned int image,
55 const gfx::Rect& rect)
56 : texture(texture), image(image), damage(rect) {}
57 unsigned int texture;
58 unsigned int image;
59 gfx::Rect damage; // This is the damage for this frame from the previous.
62 void FreeAllSurfaces();
64 void FreeSurface(AllocatedSurface* surface);
66 // Copy everything that is in |copy_rect|, except for what is in
67 // |exclude_rect| from |source_texture| to |texture|.
68 virtual void CopyBufferDamage(int texture,
69 int source_texture,
70 const gfx::Rect& new_damage,
71 const gfx::Rect& old_damage);
73 void UpdateBufferDamage(const gfx::Rect& damage);
75 // Return a surface, available to be drawn into.
76 AllocatedSurface GetNextSurface();
78 gfx::Size size_;
79 scoped_refptr<cc::ContextProvider> context_provider_;
80 unsigned int fbo_;
81 size_t allocated_count_;
82 unsigned int internalformat_;
83 AllocatedSurface current_surface_; // This surface is currently bound.
84 std::vector<AllocatedSurface> available_surfaces_; // These are free for use.
85 std::deque<AllocatedSurface> in_flight_surfaces_;
86 GLHelper* gl_helper_;
87 BrowserGpuMemoryBufferManager* gpu_memory_buffer_manager_;
88 int surface_id_;
90 DISALLOW_COPY_AND_ASSIGN(BufferQueue);
93 } // namespace content
95 #endif // CONTENT_BROWSER_COMPOSITOR_BUFFERED_OUTPUT_SURFACE_H_