| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_COMMON_GPU_CLIENT_GPU_MEMORY_BUFFER_IMPL_H_ | 5 #ifndef CONTENT_COMMON_GPU_CLIENT_GPU_MEMORY_BUFFER_IMPL_H_ |
| 6 #define CONTENT_COMMON_GPU_CLIENT_GPU_MEMORY_BUFFER_IMPL_H_ | 6 #define CONTENT_COMMON_GPU_CLIENT_GPU_MEMORY_BUFFER_IMPL_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "content/common/content_export.h" | 10 #include "content/common/content_export.h" |
| 11 #include "ui/gfx/geometry/size.h" | 11 #include "ui/gfx/geometry/size.h" |
| 12 #include "ui/gfx/gpu_memory_buffer.h" | 12 #include "ui/gfx/gpu_memory_buffer.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 | 15 |
| 16 // Provides common implementation of a GPU memory buffer. | 16 // Provides common implementation of a GPU memory buffer. |
| 17 class CONTENT_EXPORT GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { | 17 class CONTENT_EXPORT GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { |
| 18 public: | 18 public: |
| 19 typedef base::Callback<void(uint32 sync_point)> DestructionCallback; | 19 typedef base::Callback<void(uint32 sync_point)> DestructionCallback; |
| 20 | 20 |
| 21 ~GpuMemoryBufferImpl() override; | 21 ~GpuMemoryBufferImpl() override; |
| 22 | 22 |
| 23 // Creates an instance from the given |handle|. |size| and |internalformat| | 23 // Creates an instance from the given |handle|. |size| and |internalformat| |
| 24 // should match what was used to allocate the |handle|. |callback| is | 24 // should match what was used to allocate the |handle|. |callback| is |
| 25 // called when instance is deleted, which is not necessarily on the same | 25 // called when instance is deleted, which is not necessarily on the same |
| 26 // thread as this function was called on and instance was created on. | 26 // thread as this function was called on and instance was created on. |
| 27 static scoped_ptr<GpuMemoryBufferImpl> CreateFromHandle( | 27 static scoped_ptr<GpuMemoryBufferImpl> CreateFromHandle( |
| 28 const gfx::GpuMemoryBufferHandle& handle, | 28 const gfx::GpuMemoryBufferHandle& handle, |
| 29 const gfx::Size& size, | 29 const gfx::Size& size, |
| 30 Format format, | 30 gfx::BufferFormat format, |
| 31 Usage usage, | 31 gfx::BufferUsage usage, |
| 32 const DestructionCallback& callback); | 32 const DestructionCallback& callback); |
| 33 | 33 |
| 34 // Type-checking upcast routine. Returns an NULL on failure. | 34 // Type-checking upcast routine. Returns an NULL on failure. |
| 35 static GpuMemoryBufferImpl* FromClientBuffer(ClientBuffer buffer); | 35 static GpuMemoryBufferImpl* FromClientBuffer(ClientBuffer buffer); |
| 36 | 36 |
| 37 // Returns the number of planes based on the format of the buffer. | 37 // Returns the number of planes based on the format of the buffer. |
| 38 static size_t NumberOfPlanesForGpuMemoryBufferFormat(Format format); | 38 static size_t NumberOfPlanesForGpuMemoryBufferFormat( |
| 39 gfx::BufferFormat format); |
| 39 | 40 |
| 40 // Returns the subsampling factor applied to the given zero-indexed |plane| of | 41 // Returns the subsampling factor applied to the given zero-indexed |plane| of |
| 41 // the |format| both horizontally and vertically. | 42 // the |format| both horizontally and vertically. |
| 42 static size_t SubsamplingFactor(Format format, int plane); | 43 static size_t SubsamplingFactor(gfx::BufferFormat format, int plane); |
| 43 | 44 |
| 44 // Returns the number of bytes used to store a row of the given zero-indexed | 45 // Returns the number of bytes used to store a row of the given zero-indexed |
| 45 // |plane| of |format|. | 46 // |plane| of |format|. |
| 46 // Note: This is an approximation and the exact size used by an implementation | 47 // Note: This is an approximation and the exact size used by an implementation |
| 47 // might be different. | 48 // might be different. |
| 48 static bool RowSizeInBytes(size_t width, | 49 static bool RowSizeInBytes(size_t width, |
| 49 Format format, | 50 gfx::BufferFormat format, |
| 50 int plane, | 51 int plane, |
| 51 size_t* size_in_bytes); | 52 size_t* size_in_bytes); |
| 52 | 53 |
| 53 // Returns the number of bytes used to store all the planes of a given | 54 // Returns the number of bytes used to store all the planes of a given |
| 54 // |format|. | 55 // |format|. |
| 55 // Note: This is an approximation and the exact size used by an implementation | 56 // Note: This is an approximation and the exact size used by an implementation |
| 56 // might be different. | 57 // might be different. |
| 57 static bool BufferSizeInBytes(const gfx::Size& size, | 58 static bool BufferSizeInBytes(const gfx::Size& size, |
| 58 Format format, | 59 gfx::BufferFormat format, |
| 59 size_t* size_in_bytes); | 60 size_t* size_in_bytes); |
| 60 | 61 |
| 61 // Overridden from gfx::GpuMemoryBuffer: | 62 // Overridden from gfx::GpuMemoryBuffer: |
| 62 bool IsMapped() const override; | 63 bool IsMapped() const override; |
| 63 Format GetFormat() const override; | 64 gfx::BufferFormat GetFormat() const override; |
| 64 gfx::GpuMemoryBufferId GetId() const override; | 65 gfx::GpuMemoryBufferId GetId() const override; |
| 65 ClientBuffer AsClientBuffer() override; | 66 ClientBuffer AsClientBuffer() override; |
| 66 | 67 |
| 67 void set_destruction_sync_point(uint32 sync_point) { | 68 void set_destruction_sync_point(uint32 sync_point) { |
| 68 destruction_sync_point_ = sync_point; | 69 destruction_sync_point_ = sync_point; |
| 69 } | 70 } |
| 70 | 71 |
| 71 protected: | 72 protected: |
| 72 GpuMemoryBufferImpl(gfx::GpuMemoryBufferId id, | 73 GpuMemoryBufferImpl(gfx::GpuMemoryBufferId id, |
| 73 const gfx::Size& size, | 74 const gfx::Size& size, |
| 74 Format format, | 75 gfx::BufferFormat format, |
| 75 const DestructionCallback& callback); | 76 const DestructionCallback& callback); |
| 76 | 77 |
| 77 const gfx::GpuMemoryBufferId id_; | 78 const gfx::GpuMemoryBufferId id_; |
| 78 const gfx::Size size_; | 79 const gfx::Size size_; |
| 79 const Format format_; | 80 const gfx::BufferFormat format_; |
| 80 const DestructionCallback callback_; | 81 const DestructionCallback callback_; |
| 81 bool mapped_; | 82 bool mapped_; |
| 82 uint32 destruction_sync_point_; | 83 uint32 destruction_sync_point_; |
| 83 | 84 |
| 84 private: | 85 private: |
| 85 DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferImpl); | 86 DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferImpl); |
| 86 }; | 87 }; |
| 87 | 88 |
| 88 } // namespace content | 89 } // namespace content |
| 89 | 90 |
| 90 #endif // CONTENT_COMMON_GPU_CLIENT_GPU_MEMORY_BUFFER_IMPL_H_ | 91 #endif // CONTENT_COMMON_GPU_CLIENT_GPU_MEMORY_BUFFER_IMPL_H_ |
| OLD | NEW |