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 11 #include "include/gpu/gl/GrGLTypes.h" 12 #include "src/gpu/GrGpuBuffer.h" 13 14 class GrGLGpu; 15 class GrGLCaps; 16 17 class GrGLBuffer : public GrGpuBuffer { 18 public: 19 static sk_sp<GrGLBuffer> Make(GrGLGpu*, size_t size, GrGpuBufferType intendedType, 20 GrAccessPattern, const void* data = nullptr); 21 ~GrGLBuffer()22 ~GrGLBuffer() override { 23 // either release or abandon should have been called by the owner of this object. 24 SkASSERT(0 == fBufferID); 25 } 26 bufferID()27 GrGLuint bufferID() const { return fBufferID; } 28 29 /** 30 * Returns the actual size of the underlying GL buffer object. In certain cases we may make this 31 * smaller than the size reported by GrGpuBuffer. 32 */ glSizeInBytes()33 size_t glSizeInBytes() const { return fGLSizeInBytes; } 34 setHasAttachedToTexture()35 void setHasAttachedToTexture() { fHasAttachedToTexture = true; } hasAttachedToTexture()36 bool hasAttachedToTexture() const { return fHasAttachedToTexture; } 37 38 protected: 39 GrGLBuffer(GrGLGpu*, size_t size, GrGpuBufferType intendedType, GrAccessPattern, 40 const void* data); 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 59 GrGpuBufferType fIntendedType; 60 GrGLuint fBufferID; 61 GrGLenum fUsage; 62 size_t fGLSizeInBytes; 63 bool fHasAttachedToTexture; 64 65 using INHERITED = GrGpuBuffer; 66 }; 67 68 #endif 69