| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_MUS_SURFACES_BUFFER_QUEUE_H_ | |
| 6 #define COMPONENTS_MUS_SURFACES_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 "gpu/command_buffer/client/gles2_interface.h" | |
| 17 #include "ui/gfx/geometry/rect.h" | |
| 18 #include "ui/gfx/geometry/size.h" | |
| 19 #include "ui/gfx/native_widget_types.h" | |
| 20 | |
| 21 namespace cc { | |
| 22 class ContextProvider; | |
| 23 } | |
| 24 | |
| 25 namespace gfx { | |
| 26 class GpuMemoryBuffer; | |
| 27 } | |
| 28 | |
| 29 class SkRegion; | |
| 30 | |
| 31 namespace mus { | |
| 32 | |
| 33 class MojoGpuMemoryBufferManager; | |
| 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 BufferQueue { | |
| 41 public: | |
| 42 BufferQueue(scoped_refptr<cc::ContextProvider> context_provider, | |
| 43 uint32_t texture_target, | |
| 44 uint32_t internalformat, | |
| 45 gfx::AcceleratedWidget widget); | |
| 46 virtual ~BufferQueue(); | |
| 47 | |
| 48 void Initialize(); | |
| 49 | |
| 50 void BindFramebuffer(); | |
| 51 void SwapBuffers(const gfx::Rect& damage); | |
| 52 void PageFlipComplete(); | |
| 53 void Reshape(const gfx::Size& size, float scale_factor); | |
| 54 | |
| 55 void RecreateBuffers(); | |
| 56 | |
| 57 unsigned int current_texture_id() const { | |
| 58 return current_surface_ ? current_surface_->texture : 0; | |
| 59 } | |
| 60 unsigned int fbo() const { return fbo_; } | |
| 61 | |
| 62 private: | |
| 63 friend class AllocatedSurface; | |
| 64 | |
| 65 struct AllocatedSurface { | |
| 66 AllocatedSurface(BufferQueue* buffer_queue, | |
| 67 std::unique_ptr<gfx::GpuMemoryBuffer> buffer, | |
| 68 unsigned int texture, | |
| 69 unsigned int image, | |
| 70 const gfx::Rect& rect); | |
| 71 ~AllocatedSurface(); | |
| 72 BufferQueue* const buffer_queue; | |
| 73 std::unique_ptr<gfx::GpuMemoryBuffer> buffer; | |
| 74 const unsigned int texture; | |
| 75 const unsigned int image; | |
| 76 gfx::Rect damage; // This is the damage for this frame from the previous. | |
| 77 }; | |
| 78 | |
| 79 void FreeAllSurfaces(); | |
| 80 | |
| 81 void FreeSurfaceResources(AllocatedSurface* surface); | |
| 82 | |
| 83 // Copy everything that is in |copy_rect|, except for what is in | |
| 84 // |exclude_rect| from |source_texture| to |texture|. | |
| 85 virtual void CopyBufferDamage(int texture, | |
| 86 int source_texture, | |
| 87 const gfx::Rect& new_damage, | |
| 88 const gfx::Rect& old_damage); | |
| 89 | |
| 90 void UpdateBufferDamage(const gfx::Rect& damage); | |
| 91 | |
| 92 void CopySubBufferDamage(GLenum target, | |
| 93 GLuint texture, | |
| 94 GLuint previous_texture, | |
| 95 const SkRegion& new_damage, | |
| 96 const SkRegion& old_damage); | |
| 97 | |
| 98 // Return a surface, available to be drawn into. | |
| 99 std::unique_ptr<AllocatedSurface> GetNextSurface(); | |
| 100 | |
| 101 std::unique_ptr<AllocatedSurface> RecreateBuffer( | |
| 102 std::unique_ptr<AllocatedSurface> surface); | |
| 103 | |
| 104 gfx::Size size_; | |
| 105 scoped_refptr<cc::ContextProvider> context_provider_; | |
| 106 | |
| 107 unsigned int fbo_; | |
| 108 size_t allocated_count_; | |
| 109 unsigned int texture_target_; | |
| 110 unsigned int internal_format_; | |
| 111 // This surface is currently bound. This may be nullptr if no surface has | |
| 112 // been bound, or if allocation failed at bind. | |
| 113 std::unique_ptr<AllocatedSurface> current_surface_; | |
| 114 // The surface currently on the screen, if any. | |
| 115 std::unique_ptr<AllocatedSurface> displayed_surface_; | |
| 116 // These are free for use, and are not nullptr. | |
| 117 std::vector<std::unique_ptr<AllocatedSurface>> available_surfaces_; | |
| 118 // These have been swapped but are not displayed yet. Entries of this deque | |
| 119 // may be nullptr, if they represent frames that have been destroyed. | |
| 120 std::deque<std::unique_ptr<AllocatedSurface>> in_flight_surfaces_; | |
| 121 gfx::AcceleratedWidget widget_; | |
| 122 | |
| 123 DISALLOW_COPY_AND_ASSIGN(BufferQueue); | |
| 124 }; | |
| 125 | |
| 126 } // namespace mus | |
| 127 | |
| 128 #endif // COMPONENTS_MUS_SURFACES_BUFFER_QUEUE_H_ | |
| OLD | NEW |