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 "GrBuffer.h"
12#include "GrCaps.h"
13#include "GrMockGpu.h"
14
15class GrMockBuffer : public GrBuffer {
16public:
17    GrMockBuffer(GrMockGpu* gpu, size_t sizeInBytes, GrBufferType type,
18                 GrAccessPattern accessPattern)
19            : INHERITED(gpu, sizeInBytes, type, accessPattern) {
20        this->registerWithCache(SkBudgeted::kYes);
21    }
22
23private:
24    void onMap() override {
25        if (GrCaps::kNone_MapFlags != this->getGpu()->caps()->mapBufferFlags()) {
26            fMapPtr = sk_malloc_throw(this->sizeInBytes());
27        }
28    }
29    void onUnmap() override { sk_free(fMapPtr); }
30    bool onUpdateData(const void* src, size_t srcSizeInBytes) override { return true; }
31
32    typedef GrBuffer INHERITED;
33};
34
35#endif
36