Blink roll 25b6bd3a7a131ffe68d809546ad1a20707915cdc:3a503f41ae42e5b79cfcd2ff10e65afde...
[chromium-blink-merge.git] / content / browser / compositor / buffer_queue.h
blobdca9c38c0d48ffb90f0846ea732da6aece889ee8
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 GLHelper;
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 {
30 public:
31 BufferQueue(scoped_refptr<cc::ContextProvider> context_provider,
32 unsigned int internalformat,
33 GLHelper* gl_helper);
34 virtual ~BufferQueue();
36 bool Initialize();
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; }
45 private:
46 friend class BufferQueueTest;
48 struct AllocatedSurface {
49 AllocatedSurface() : texture(0), image(0) {}
50 AllocatedSurface(unsigned int texture,
51 unsigned int image,
52 const gfx::Rect& rect)
53 : texture(texture), image(image), damage(rect) {}
54 unsigned int texture;
55 unsigned int image;
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,
66 int source_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();
75 gfx::Size size_;
76 scoped_refptr<cc::ContextProvider> context_provider_;
77 unsigned int fbo_;
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_;
83 GLHelper* gl_helper_;
85 DISALLOW_COPY_AND_ASSIGN(BufferQueue);
88 } // namespace content
90 #endif // CONTENT_BROWSER_COMPOSITOR_BUFFERED_OUTPUT_SURFACE_H_