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