| 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/core/SkRefCnt.h" |
| 12 |
#include "include/gpu/ganesh/gl/GrGLTypes.h" |
| 13 |
#include "include/private/base/SkAssert.h" |
| 14 |
#include "include/private/gpu/ganesh/GrTypesPriv.h" |
| 15 |
#include "src/gpu/ganesh/GrGpuBuffer.h" |
| 16 |
|
| 17 |
#include <cstddef> |
| 18 |
#include <string_view> |
| 19 |
|
| 20 |
class GrGLCaps; |
| 21 |
class GrGLGpu; |
| 22 |
class SkString; |
| 23 |
class SkTraceMemoryDump; |
| 24 |
|
| 25 |
class GrGLBuffer : public GrGpuBuffer { |
| 26 |
public: |
| 27 |
static sk_sp<GrGLBuffer> Make(GrGLGpu*, |
| 28 |
size_t size, |
| 29 |
GrGpuBufferType intendedType, |
| 30 |
GrAccessPattern); |
| 31 |
|
| 32 |
~GrGLBuffer() override { |
| 33 |
// either release or abandon should have been called by the owner of this object. |
| 34 |
SkASSERT(0 == fBufferID); |
| 35 |
} |
| 36 |
|
| 37 |
GrGLuint bufferID() const { return fBufferID; } |
| 38 |
|
| 39 |
void setHasAttachedToTexture() { fHasAttachedToTexture = true; } |
| 40 |
bool hasAttachedToTexture() const { return fHasAttachedToTexture; } |
| 41 |
|
| 42 |
protected: |
| 43 |
GrGLBuffer(GrGLGpu*, |
| 44 |
size_t size, |
| 45 |
GrGpuBufferType intendedType, |
| 46 |
GrAccessPattern, |
| 47 |
std::string_view label); |
| 48 |
|
| 49 |
void onAbandon() override; |
| 50 |
void onRelease() override; |
| 51 |
void setMemoryBacking(SkTraceMemoryDump* traceMemoryDump, |
| 52 |
const SkString& dumpName) const override; |
| 53 |
|
| 54 |
private: |
| 55 |
GrGLGpu* glGpu() const; |
| 56 |
const GrGLCaps& glCaps() const; |
| 57 |
|
| 58 |
void onMap(MapType) override; |
| 59 |
void onUnmap(MapType) override; |
| 60 |
bool onClearToZero() override; |
| 61 |
bool onUpdateData(const void* src, size_t offset, size_t size, bool preserve) override; |
| 62 |
|
| 63 |
void onSetLabel() override; |
| 64 |
|
| 65 |
GrGpuBufferType fIntendedType; |
| 66 |
GrGLuint fBufferID; |
| 67 |
GrGLenum fUsage; |
| 68 |
bool fHasAttachedToTexture; |
| 69 |
|
| 70 |
using INHERITED = GrGpuBuffer; |
| 71 |
}; |
| 72 |
|
| 73 |
#endif |