Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(490)

Unified Diff: include/gpu/GrBuffer.h

Issue 2143333002: Add resource provider flag to avoid client-side buffers (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add resource provider flag to avoid client-side buffers Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gyp/gpu.gypi ('k') | include/gpu/GrCaps.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/gpu/GrBuffer.h
diff --git a/include/gpu/GrBuffer.h b/include/gpu/GrBuffer.h
index 829596e73456f82cc6cc5ba66f08f3fe7f92afda..b2201a140fa33acde4e3dced4e931a22f6786bf8 100644
--- a/include/gpu/GrBuffer.h
+++ b/include/gpu/GrBuffer.h
@@ -15,30 +15,26 @@ class GrGpu;
class GrBuffer : public GrGpuResource {
public:
/**
- * 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.)
+ * Creates a client-side buffer.
*/
- static void ComputeScratchKeyForDynamicBuffer(size_t size, GrBufferType intendedType,
- GrScratchKey* key) {
- static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResourceType();
- GrScratchKey::Builder builder(key, kType, 1 + (sizeof(size_t) + 3) / 4);
- // 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] = intendedType;
- builder[1] = (uint32_t)size;
- if (sizeof(size_t) > 4) {
- builder[2] = (uint32_t)((uint64_t)size >> 32);
- }
- }
+ static SK_WARN_UNUSED_RESULT GrBuffer* CreateCPUBacked(GrGpu*, size_t sizeInBytes, GrBufferType,
+ const void* data = nullptr);
+
+ /**
+ * Computes a scratch key for a GPU-side buffer with a "dynamic" access pattern. (Buffers with
+ * "static" and "stream" patterns are disqualified by nature from being cached and reused.)
+ */
+ static void ComputeScratchKeyForDynamicVBO(size_t size, GrBufferType, GrScratchKey*);
GrAccessPattern accessPattern() const { return fAccessPattern; }
+ size_t sizeInBytes() const { return fSizeInBytes; }
/**
* Returns true if the buffer is a wrapper around a CPU array. If true it
* indicates that map will always succeed and will be free.
*/
- bool isCPUBacked() const { return fCPUBacked; }
+ bool isCPUBacked() const { return SkToBool(fCPUData); }
+ size_t baseOffset() const { return reinterpret_cast<size_t>(fCPUData); }
/**
* Maps the buffer to be written by the CPU.
@@ -103,40 +99,37 @@ public:
*/
bool updateData(const void* src, size_t srcSizeInBytes) {
SkASSERT(!this->isMapped());
- SkASSERT(srcSizeInBytes <= fGpuMemorySize);
+ SkASSERT(srcSizeInBytes <= fSizeInBytes);
return this->onUpdateData(src, srcSizeInBytes);
}
-protected:
- GrBuffer(GrGpu* gpu, size_t gpuMemorySize, GrBufferType intendedType,
- GrAccessPattern accessPattern, bool cpuBacked)
- : INHERITED(gpu),
- fMapPtr(nullptr),
- fGpuMemorySize(gpuMemorySize), // TODO: Zero for cpu backed buffers?
- fAccessPattern(accessPattern),
- fCPUBacked(cpuBacked),
- fIntendedType(intendedType) {
+ ~GrBuffer() override {
+ sk_free(fCPUData);
}
- void computeScratchKey(GrScratchKey* key) const override {
- if (!fCPUBacked && SkIsPow2(fGpuMemorySize) && kDynamic_GrAccessPattern == fAccessPattern) {
- ComputeScratchKeyForDynamicBuffer(fGpuMemorySize, fIntendedType, key);
- }
- }
+protected:
+ GrBuffer(GrGpu*, size_t sizeInBytes, GrBufferType, GrAccessPattern);
void* fMapPtr;
private:
- size_t onGpuMemorySize() const override { return fGpuMemorySize; }
+ /**
+ * Internal constructor to make a CPU-backed buffer.
+ */
+ GrBuffer(GrGpu*, size_t sizeInBytes, GrBufferType, void* cpuData);
- virtual void onMap() = 0;
- virtual void onUnmap() = 0;
- virtual bool onUpdateData(const void* src, size_t srcSizeInBytes) = 0;
+ virtual void onMap() { SkASSERT(this->isCPUBacked()); fMapPtr = fCPUData; }
+ virtual void onUnmap() { SkASSERT(this->isCPUBacked()); }
+ virtual bool onUpdateData(const void* src, size_t srcSizeInBytes);
- size_t fGpuMemorySize;
+ size_t onGpuMemorySize() const override { return fSizeInBytes; } // TODO: zero for cpu backed?
+ void computeScratchKey(GrScratchKey* key) const override;
+
+ size_t fSizeInBytes;
GrAccessPattern fAccessPattern;
- bool fCPUBacked;
+ void* fCPUData;
GrBufferType fIntendedType;
+
typedef GrGpuResource INHERITED;
};
« no previous file with comments | « gyp/gpu.gypi ('k') | include/gpu/GrCaps.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698