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