blob: d408e468cd39853a8486c3b96f83cbf3cd8bf0ac [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/gpu/gl/GrGLTypes.h"
12#include "src/gpu/GrGpuBuffer.h"
cdalton397536c2016-03-25 12:15:03 -070013
14class GrGLGpu;
15class GrGLCaps;
16
Brian Salomondbf70722019-02-07 11:31:24 -050017class GrGLBuffer : public GrGpuBuffer {
cdalton397536c2016-03-25 12:15:03 -070018public:
Brian Salomonae64c192019-02-05 09:41:37 -050019 static sk_sp<GrGLBuffer> Make(GrGLGpu*, size_t size, GrGpuBufferType intendedType,
20 GrAccessPattern, const void* data = nullptr);
cdalton397536c2016-03-25 12:15:03 -070021
Brian Salomond3b65972017-03-22 12:05:03 -040022 ~GrGLBuffer() override {
cdalton397536c2016-03-25 12:15:03 -070023 // 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
Brian Salomondbf70722019-02-07 11:31:24 -050031 * smaller than the size reported by GrGpuBuffer.
cdalton74b8d322016-04-11 14:47:28 -070032 */
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:
Brian Salomonae64c192019-02-05 09:41:37 -050039 GrGLBuffer(GrGLGpu*, size_t size, GrGpuBufferType intendedType, GrAccessPattern,
40 const void* data);
cdalton397536c2016-03-25 12:15:03 -070041
42 void onAbandon() override;
43 void onRelease() override;
44 void setMemoryBacking(SkTraceMemoryDump* traceMemoryDump,
45 const SkString& dumpName) const override;
46
47private:
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 Salomonae64c192019-02-05 09:41:37 -050059 GrGpuBufferType fIntendedType;
60 GrGLuint fBufferID;
61 GrGLenum fUsage;
62 size_t fGLSizeInBytes;
63 bool fHasAttachedToTexture;
cdalton397536c2016-03-25 12:15:03 -070064
Brian Salomondbf70722019-02-07 11:31:24 -050065 typedef GrGpuBuffer INHERITED;
cdalton397536c2016-03-25 12:15:03 -070066};
67
68#endif