OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrGLBuffer_DEFINED | 8 #ifndef GrGLBuffer_DEFINED |
9 #define GrGLBuffer_DEFINED | 9 #define GrGLBuffer_DEFINED |
10 | 10 |
11 #include "GrBuffer.h" | 11 #include "GrBuffer.h" |
12 #include "gl/GrGLTypes.h" | 12 #include "gl/GrGLTypes.h" |
13 | 13 |
14 class GrGLGpu; | 14 class GrGLGpu; |
15 class GrGLCaps; | 15 class GrGLCaps; |
16 | 16 |
17 class GrGLBuffer : public GrBuffer { | 17 class GrGLBuffer : public GrBuffer { |
18 public: | 18 public: |
19 static GrGLBuffer* Create(GrGLGpu*, size_t size, GrBufferType intendedType,
GrAccessPattern, | 19 static GrGLBuffer* Create(GrGLGpu*, size_t size, GrBufferType intendedType,
GrAccessPattern, |
20 const void* data = nullptr); | 20 const void* data = nullptr); |
21 | 21 |
22 ~GrGLBuffer() { | 22 ~GrGLBuffer() { |
23 // either release or abandon should have been called by the owner of thi
s object. | 23 // either release or abandon should have been called by the owner of thi
s object. |
24 SkASSERT(0 == fBufferID); | 24 SkASSERT(0 == fBufferID); |
25 } | 25 } |
26 | 26 |
27 GrGLuint bufferID() const { return fBufferID; } | 27 GrGLuint bufferID() const { return fBufferID; } |
28 size_t baseOffset() const { return reinterpret_cast<size_t>(fCPUData); } | |
29 | 28 |
30 /** | 29 /** |
31 * Returns the actual size of the underlying GL buffer object. In certain ca
ses we may make this | 30 * Returns the actual size of the underlying GL buffer object. In certain ca
ses we may make this |
32 * smaller than the size reported by GrBuffer. | 31 * smaller than the size reported by GrBuffer. |
33 */ | 32 */ |
34 size_t glSizeInBytes() const { return fGLSizeInBytes; } | 33 size_t glSizeInBytes() const { return fGLSizeInBytes; } |
35 | 34 |
36 void setHasAttachedToTexture() { fHasAttachedToTexture = true; } | 35 void setHasAttachedToTexture() { fHasAttachedToTexture = true; } |
37 bool hasAttachedToTexture() const { return fHasAttachedToTexture; } | 36 bool hasAttachedToTexture() const { return fHasAttachedToTexture; } |
38 | 37 |
39 protected: | 38 protected: |
40 GrGLBuffer(GrGLGpu*, size_t size, GrBufferType intendedType, GrAccessPattern
, bool cpuBacked, | 39 GrGLBuffer(GrGLGpu*, size_t size, GrBufferType intendedType, GrAccessPattern
, const void* data); |
41 const void* data); | |
42 | 40 |
43 void onAbandon() override; | 41 void onAbandon() override; |
44 void onRelease() override; | 42 void onRelease() override; |
45 void setMemoryBacking(SkTraceMemoryDump* traceMemoryDump, | 43 void setMemoryBacking(SkTraceMemoryDump* traceMemoryDump, |
46 const SkString& dumpName) const override; | 44 const SkString& dumpName) const override; |
47 | 45 |
48 private: | 46 private: |
49 GrGLGpu* glGpu() const; | 47 GrGLGpu* glGpu() const; |
50 const GrGLCaps& glCaps() const; | 48 const GrGLCaps& glCaps() const; |
51 | 49 |
52 void onMap() override; | 50 void onMap() override; |
53 void onUnmap() override; | 51 void onUnmap() override; |
54 bool onUpdateData(const void* src, size_t srcSizeInBytes) override; | 52 bool onUpdateData(const void* src, size_t srcSizeInBytes) override; |
55 | 53 |
56 #ifdef SK_DEBUG | 54 #ifdef SK_DEBUG |
57 void validate() const; | 55 void validate() const; |
58 #endif | 56 #endif |
59 | 57 |
60 void* fCPUData; | |
61 GrBufferType fIntendedType; | 58 GrBufferType fIntendedType; |
62 GrGLuint fBufferID; | 59 GrGLuint fBufferID; |
63 size_t fSizeInBytes; | |
64 GrGLenum fUsage; | 60 GrGLenum fUsage; |
65 size_t fGLSizeInBytes; | 61 size_t fGLSizeInBytes; |
66 bool fHasAttachedToTexture; | 62 bool fHasAttachedToTexture; |
67 | 63 |
68 typedef GrBuffer INHERITED; | 64 typedef GrBuffer INHERITED; |
69 }; | 65 }; |
70 | 66 |
71 #endif | 67 #endif |
OLD | NEW |