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 "GrBuffer.h" 12 #include "gl/GrGLTypes.h" 13 14 class GrGLGpu; 15 class GrGLCaps; 16 17 class GrGLBuffer : public GrBuffer { 18 public: 19 static GrGLBuffer* Create(GrGLGpu*, size_t size, GrBufferType intendedType, GrAccessPattern, 20 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 GrBuffer. 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, GrBufferType intendedType, GrAccessPattern, const void* data); 40 41 void onAbandon() override; 42 void onRelease() override; 43 void setMemoryBacking(SkTraceMemoryDump* traceMemoryDump, 44 const SkString& dumpName) const override; 45 46 private: 47 GrGLGpu* glGpu() const; 48 const GrGLCaps& glCaps() const; 49 50 void onMap() override; 51 void onUnmap() override; 52 bool onUpdateData(const void* src, size_t srcSizeInBytes) override; 53 54 #ifdef SK_DEBUG 55 void validate() const; 56 #endif 57 58 GrBufferType fIntendedType; 59 GrGLuint fBufferID; 60 GrGLenum fUsage; 61 size_t fGLSizeInBytes; 62 bool fHasAttachedToTexture; 63 64 typedef GrBuffer INHERITED; 65 }; 66 67 #endif 68