OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 #include "GrResourceProvider.h" | 8 #include "GrResourceProvider.h" |
9 | 9 |
10 #include "GrBuffer.h" | 10 #include "GrBuffer.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 93 |
94 GrBuffer* GrResourceProvider::createBuffer(size_t size, GrBufferType intendedTyp
e, | 94 GrBuffer* GrResourceProvider::createBuffer(size_t size, GrBufferType intendedTyp
e, |
95 GrAccessPattern accessPattern, uint32
_t flags, | 95 GrAccessPattern accessPattern, uint32
_t flags, |
96 const void* data) { | 96 const void* data) { |
97 if (this->isAbandoned()) { | 97 if (this->isAbandoned()) { |
98 return nullptr; | 98 return nullptr; |
99 } | 99 } |
100 if (kDynamic_GrAccessPattern != accessPattern) { | 100 if (kDynamic_GrAccessPattern != accessPattern) { |
101 return this->gpu()->createBuffer(size, intendedType, accessPattern, data
); | 101 return this->gpu()->createBuffer(size, intendedType, accessPattern, data
); |
102 } | 102 } |
| 103 if (!(flags & kRequireGpuMemory_Flag) && |
| 104 this->gpu()->caps()->preferClientSideDynamicBuffers() && |
| 105 GrBufferTypeIsVertexOrIndex(intendedType) && |
| 106 kDynamic_GrAccessPattern == accessPattern) { |
| 107 return GrBuffer::CreateCPUBacked(this->gpu(), size, intendedType, data); |
| 108 } |
103 | 109 |
104 // bin by pow2 with a reasonable min | 110 // bin by pow2 with a reasonable min |
105 static const uint32_t MIN_SIZE = 1 << 12; | 111 static const uint32_t MIN_SIZE = 1 << 12; |
106 size_t allocSize = SkTMax(MIN_SIZE, GrNextPow2(SkToUInt(size))); | 112 size_t allocSize = SkTMax(MIN_SIZE, GrNextPow2(SkToUInt(size))); |
107 | 113 |
108 GrScratchKey key; | 114 GrScratchKey key; |
109 GrBuffer::ComputeScratchKeyForDynamicBuffer(allocSize, intendedType, &key); | 115 GrBuffer::ComputeScratchKeyForDynamicVBO(allocSize, intendedType, &key); |
110 uint32_t scratchFlags = 0; | 116 uint32_t scratchFlags = 0; |
111 if (flags & kNoPendingIO_Flag) { | 117 if (flags & kNoPendingIO_Flag) { |
112 scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag; | 118 scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag; |
113 } else { | 119 } else { |
114 scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag; | 120 scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag; |
115 } | 121 } |
116 GrBuffer* buffer = static_cast<GrBuffer*>( | 122 GrBuffer* buffer = static_cast<GrBuffer*>( |
117 this->cache()->findAndRefScratchResource(key, allocSize, scratchFlags)); | 123 this->cache()->findAndRefScratchResource(key, allocSize, scratchFlags)); |
118 if (!buffer) { | 124 if (!buffer) { |
119 buffer = this->gpu()->createBuffer(allocSize, intendedType, kDynamic_GrA
ccessPattern); | 125 buffer = this->gpu()->createBuffer(allocSize, intendedType, kDynamic_GrA
ccessPattern); |
120 if (!buffer) { | 126 if (!buffer) { |
121 return nullptr; | 127 return nullptr; |
122 } | 128 } |
123 } | 129 } |
124 if (data) { | 130 if (data) { |
125 buffer->updateData(data, size); | 131 buffer->updateData(data, size); |
126 } | 132 } |
| 133 SkASSERT(!buffer->isCPUBacked()); // We should only cache real VBOs. |
127 return buffer; | 134 return buffer; |
128 } | 135 } |
129 | 136 |
130 GrBatchAtlas* GrResourceProvider::createAtlas(GrPixelConfig config, | 137 GrBatchAtlas* GrResourceProvider::createAtlas(GrPixelConfig config, |
131 int width, int height, | 138 int width, int height, |
132 int numPlotsX, int numPlotsY, | 139 int numPlotsX, int numPlotsY, |
133 GrBatchAtlas::EvictionFunc func, v
oid* data) { | 140 GrBatchAtlas::EvictionFunc func, v
oid* data) { |
134 GrSurfaceDesc desc; | 141 GrSurfaceDesc desc; |
135 desc.fFlags = kNone_GrSurfaceFlags; | 142 desc.fFlags = kNone_GrSurfaceFlags; |
136 desc.fWidth = width; | 143 desc.fWidth = width; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 return rt->renderTargetPriv().getStencilAttachment(); | 204 return rt->renderTargetPriv().getStencilAttachment(); |
198 } | 205 } |
199 | 206 |
200 GrRenderTarget* GrResourceProvider::wrapBackendTextureAsRenderTarget( | 207 GrRenderTarget* GrResourceProvider::wrapBackendTextureAsRenderTarget( |
201 const GrBackendTextureDesc& desc) { | 208 const GrBackendTextureDesc& desc) { |
202 if (this->isAbandoned()) { | 209 if (this->isAbandoned()) { |
203 return nullptr; | 210 return nullptr; |
204 } | 211 } |
205 return this->gpu()->wrapBackendTextureAsRenderTarget(desc); | 212 return this->gpu()->wrapBackendTextureAsRenderTarget(desc); |
206 } | 213 } |
OLD | NEW |