| Index: src/gpu/GrBuffer.h
|
| diff --git a/src/gpu/GrGeometryBuffer.h b/src/gpu/GrBuffer.h
|
| similarity index 59%
|
| rename from src/gpu/GrGeometryBuffer.h
|
| rename to src/gpu/GrBuffer.h
|
| index 56a6cae3fb08f32f8e3e7fcbbb276ba81620b858..c2125ccdf454413a18c4fa209c66f5fae641836a 100644
|
| --- a/src/gpu/GrGeometryBuffer.h
|
| +++ b/src/gpu/GrBuffer.h
|
| @@ -7,26 +7,40 @@
|
| */
|
|
|
|
|
| -#ifndef GrGeometryBuffer_DEFINED
|
| -#define GrGeometryBuffer_DEFINED
|
| +#ifndef GrBuffer_DEFINED
|
| +#define GrBuffer_DEFINED
|
|
|
| #include "GrGpuResource.h"
|
|
|
| class GrGpu;
|
|
|
| -/**
|
| - * Parent class for vertex and index buffers
|
| - */
|
| -class GrGeometryBuffer : public GrGpuResource {
|
| +class GrBuffer : public GrGpuResource {
|
| public:
|
| -
|
| -
|
| /**
|
| - *Retrieves whether the buffer was created with the dynamic flag
|
| - *
|
| - * @return true if the buffer was created with the dynamic flag
|
| + * Computes a scratch key for a buffer with a "dynamic" access pattern. (Buffers with "static"
|
| + * and "stream" access patterns are disqualified by nature from being cached and reused.)
|
| */
|
| - bool dynamic() const { return fDynamic; }
|
| + static void ComputeScratchKeyForDynamicBuffer(GrBufferType type, size_t size,
|
| + GrScratchKey* key) {
|
| + static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResourceType();
|
| + if (uint32_t hi = size >> 32) {
|
| + GrScratchKey::Builder builder(key, kType, 3);
|
| + builder[0] = type;
|
| + builder[1] = size;
|
| + builder[2] = hi;
|
| + } else {
|
| + GrScratchKey::Builder builder(key, kType, 2);
|
| + // TODO: There's not always reason to cache a buffer by type. In some (all?) APIs it's
|
| + // just a chunk of memory we can use/reuse for any type of data. We really only need to
|
| + // differentiate between the "read" types (e.g. kGpuToCpu_BufferType) and "draw" types.
|
| + builder[0] = type;
|
| + builder[1] = size;
|
| + }
|
| + }
|
| +
|
| + GrBufferType type() const { return fType; }
|
| +
|
| + GrAccessPattern accessPattern() const { return fAccessPattern; }
|
|
|
| /**
|
| * Returns true if the buffer is a wrapper around a CPU array. If true it
|
| @@ -50,7 +64,10 @@ public:
|
| *
|
| * @return a pointer to the data or nullptr if the map fails.
|
| */
|
| - void* map() { return (fMapPtr = this->onMap()); }
|
| + void* map() {
|
| + this->onMap();
|
| + return fMapPtr;
|
| + }
|
|
|
| /**
|
| * Unmaps the buffer.
|
| @@ -99,24 +116,28 @@ public:
|
| }
|
|
|
| protected:
|
| - GrGeometryBuffer(GrGpu* gpu, size_t gpuMemorySize, bool dynamic, bool cpuBacked)
|
| - : INHERITED(gpu, kCached_LifeCycle)
|
| - , fMapPtr(nullptr)
|
| - , fGpuMemorySize(gpuMemorySize)
|
| - , fDynamic(dynamic)
|
| - , fCPUBacked(cpuBacked) {}
|
| + GrBuffer(GrGpu* gpu, GrBufferType type, size_t gpuMemorySize, GrAccessPattern accessPattern,
|
| + bool cpuBacked)
|
| + : INHERITED(gpu, kCached_LifeCycle),
|
| + fMapPtr(nullptr),
|
| + fType(type),
|
| + fGpuMemorySize(gpuMemorySize), // TODO: Zero for cpu backed buffers?
|
| + fAccessPattern(accessPattern),
|
| + fCPUBacked(cpuBacked) {}
|
| +
|
| + void* fMapPtr;
|
|
|
| private:
|
| virtual size_t onGpuMemorySize() const { return fGpuMemorySize; }
|
|
|
| - virtual void* onMap() = 0;
|
| + virtual void onMap() = 0;
|
| virtual void onUnmap() = 0;
|
| virtual bool onUpdateData(const void* src, size_t srcSizeInBytes) = 0;
|
|
|
| - void* fMapPtr;
|
| - size_t fGpuMemorySize;
|
| - bool fDynamic;
|
| - bool fCPUBacked;
|
| + GrBufferType fType;
|
| + size_t fGpuMemorySize;
|
| + GrAccessPattern fAccessPattern;
|
| + bool fCPUBacked;
|
|
|
| typedef GrGpuResource INHERITED;
|
| };
|
|
|