We started redesigning GpuMemoryBuffer interface to handle multiple buffers [0].
[chromium-blink-merge.git] / content / common / gpu / client / gpu_memory_buffer_impl.h
blob31b28bcfd2d6681b2f90ac87d173560504335041
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_COMMON_GPU_CLIENT_GPU_MEMORY_BUFFER_IMPL_H_
6 #define CONTENT_COMMON_GPU_CLIENT_GPU_MEMORY_BUFFER_IMPL_H_
8 #include "base/callback.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "content/common/content_export.h"
11 #include "ui/gfx/geometry/size.h"
12 #include "ui/gfx/gpu_memory_buffer.h"
14 namespace content {
16 // Provides common implementation of a GPU memory buffer.
17 class CONTENT_EXPORT GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
18 public:
19 typedef base::Callback<void(uint32 sync_point)> DestructionCallback;
21 ~GpuMemoryBufferImpl() override;
23 // Creates an instance from the given |handle|. |size| and |internalformat|
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
26 // thread as this function was called on and instance was created on.
27 static scoped_ptr<GpuMemoryBufferImpl> CreateFromHandle(
28 const gfx::GpuMemoryBufferHandle& handle,
29 const gfx::Size& size,
30 Format format,
31 const DestructionCallback& callback);
33 // Type-checking upcast routine. Returns an NULL on failure.
34 static GpuMemoryBufferImpl* FromClientBuffer(ClientBuffer buffer);
36 // Returns the number of planes based on the format of the buffer.
37 static size_t NumberOfPlanesForGpuMemoryBufferFormat(Format format);
39 // Calculates the number of bytes that an implementation must use to store
40 // one row of pixel data.
41 static bool StrideInBytes(size_t width,
42 Format format,
43 int plane,
44 size_t* stride_in_bytes);
46 // Returns the subsampling factor applied to the given zero-indexed |plane| of
47 // the |format| both horizontally and vertically.
48 static size_t SubsamplingFactor(Format format, int plane);
50 // Overridden from gfx::GpuMemoryBuffer:
51 bool IsMapped() const override;
52 Format GetFormat() const override;
53 ClientBuffer AsClientBuffer() override;
55 void set_destruction_sync_point(uint32 sync_point) {
56 destruction_sync_point_ = sync_point;
59 protected:
60 GpuMemoryBufferImpl(gfx::GpuMemoryBufferId id,
61 const gfx::Size& size,
62 Format format,
63 const DestructionCallback& callback);
65 const gfx::GpuMemoryBufferId id_;
66 const gfx::Size size_;
67 const Format format_;
68 const DestructionCallback callback_;
69 bool mapped_;
70 uint32 destruction_sync_point_;
72 private:
73 DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferImpl);
76 } // namespace content
78 #endif // CONTENT_COMMON_GPU_CLIENT_GPU_MEMORY_BUFFER_IMPL_H_