| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_DISPLAY_COMPOSITOR_BUFFER_QUEUE_H_ | 5 #ifndef COMPONENTS_DISPLAY_COMPOSITOR_BUFFER_QUEUE_H_ |
| 6 #define COMPONENTS_DISPLAY_COMPOSITOR_BUFFER_QUEUE_H_ | 6 #define COMPONENTS_DISPLAY_COMPOSITOR_BUFFER_QUEUE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <deque> | 10 #include <deque> |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 class GLHelper; | 35 class GLHelper; |
| 36 | 36 |
| 37 // Provides a surface that manages its own buffers, backed by GpuMemoryBuffers | 37 // Provides a surface that manages its own buffers, backed by GpuMemoryBuffers |
| 38 // created using CHROMIUM_gpu_memory_buffer_image. Double/triple buffering is | 38 // created using CHROMIUM_gpu_memory_buffer_image. Double/triple buffering is |
| 39 // implemented internally. Doublebuffering occurs if PageFlipComplete is called | 39 // implemented internally. Doublebuffering occurs if PageFlipComplete is called |
| 40 // before the next BindFramebuffer call, otherwise it creates extra buffers. | 40 // before the next BindFramebuffer call, otherwise it creates extra buffers. |
| 41 class DISPLAY_COMPOSITOR_EXPORT BufferQueue { | 41 class DISPLAY_COMPOSITOR_EXPORT BufferQueue { |
| 42 public: | 42 public: |
| 43 BufferQueue(gpu::gles2::GLES2Interface* gl, | 43 BufferQueue(gpu::gles2::GLES2Interface* gl, |
| 44 unsigned int texture_target, | 44 uint32_t texture_target, |
| 45 unsigned int internalformat, | 45 uint32_t internal_format, |
| 46 GLHelper* gl_helper, | 46 GLHelper* gl_helper, |
| 47 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 47 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 48 gpu::SurfaceHandle surface_handle); | 48 gpu::SurfaceHandle surface_handle); |
| 49 virtual ~BufferQueue(); | 49 virtual ~BufferQueue(); |
| 50 | 50 |
| 51 void Initialize(); | 51 void Initialize(); |
| 52 | 52 |
| 53 void BindFramebuffer(); | 53 void BindFramebuffer(); |
| 54 void SwapBuffers(const gfx::Rect& damage); | 54 void SwapBuffers(const gfx::Rect& damage); |
| 55 void PageFlipComplete(); | 55 void PageFlipComplete(); |
| 56 void Reshape(const gfx::Size& size, float scale_factor); | 56 void Reshape(const gfx::Size& size, float scale_factor); |
| 57 | 57 |
| 58 void RecreateBuffers(); | 58 void RecreateBuffers(); |
| 59 | 59 |
| 60 unsigned int current_texture_id() const { | 60 uint32_t current_texture_id() const { |
| 61 return current_surface_ ? current_surface_->texture : 0; | 61 return current_surface_ ? current_surface_->texture : 0; |
| 62 } | 62 } |
| 63 unsigned int fbo() const { return fbo_; } | 63 uint32_t fbo() const { return fbo_; } |
| 64 uint32_t internal_format() const { return internal_format_; } |
| 64 | 65 |
| 65 private: | 66 private: |
| 66 friend class BufferQueueTest; | 67 friend class BufferQueueTest; |
| 67 friend class AllocatedSurface; | 68 friend class AllocatedSurface; |
| 68 | 69 |
| 69 struct DISPLAY_COMPOSITOR_EXPORT AllocatedSurface { | 70 struct DISPLAY_COMPOSITOR_EXPORT AllocatedSurface { |
| 70 AllocatedSurface(BufferQueue* buffer_queue, | 71 AllocatedSurface(BufferQueue* buffer_queue, |
| 71 std::unique_ptr<gfx::GpuMemoryBuffer> buffer, | 72 std::unique_ptr<gfx::GpuMemoryBuffer> buffer, |
| 72 unsigned int texture, | 73 uint32_t texture, |
| 73 unsigned int image, | 74 uint32_t image, |
| 74 const gfx::Rect& rect); | 75 const gfx::Rect& rect); |
| 75 ~AllocatedSurface(); | 76 ~AllocatedSurface(); |
| 76 BufferQueue* const buffer_queue; | 77 BufferQueue* const buffer_queue; |
| 77 std::unique_ptr<gfx::GpuMemoryBuffer> buffer; | 78 std::unique_ptr<gfx::GpuMemoryBuffer> buffer; |
| 78 const unsigned int texture; | 79 const uint32_t texture; |
| 79 const unsigned int image; | 80 const uint32_t image; |
| 80 gfx::Rect damage; // This is the damage for this frame from the previous. | 81 gfx::Rect damage; // This is the damage for this frame from the previous. |
| 81 }; | 82 }; |
| 82 | 83 |
| 83 void FreeAllSurfaces(); | 84 void FreeAllSurfaces(); |
| 84 | 85 |
| 85 void FreeSurfaceResources(AllocatedSurface* surface); | 86 void FreeSurfaceResources(AllocatedSurface* surface); |
| 86 | 87 |
| 87 // Copy everything that is in |copy_rect|, except for what is in | 88 // Copy everything that is in |copy_rect|, except for what is in |
| 88 // |exclude_rect| from |source_texture| to |texture|. | 89 // |exclude_rect| from |source_texture| to |texture|. |
| 89 virtual void CopyBufferDamage(int texture, | 90 virtual void CopyBufferDamage(int texture, |
| 90 int source_texture, | 91 int source_texture, |
| 91 const gfx::Rect& new_damage, | 92 const gfx::Rect& new_damage, |
| 92 const gfx::Rect& old_damage); | 93 const gfx::Rect& old_damage); |
| 93 | 94 |
| 94 void UpdateBufferDamage(const gfx::Rect& damage); | 95 void UpdateBufferDamage(const gfx::Rect& damage); |
| 95 | 96 |
| 96 // Return a surface, available to be drawn into. | 97 // Return a surface, available to be drawn into. |
| 97 std::unique_ptr<AllocatedSurface> GetNextSurface(); | 98 std::unique_ptr<AllocatedSurface> GetNextSurface(); |
| 98 | 99 |
| 99 std::unique_ptr<AllocatedSurface> RecreateBuffer( | 100 std::unique_ptr<AllocatedSurface> RecreateBuffer( |
| 100 std::unique_ptr<AllocatedSurface> surface); | 101 std::unique_ptr<AllocatedSurface> surface); |
| 101 | 102 |
| 102 gpu::gles2::GLES2Interface* const gl_; | 103 gpu::gles2::GLES2Interface* const gl_; |
| 103 gfx::Size size_; | 104 gfx::Size size_; |
| 104 unsigned int fbo_; | 105 uint32_t fbo_; |
| 105 size_t allocated_count_; | 106 size_t allocated_count_; |
| 106 unsigned int texture_target_; | 107 uint32_t texture_target_; |
| 107 unsigned int internal_format_; | 108 uint32_t internal_format_; |
| 108 // This surface is currently bound. This may be nullptr if no surface has | 109 // This surface is currently bound. This may be nullptr if no surface has |
| 109 // been bound, or if allocation failed at bind. | 110 // been bound, or if allocation failed at bind. |
| 110 std::unique_ptr<AllocatedSurface> current_surface_; | 111 std::unique_ptr<AllocatedSurface> current_surface_; |
| 111 // The surface currently on the screen, if any. | 112 // The surface currently on the screen, if any. |
| 112 std::unique_ptr<AllocatedSurface> displayed_surface_; | 113 std::unique_ptr<AllocatedSurface> displayed_surface_; |
| 113 // These are free for use, and are not nullptr. | 114 // These are free for use, and are not nullptr. |
| 114 std::vector<std::unique_ptr<AllocatedSurface>> available_surfaces_; | 115 std::vector<std::unique_ptr<AllocatedSurface>> available_surfaces_; |
| 115 // These have been swapped but are not displayed yet. Entries of this deque | 116 // These have been swapped but are not displayed yet. Entries of this deque |
| 116 // may be nullptr, if they represent frames that have been destroyed. | 117 // may be nullptr, if they represent frames that have been destroyed. |
| 117 std::deque<std::unique_ptr<AllocatedSurface>> in_flight_surfaces_; | 118 std::deque<std::unique_ptr<AllocatedSurface>> in_flight_surfaces_; |
| 118 GLHelper* gl_helper_; | 119 GLHelper* gl_helper_; |
| 119 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager_; | 120 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager_; |
| 120 gpu::SurfaceHandle surface_handle_; | 121 gpu::SurfaceHandle surface_handle_; |
| 121 | 122 |
| 122 DISALLOW_COPY_AND_ASSIGN(BufferQueue); | 123 DISALLOW_COPY_AND_ASSIGN(BufferQueue); |
| 123 }; | 124 }; |
| 124 | 125 |
| 125 } // namespace display_compositor | 126 } // namespace display_compositor |
| 126 | 127 |
| 127 #endif // COMPONENTS_DISPLAY_COMPOSITOR_BUFFER_QUEUE_H_ | 128 #endif // COMPONENTS_DISPLAY_COMPOSITOR_BUFFER_QUEUE_H_ |
| OLD | NEW |