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