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