1 /* 2 * Copyright 2019 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 GrCpuBuffer_DEFINED 9 #define GrCpuBuffer_DEFINED 10 11 #include "GrBuffer.h" 12 #include "GrNonAtomicRef.h" 13 14 class GrCpuBuffer final : public GrNonAtomicRef<GrCpuBuffer>, public GrBuffer { 15 public: Make(size_t size)16 static sk_sp<GrCpuBuffer> Make(size_t size) { 17 SkASSERT(size > 0); 18 auto mem = ::operator new(sizeof(GrCpuBuffer) + size); 19 return sk_sp<GrCpuBuffer>(new (mem) GrCpuBuffer((char*)mem + sizeof(GrCpuBuffer), size)); 20 } 21 ref()22 void ref() const override { GrNonAtomicRef<GrCpuBuffer>::ref(); } unref()23 void unref() const override { GrNonAtomicRef<GrCpuBuffer>::unref(); } size()24 size_t size() const override { return fSize; } isCpuBuffer()25 bool isCpuBuffer() const override { return true; } 26 data()27 char* data() { return reinterpret_cast<char*>(fData); } data()28 const char* data() const { return reinterpret_cast<const char*>(fData); } 29 30 private: GrCpuBuffer(void * data,size_t size)31 GrCpuBuffer(void* data, size_t size) : fData(data), fSize(size) {} 32 void* fData; 33 size_t fSize; 34 }; 35 36 #endif 37