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

Side by Side Diff: src/gpu/GrGpu.cpp

Issue 1126613003: Revert of Move instanced index buffer creation to flush time (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 7 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 | « src/gpu/GrGpu.h ('k') | src/gpu/GrInOrderDrawBuffer.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 /* 2 /*
3 * Copyright 2010 Google Inc. 3 * Copyright 2010 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "GrGpu.h" 10 #include "GrGpu.h"
11 11
12 #include "GrBufferAllocPool.h" 12 #include "GrBufferAllocPool.h"
13 #include "GrContext.h" 13 #include "GrContext.h"
14 #include "GrDrawTargetCaps.h" 14 #include "GrDrawTargetCaps.h"
15 #include "GrGpuResourcePriv.h" 15 #include "GrGpuResourcePriv.h"
16 #include "GrIndexBuffer.h" 16 #include "GrIndexBuffer.h"
17 #include "GrResourceCache.h" 17 #include "GrResourceCache.h"
18 #include "GrRenderTargetPriv.h" 18 #include "GrRenderTargetPriv.h"
19 #include "GrStencilAttachment.h" 19 #include "GrStencilAttachment.h"
20 #include "GrVertexBuffer.h" 20 #include "GrVertexBuffer.h"
21 21
22 //////////////////////////////////////////////////////////////////////////////// 22 ////////////////////////////////////////////////////////////////////////////////
23 23
24 GrGpu::GrGpu(GrContext* context) 24 GrGpu::GrGpu(GrContext* context)
25 : fResetTimestamp(kExpiredTimestamp+1) 25 : fResetTimestamp(kExpiredTimestamp+1)
26 , fResetBits(kAll_GrBackendState) 26 , fResetBits(kAll_GrBackendState)
27 , fQuadIndexBuffer(NULL)
27 , fGpuTraceMarkerCount(0) 28 , fGpuTraceMarkerCount(0)
28 , fContext(context) { 29 , fContext(context) {
29 } 30 }
30 31
31 GrGpu::~GrGpu() {} 32 GrGpu::~GrGpu() {
33 SkSafeSetNull(fQuadIndexBuffer);
34 }
32 35
33 void GrGpu::contextAbandoned() {} 36 void GrGpu::contextAbandoned() {}
34 37
35 //////////////////////////////////////////////////////////////////////////////// 38 ////////////////////////////////////////////////////////////////////////////////
36 39
37 static GrSurfaceOrigin resolve_origin(GrSurfaceOrigin origin, bool renderTarget) { 40 static GrSurfaceOrigin resolve_origin(GrSurfaceOrigin origin, bool renderTarget) {
38 // By default, GrRenderTargets are GL's normal orientation so that they 41 // By default, GrRenderTargets are GL's normal orientation so that they
39 // can be drawn to by the outside world without the client having 42 // can be drawn to by the outside world without the client having
40 // to render upside down. 43 // to render upside down.
41 if (kDefault_GrSurfaceOrigin == origin) { 44 if (kDefault_GrSurfaceOrigin == origin) {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 GrVertexBuffer* GrGpu::createVertexBuffer(size_t size, bool dynamic) { 177 GrVertexBuffer* GrGpu::createVertexBuffer(size_t size, bool dynamic) {
175 this->handleDirtyContext(); 178 this->handleDirtyContext();
176 return this->onCreateVertexBuffer(size, dynamic); 179 return this->onCreateVertexBuffer(size, dynamic);
177 } 180 }
178 181
179 GrIndexBuffer* GrGpu::createIndexBuffer(size_t size, bool dynamic) { 182 GrIndexBuffer* GrGpu::createIndexBuffer(size_t size, bool dynamic) {
180 this->handleDirtyContext(); 183 this->handleDirtyContext();
181 return this->onCreateIndexBuffer(size, dynamic); 184 return this->onCreateIndexBuffer(size, dynamic);
182 } 185 }
183 186
187 GrIndexBuffer* GrGpu::createInstancedIndexBuffer(const uint16_t* pattern,
188 int patternSize,
189 int reps,
190 int vertCount,
191 bool isDynamic) {
192 size_t bufferSize = patternSize * reps * sizeof(uint16_t);
193 GrGpu* me = const_cast<GrGpu*>(this);
194 GrIndexBuffer* buffer = me->createIndexBuffer(bufferSize, isDynamic);
195 if (buffer) {
196 uint16_t* data = (uint16_t*) buffer->map();
197 bool useTempData = (NULL == data);
198 if (useTempData) {
199 data = SkNEW_ARRAY(uint16_t, reps * patternSize);
200 }
201 for (int i = 0; i < reps; ++i) {
202 int baseIdx = i * patternSize;
203 uint16_t baseVert = (uint16_t)(i * vertCount);
204 for (int j = 0; j < patternSize; ++j) {
205 data[baseIdx+j] = baseVert + pattern[j];
206 }
207 }
208 if (useTempData) {
209 if (!buffer->updateData(data, bufferSize)) {
210 SkFAIL("Can't get indices into buffer!");
211 }
212 SkDELETE_ARRAY(data);
213 } else {
214 buffer->unmap();
215 }
216 }
217 return buffer;
218 }
219
184 void GrGpu::clear(const SkIRect* rect, 220 void GrGpu::clear(const SkIRect* rect,
185 GrColor color, 221 GrColor color,
186 bool canIgnoreRect, 222 bool canIgnoreRect,
187 GrRenderTarget* renderTarget) { 223 GrRenderTarget* renderTarget) {
188 SkASSERT(renderTarget); 224 SkASSERT(renderTarget);
189 this->handleDirtyContext(); 225 this->handleDirtyContext();
190 this->onClear(renderTarget, rect, color, canIgnoreRect); 226 this->onClear(renderTarget, rect, color, canIgnoreRect);
191 } 227 }
192 228
193 void GrGpu::clearStencilClip(const SkIRect& rect, 229 void GrGpu::clearStencilClip(const SkIRect& rect,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 void GrGpu::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { 297 void GrGpu::removeGpuTraceMarker(const GrGpuTraceMarker* marker) {
262 if (this->caps()->gpuTracingSupport()) { 298 if (this->caps()->gpuTracingSupport()) {
263 SkASSERT(fGpuTraceMarkerCount >= 1); 299 SkASSERT(fGpuTraceMarkerCount >= 1);
264 this->fActiveTraceMarkers.remove(*marker); 300 this->fActiveTraceMarkers.remove(*marker);
265 this->didRemoveGpuTraceMarker(); 301 this->didRemoveGpuTraceMarker();
266 --fGpuTraceMarkerCount; 302 --fGpuTraceMarkerCount;
267 } 303 }
268 } 304 }
269 305
270 //////////////////////////////////////////////////////////////////////////////// 306 ////////////////////////////////////////////////////////////////////////////////
307
308 static const int MAX_QUADS = 1 << 12; // max possible: (1 << 14) - 1;
309
310 GR_STATIC_ASSERT(4 * MAX_QUADS <= 65535);
311
312 static const uint16_t gQuadIndexPattern[] = {
313 0, 1, 2, 0, 2, 3
314 };
315
316 const GrIndexBuffer* GrGpu::getQuadIndexBuffer() const {
317 if (NULL == fQuadIndexBuffer || fQuadIndexBuffer->wasDestroyed()) {
318 SkSafeUnref(fQuadIndexBuffer);
319 GrGpu* me = const_cast<GrGpu*>(this);
320 fQuadIndexBuffer = me->createInstancedIndexBuffer(gQuadIndexPattern,
321 6,
322 MAX_QUADS,
323 4);
324 }
325
326 return fQuadIndexBuffer;
327 }
328
329 ////////////////////////////////////////////////////////////////////////////////
271 330
272 void GrGpu::draw(const DrawArgs& args, const GrDrawTarget::DrawInfo& info) { 331 void GrGpu::draw(const DrawArgs& args, const GrDrawTarget::DrawInfo& info) {
273 this->handleDirtyContext(); 332 this->handleDirtyContext();
274 this->onDraw(args, info); 333 this->onDraw(args, info);
275 } 334 }
276 335
277 void GrGpu::stencilPath(const GrPath* path, const StencilPathState& state) { 336 void GrGpu::stencilPath(const GrPath* path, const StencilPathState& state) {
278 this->handleDirtyContext(); 337 this->handleDirtyContext();
279 this->onStencilPath(path, state); 338 this->onStencilPath(path, state);
280 } 339 }
(...skipping 11 matching lines...) Expand all
292 GrDrawTarget::PathIndexType indexType, 351 GrDrawTarget::PathIndexType indexType,
293 const float transformValues[], 352 const float transformValues[],
294 GrDrawTarget::PathTransformType transformType, 353 GrDrawTarget::PathTransformType transformType,
295 int count, 354 int count,
296 const GrStencilSettings& stencilSettings) { 355 const GrStencilSettings& stencilSettings) {
297 this->handleDirtyContext(); 356 this->handleDirtyContext();
298 pathRange->willDrawPaths(indices, indexType, count); 357 pathRange->willDrawPaths(indices, indexType, count);
299 this->onDrawPaths(args, pathRange, indices, indexType, transformValues, 358 this->onDrawPaths(args, pathRange, indices, indexType, transformValues,
300 transformType, count, stencilSettings); 359 transformType, count, stencilSettings);
301 } 360 }
OLDNEW
« no previous file with comments | « src/gpu/GrGpu.h ('k') | src/gpu/GrInOrderDrawBuffer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698