blob: efb959b82e069fe271ce329c363d7e30476da852 [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
Chris Daltonfddb6c02017-11-04 15:22:22 -060011#include "GrCaps.h"
Brian Salomondbf70722019-02-07 11:31:24 -050012#include "GrGpuBuffer.h"
Brian Salomoncfe910d2017-07-06 16:40:18 -040013#include "GrMockGpu.h"
14
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