OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef COMPONENTS_DISPLAY_COMPOSITOR_BUFFER_QUEUE_H_ | |
6 #define COMPONENTS_DISPLAY_COMPOSITOR_BUFFER_QUEUE_H_ | |
7 | |
8 #include <stddef.h> | |
9 | |
10 #include <deque> | |
11 #include <memory> | |
12 #include <vector> | |
13 | |
14 #include "base/macros.h" | |
15 #include "base/memory/ref_counted.h" | |
16 #include "components/display_compositor/display_compositor_export.h" | |
17 #include "gpu/ipc/common/surface_handle.h" | |
18 #include "ui/gfx/buffer_types.h" | |
19 #include "ui/gfx/color_space.h" | |
20 #include "ui/gfx/geometry/rect.h" | |
21 #include "ui/gfx/geometry/size.h" | |
22 | |
23 namespace gfx { | |
24 class GpuMemoryBuffer; | |
25 } | |
26 | |
27 namespace gpu { | |
28 class GpuMemoryBufferManager; | |
29 | |
30 namespace gles2 { | |
31 class GLES2Interface; | |
32 } | |
33 } | |
34 | |
35 namespace display_compositor { | |
36 | |
37 class GLHelper; | |
38 | |
39 // Provides a surface that manages its own buffers, backed by GpuMemoryBuffers | |
40 // created using CHROMIUM_image. Double/triple buffering is implemented | |
41 // internally. Doublebuffering occurs if PageFlipComplete is called before the | |
42 // next BindFramebuffer call, otherwise it creates extra buffers. | |
43 class DISPLAY_COMPOSITOR_EXPORT BufferQueue { | |
44 public: | |
45 BufferQueue(gpu::gles2::GLES2Interface* gl, | |
46 uint32_t texture_target, | |
47 uint32_t internal_format, | |
48 gfx::BufferFormat format, | |
49 GLHelper* gl_helper, | |
50 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | |
51 gpu::SurfaceHandle surface_handle); | |
52 virtual ~BufferQueue(); | |
53 | |
54 void Initialize(); | |
55 | |
56 void BindFramebuffer(); | |
57 void SwapBuffers(const gfx::Rect& damage); | |
58 void PageFlipComplete(); | |
59 void Reshape(const gfx::Size& size, | |
60 float scale_factor, | |
61 const gfx::ColorSpace& color_space, | |
62 bool use_stencil); | |
63 void RecreateBuffers(); | |
64 uint32_t GetCurrentTextureId() const; | |
65 | |
66 uint32_t fbo() const { return fbo_; } | |
67 uint32_t internal_format() const { return internal_format_; } | |
68 | |
69 private: | |
70 friend class BufferQueueTest; | |
71 friend class AllocatedSurface; | |
72 | |
73 struct DISPLAY_COMPOSITOR_EXPORT AllocatedSurface { | |
74 AllocatedSurface(BufferQueue* buffer_queue, | |
75 std::unique_ptr<gfx::GpuMemoryBuffer> buffer, | |
76 uint32_t texture, | |
77 uint32_t image, | |
78 uint32_t stencil, | |
79 const gfx::Rect& rect); | |
80 ~AllocatedSurface(); | |
81 BufferQueue* const buffer_queue; | |
82 std::unique_ptr<gfx::GpuMemoryBuffer> buffer; | |
83 const uint32_t texture; | |
84 const uint32_t image; | |
85 const uint32_t stencil; | |
86 gfx::Rect damage; // This is the damage for this frame from the previous. | |
87 }; | |
88 | |
89 void FreeAllSurfaces(); | |
90 | |
91 void FreeSurfaceResources(AllocatedSurface* surface); | |
92 | |
93 // Copy everything that is in |copy_rect|, except for what is in | |
94 // |exclude_rect| from |source_texture| to |texture|. | |
95 virtual void CopyBufferDamage(int texture, | |
96 int source_texture, | |
97 const gfx::Rect& new_damage, | |
98 const gfx::Rect& old_damage); | |
99 | |
100 void UpdateBufferDamage(const gfx::Rect& damage); | |
101 | |
102 // Return a surface, available to be drawn into. | |
103 std::unique_ptr<AllocatedSurface> GetNextSurface(); | |
104 | |
105 std::unique_ptr<AllocatedSurface> RecreateBuffer( | |
106 std::unique_ptr<AllocatedSurface> surface); | |
107 | |
108 gpu::gles2::GLES2Interface* const gl_; | |
109 gfx::Size size_; | |
110 gfx::ColorSpace color_space_; | |
111 bool use_stencil_ = false; | |
112 uint32_t fbo_; | |
113 size_t allocated_count_; | |
114 uint32_t texture_target_; | |
115 uint32_t internal_format_; | |
116 gfx::BufferFormat format_; | |
117 // This surface is currently bound. This may be nullptr if no surface has | |
118 // been bound, or if allocation failed at bind. | |
119 std::unique_ptr<AllocatedSurface> current_surface_; | |
120 // The surface currently on the screen, if any. | |
121 std::unique_ptr<AllocatedSurface> displayed_surface_; | |
122 // These are free for use, and are not nullptr. | |
123 std::vector<std::unique_ptr<AllocatedSurface>> available_surfaces_; | |
124 // These have been swapped but are not displayed yet. Entries of this deque | |
125 // may be nullptr, if they represent frames that have been destroyed. | |
126 std::deque<std::unique_ptr<AllocatedSurface>> in_flight_surfaces_; | |
127 GLHelper* gl_helper_; | |
128 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager_; | |
129 gpu::SurfaceHandle surface_handle_; | |
130 | |
131 DISALLOW_COPY_AND_ASSIGN(BufferQueue); | |
132 }; | |
133 | |
134 } // namespace display_compositor | |
135 | |
136 #endif // COMPONENTS_DISPLAY_COMPOSITOR_BUFFER_QUEUE_H_ | |
OLD | NEW |