Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / content / common / gpu / client / gpu_memory_buffer_impl.h
blobfa65133d5fc88c9ea56b00779063b6b339797031
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 Usage usage,
32 const DestructionCallback& callback);
34 // Type-checking upcast routine. Returns an NULL on failure.
35 static GpuMemoryBufferImpl* FromClientBuffer(ClientBuffer buffer);
37 // Returns the number of planes based on the format of the buffer.
38 static size_t NumberOfPlanesForGpuMemoryBufferFormat(Format format);
40 // Returns the subsampling factor applied to the given zero-indexed |plane| of
41 // the |format| both horizontally and vertically.
42 static size_t SubsamplingFactor(Format format, int plane);
44 // Returns the number of bytes used to store a row of the given zero-indexed
45 // |plane| of |format|.
46 // Note: This is an approximation and the exact size used by an implementation
47 // might be different.
48 static bool RowSizeInBytes(size_t width,
49 Format format,
50 int plane,
51 size_t* size_in_bytes);
53 // Returns the number of bytes used to store all the planes of a given
54 // |format|.
55 // Note: This is an approximation and the exact size used by an implementation
56 // might be different.
57 static bool BufferSizeInBytes(const gfx::Size& size,
58 Format format,
59 size_t* size_in_bytes);
61 // Overridden from gfx::GpuMemoryBuffer:
62 bool IsMapped() const override;
63 Format GetFormat() const override;
64 gfx::GpuMemoryBufferId GetId() const override;
65 ClientBuffer AsClientBuffer() override;
67 void set_destruction_sync_point(uint32 sync_point) {
68 destruction_sync_point_ = sync_point;
71 protected:
72 GpuMemoryBufferImpl(gfx::GpuMemoryBufferId id,
73 const gfx::Size& size,
74 Format format,
75 const DestructionCallback& callback);
77 const gfx::GpuMemoryBufferId id_;
78 const gfx::Size size_;
79 const Format format_;
80 const DestructionCallback callback_;
81 bool mapped_;
82 uint32 destruction_sync_point_;
84 private:
85 DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferImpl);
88 } // namespace content
90 #endif // CONTENT_COMMON_GPU_CLIENT_GPU_MEMORY_BUFFER_IMPL_H_