Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 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 | |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 11 | #include "GrCaps.h" |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 12 | #include "GrGpuBuffer.h" |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 13 | #include "GrMockGpu.h" |
| 14 | |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 15 | class GrMockBuffer : public GrGpuBuffer { |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 16 | public: |
Brian Salomon | ae64c19 | 2019-02-05 09:41:37 -0500 | [diff] [blame] | 17 | GrMockBuffer(GrMockGpu* gpu, size_t sizeInBytes, GrGpuBufferType type, |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 18 | GrAccessPattern accessPattern) |
| 19 | : INHERITED(gpu, sizeInBytes, type, accessPattern) { |
| 20 | this->registerWithCache(SkBudgeted::kYes); |
| 21 | } |
| 22 | |
| 23 | private: |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 24 | void onMap() override { |
| 25 | if (GrCaps::kNone_MapFlags != this->getGpu()->caps()->mapBufferFlags()) { |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 26 | fMapPtr = sk_malloc_throw(this->size()); |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 27 | } |
| 28 | } |
| 29 | void onUnmap() override { sk_free(fMapPtr); } |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 30 | bool onUpdateData(const void* src, size_t srcSizeInBytes) override { return true; } |
| 31 | |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 32 | typedef GrGpuBuffer INHERITED; |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 33 | }; |
| 34 | |
| 35 | #endif |