blob: 17b56a0f02995aae56228834b741ea2b30edf716 [file] [log] [blame]
Brian Salomoncfe910d2017-07-06 16:40:18 -04001/*
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/gpu/GrCaps.h"
12#include "src/gpu/GrGpuBuffer.h"
13#include "src/gpu/mock/GrMockGpu.h"
Brian Salomoncfe910d2017-07-06 16:40:18 -040014
Brian Salomondbf70722019-02-07 11:31:24 -050015class GrMockBuffer : public GrGpuBuffer {
Brian Salomoncfe910d2017-07-06 16:40:18 -040016public:
Brian Salomonae64c192019-02-05 09:41:37 -050017 GrMockBuffer(GrMockGpu* gpu, size_t sizeInBytes, GrGpuBufferType type,
Brian Salomoncfe910d2017-07-06 16:40:18 -040018 GrAccessPattern accessPattern)
19 : INHERITED(gpu, sizeInBytes, type, accessPattern) {
20 this->registerWithCache(SkBudgeted::kYes);
21 }
22
23private:
Chris Daltonfddb6c02017-11-04 15:22:22 -060024 void onMap() override {
25 if (GrCaps::kNone_MapFlags != this->getGpu()->caps()->mapBufferFlags()) {
Brian Salomondbf70722019-02-07 11:31:24 -050026 fMapPtr = sk_malloc_throw(this->size());
Chris Daltonfddb6c02017-11-04 15:22:22 -060027 }
28 }
29 void onUnmap() override { sk_free(fMapPtr); }
Brian Salomoncfe910d2017-07-06 16:40:18 -040030 bool onUpdateData(const void* src, size_t srcSizeInBytes) override { return true; }
31
Brian Salomondbf70722019-02-07 11:31:24 -050032 typedef GrGpuBuffer INHERITED;
Brian Salomoncfe910d2017-07-06 16:40:18 -040033};
34
35#endif