• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/ganesh/GrGpuBuffer.h"
13 
14 class GrGLGpu;
15 class GrGLCaps;
16 
17 class GrGLBuffer : public GrGpuBuffer {
18 public:
19     static sk_sp<GrGLBuffer> Make(GrGLGpu*,
20                                   size_t size,
21                                   GrGpuBufferType intendedType,
22                                   GrAccessPattern);
23 
~GrGLBuffer()24     ~GrGLBuffer() override {
25         // either release or abandon should have been called by the owner of this object.
26         SkASSERT(0 == fBufferID);
27     }
28 
bufferID()29     GrGLuint bufferID() const { return fBufferID; }
30 
setHasAttachedToTexture()31     void setHasAttachedToTexture() { fHasAttachedToTexture = true; }
hasAttachedToTexture()32     bool hasAttachedToTexture() const { return fHasAttachedToTexture; }
33 
34 protected:
35     GrGLBuffer(GrGLGpu*,
36                size_t size,
37                GrGpuBufferType intendedType,
38                GrAccessPattern,
39                std::string_view label);
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(MapType) override;
51     void onUnmap(MapType) override;
52     bool onClearToZero() override;
53     bool onUpdateData(const void* src, size_t offset, size_t size, bool preserve) override;
54 
55     void onSetLabel() override;
56 
57     GrGpuBufferType fIntendedType;
58     GrGLuint        fBufferID;
59     GrGLenum        fUsage;
60     bool            fHasAttachedToTexture;
61 
62     using INHERITED = GrGpuBuffer;
63 };
64 
65 #endif
66