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

Side by Side Diff: src/gpu/GrBuffer.h

Issue 1870553002: Revert of Track GL buffer state based on unique resource ID (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 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 unified diff | Download patch
« no previous file with comments | « include/gpu/GrTypesPriv.h ('k') | src/gpu/GrBufferAllocPool.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef GrBuffer_DEFINED 8 #ifndef GrBuffer_DEFINED
9 #define GrBuffer_DEFINED 9 #define GrBuffer_DEFINED
10 10
11 #include "GrGpuResource.h" 11 #include "GrGpuResource.h"
12 12
13 class GrGpu; 13 class GrGpu;
14 14
15 class GrBuffer : public GrGpuResource { 15 class GrBuffer : public GrGpuResource {
16 public: 16 public:
17 /** 17 /**
18 * Computes a scratch key for a buffer with a "dynamic" access pattern. (Buf fers with "static" 18 * Computes a scratch key for a buffer with a "dynamic" access pattern. (Buf fers with "static"
19 * and "stream" access patterns are disqualified by nature from being cached and reused.) 19 * and "stream" access patterns are disqualified by nature from being cached and reused.)
20 */ 20 */
21 static void ComputeScratchKeyForDynamicBuffer(size_t size, GrBufferType inte ndedType, 21 static void ComputeScratchKeyForDynamicBuffer(GrBufferType type, size_t size ,
22 GrScratchKey* key) { 22 GrScratchKey* key) {
23 static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateRe sourceType(); 23 static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateRe sourceType();
24 GrScratchKey::Builder builder(key, kType, 1 + (sizeof(size_t) + 3) / 4); 24 GrScratchKey::Builder builder(key, kType, 1 + (sizeof(size_t) + 3) / 4);
25 // TODO: There's not always reason to cache a buffer by type. In some (a ll?) APIs it's just 25 // TODO: There's not always reason to cache a buffer by type. In some (a ll?) APIs it's just
26 // a chunk of memory we can use/reuse for any type of data. We really on ly need to 26 // a chunk of memory we can use/reuse for any type of data. We really on ly need to
27 // differentiate between the "read" types (e.g. kGpuToCpu_BufferType) an d "draw" types. 27 // differentiate between the "read" types (e.g. kGpuToCpu_BufferType) an d "draw" types.
28 builder[0] = intendedType; 28 builder[0] = type;
29 builder[1] = (uint32_t)size; 29 builder[1] = (uint32_t)size;
30 if (sizeof(size_t) > 4) { 30 if (sizeof(size_t) > 4) {
31 builder[2] = (uint32_t)((uint64_t)size >> 32); 31 builder[2] = (uint32_t)((uint64_t)size >> 32);
32 } 32 }
33 } 33 }
34 34
35 GrBufferType type() const { return fType; }
36
35 GrAccessPattern accessPattern() const { return fAccessPattern; } 37 GrAccessPattern accessPattern() const { return fAccessPattern; }
36 38
37 /** 39 /**
38 * Returns true if the buffer is a wrapper around a CPU array. If true it 40 * Returns true if the buffer is a wrapper around a CPU array. If true it
39 * indicates that map will always succeed and will be free. 41 * indicates that map will always succeed and will be free.
40 */ 42 */
41 bool isCPUBacked() const { return fCPUBacked; } 43 bool isCPUBacked() const { return fCPUBacked; }
42 44
43 /** 45 /**
44 * Maps the buffer to be written by the CPU. 46 * Maps the buffer to be written by the CPU.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 * 103 *
102 * @return returns true if the update succeeds, false otherwise. 104 * @return returns true if the update succeeds, false otherwise.
103 */ 105 */
104 bool updateData(const void* src, size_t srcSizeInBytes) { 106 bool updateData(const void* src, size_t srcSizeInBytes) {
105 SkASSERT(!this->isMapped()); 107 SkASSERT(!this->isMapped());
106 SkASSERT(srcSizeInBytes <= fGpuMemorySize); 108 SkASSERT(srcSizeInBytes <= fGpuMemorySize);
107 return this->onUpdateData(src, srcSizeInBytes); 109 return this->onUpdateData(src, srcSizeInBytes);
108 } 110 }
109 111
110 protected: 112 protected:
111 GrBuffer(GrGpu* gpu, size_t gpuMemorySize, GrBufferType intendedType, 113 GrBuffer(GrGpu* gpu, GrBufferType type, size_t gpuMemorySize, GrAccessPatter n accessPattern,
112 GrAccessPattern accessPattern, bool cpuBacked) 114 bool cpuBacked)
113 : INHERITED(gpu, kCached_LifeCycle), 115 : INHERITED(gpu, kCached_LifeCycle),
114 fMapPtr(nullptr), 116 fMapPtr(nullptr),
117 fType(type),
115 fGpuMemorySize(gpuMemorySize), // TODO: Zero for cpu backed buffers? 118 fGpuMemorySize(gpuMemorySize), // TODO: Zero for cpu backed buffers?
116 fAccessPattern(accessPattern), 119 fAccessPattern(accessPattern),
117 fCPUBacked(cpuBacked) { 120 fCPUBacked(cpuBacked) {
118 if (!fCPUBacked && SkIsPow2(fGpuMemorySize) && kDynamic_GrAccessPattern == fAccessPattern) { 121 if (!fCPUBacked && SkIsPow2(fGpuMemorySize) && kDynamic_GrAccessPattern == fAccessPattern) {
119 GrScratchKey key; 122 GrScratchKey key;
120 ComputeScratchKeyForDynamicBuffer(fGpuMemorySize, intendedType, &key ); 123 ComputeScratchKeyForDynamicBuffer(fType, fGpuMemorySize, &key);
121 this->setScratchKey(key); 124 this->setScratchKey(key);
122 } 125 }
123 } 126 }
124 127
125 void* fMapPtr; 128 void* fMapPtr;
126 129
127 private: 130 private:
128 virtual size_t onGpuMemorySize() const { return fGpuMemorySize; } 131 virtual size_t onGpuMemorySize() const { return fGpuMemorySize; }
129 132
130 virtual void onMap() = 0; 133 virtual void onMap() = 0;
131 virtual void onUnmap() = 0; 134 virtual void onUnmap() = 0;
132 virtual bool onUpdateData(const void* src, size_t srcSizeInBytes) = 0; 135 virtual bool onUpdateData(const void* src, size_t srcSizeInBytes) = 0;
133 136
137 GrBufferType fType;
134 size_t fGpuMemorySize; 138 size_t fGpuMemorySize;
135 GrAccessPattern fAccessPattern; 139 GrAccessPattern fAccessPattern;
136 bool fCPUBacked; 140 bool fCPUBacked;
137 141
138 typedef GrGpuResource INHERITED; 142 typedef GrGpuResource INHERITED;
139 }; 143 };
140 144
141 #endif 145 #endif
OLDNEW
« no previous file with comments | « include/gpu/GrTypesPriv.h ('k') | src/gpu/GrBufferAllocPool.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698