blob: 6a90d0334c79b78b75b484f879549baa9a16caf9 [file] [log] [blame]
cdalton397536c2016-03-25 12:15:03 -07001/*
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
14class GrGLGpu;
15class GrGLCaps;
16
17class GrGLBuffer : public GrBuffer {
18public:
cdaltone2e71c22016-04-07 18:13:29 -070019 static GrGLBuffer* Create(GrGLGpu*, size_t size, GrBufferType intendedType, GrAccessPattern,
20 const void* data = nullptr);
cdalton397536c2016-03-25 12:15:03 -070021
22 ~GrGLBuffer() {
23 // either release or abandon should have been called by the owner of this object.
24 SkASSERT(0 == fBufferID);
25 }
26
cdalton397536c2016-03-25 12:15:03 -070027 GrGLuint bufferID() const { return fBufferID; }
cdalton397536c2016-03-25 12:15:03 -070028
cdalton74b8d322016-04-11 14:47:28 -070029 /**
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 */
33 size_t glSizeInBytes() const { return fGLSizeInBytes; }
34
35 void setHasAttachedToTexture() { fHasAttachedToTexture = true; }
36 bool hasAttachedToTexture() const { return fHasAttachedToTexture; }
37
cdalton397536c2016-03-25 12:15:03 -070038protected:
csmartdalton485a1202016-07-13 10:16:32 -070039 GrGLBuffer(GrGLGpu*, size_t size, GrBufferType intendedType, GrAccessPattern, const void* data);
cdalton397536c2016-03-25 12:15:03 -070040
41 void onAbandon() override;
42 void onRelease() override;
43 void setMemoryBacking(SkTraceMemoryDump* traceMemoryDump,
44 const SkString& dumpName) const override;
45
46private:
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
cdaltone2e71c22016-04-07 18:13:29 -070058 GrBufferType fIntendedType;
59 GrGLuint fBufferID;
cdaltone2e71c22016-04-07 18:13:29 -070060 GrGLenum fUsage;
cdalton74b8d322016-04-11 14:47:28 -070061 size_t fGLSizeInBytes;
62 bool fHasAttachedToTexture;
cdalton397536c2016-03-25 12:15:03 -070063
64 typedef GrBuffer INHERITED;
65};
66
67#endif