| 1 |
/* |
| 2 |
* Copyright 2017 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 GrMockBuffer_DEFINED |
| 9 |
#define GrMockBuffer_DEFINED |
| 10 |
|
| 11 |
#include "include/gpu/GpuTypes.h" |
| 12 |
#include "include/private/base/SkMalloc.h" |
| 13 |
#include "include/private/gpu/ganesh/GrTypesPriv.h" |
| 14 |
#include "src/gpu/ganesh/GrCaps.h" |
| 15 |
#include "src/gpu/ganesh/GrGpu.h" |
| 16 |
#include "src/gpu/ganesh/GrGpuBuffer.h" |
| 17 |
#include "src/gpu/ganesh/mock/GrMockGpu.h" |
| 18 |
|
| 19 |
#include <cstddef> |
| 20 |
#include <string_view> |
| 21 |
|
| 22 |
class GrMockBuffer : public GrGpuBuffer { |
| 23 |
public: |
| 24 |
GrMockBuffer(GrMockGpu* gpu, size_t sizeInBytes, GrGpuBufferType type, |
| 25 |
GrAccessPattern accessPattern, |
| 26 |
std::string_view label) |
| 27 |
: INHERITED(gpu, sizeInBytes, type, accessPattern, label) { |
| 28 |
this->registerWithCache(skgpu::Budgeted::kYes); |
| 29 |
} |
| 30 |
|
| 31 |
private: |
| 32 |
void onMap(MapType) override { |
| 33 |
if (GrCaps::kNone_MapFlags != this->getGpu()->caps()->mapBufferFlags()) { |
| 34 |
fMapPtr = sk_malloc_throw(this->size()); |
| 35 |
} |
| 36 |
} |
| 37 |
void onUnmap(MapType) override { sk_free(fMapPtr); } |
| 38 |
bool onClearToZero() override { return true; } |
| 39 |
bool onUpdateData(const void* src, size_t offset, size_t size, bool preserve) override { |
| 40 |
return true; |
| 41 |
} |
| 42 |
|
| 43 |
using INHERITED = GrGpuBuffer; |
| 44 |
}; |
| 45 |
|
| 46 |
#endif |