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

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

Issue 1116943004: Move instanced index buffer creation to flush time (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix missing assignment of keys to index buffers 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/GrResourceProvider.h ('k') | src/gpu/effects/GrDashingEffect.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "GrResourceProvider.h"
9
10 #include "GrGpu.h"
11 #include "GrResourceCache.h"
12 #include "GrResourceKey.h"
13 #include "GrVertexBuffer.h"
14
15 GR_DECLARE_STATIC_UNIQUE_KEY(gQuadIndexBufferKey);
16
17 GrResourceProvider::GrResourceProvider(GrGpu* gpu, GrResourceCache* cache) : INH ERITED(gpu, cache) {
18 GR_DEFINE_STATIC_UNIQUE_KEY(gQuadIndexBufferKey);
19 fQuadIndexBufferKey = gQuadIndexBufferKey;
20 }
21
22 const GrIndexBuffer* GrResourceProvider::createInstancedIndexBuffer(const uint16 _t* pattern,
23 int patternS ize,
24 int reps,
25 int vertCoun t,
26 const GrUniq ueKey& key) {
27 size_t bufferSize = patternSize * reps * sizeof(uint16_t);
28
29 GrIndexBuffer* buffer = this->gpu()->createIndexBuffer(bufferSize, /* dynami c = */ false);
30 if (!buffer) {
31 return NULL;
32 }
33 uint16_t* data = (uint16_t*) buffer->map();
34 bool useTempData = (NULL == data);
35 if (useTempData) {
36 data = SkNEW_ARRAY(uint16_t, reps * patternSize);
37 }
38 for (int i = 0; i < reps; ++i) {
39 int baseIdx = i * patternSize;
40 uint16_t baseVert = (uint16_t)(i * vertCount);
41 for (int j = 0; j < patternSize; ++j) {
42 data[baseIdx+j] = baseVert + pattern[j];
43 }
44 }
45 if (useTempData) {
46 if (!buffer->updateData(data, bufferSize)) {
47 buffer->unref();
48 return NULL;
49 }
50 SkDELETE_ARRAY(data);
51 } else {
52 buffer->unmap();
53 }
54 this->assignUniqueKeyToResource(key, buffer);
55 return buffer;
56 }
57
58 const GrIndexBuffer* GrResourceProvider::createQuadIndexBuffer() {
59 static const int kMaxQuads = 1 << 12; // max possible: (1 << 14) - 1;
60 GR_STATIC_ASSERT(4 * kMaxQuads <= 65535);
61 static const uint16_t kPattern[] = { 0, 1, 2, 0, 2, 3 };
62
63 return this->createInstancedIndexBuffer(kPattern, 6, kMaxQuads, 4, fQuadInde xBufferKey);
64 }
65
OLDNEW
« no previous file with comments | « src/gpu/GrResourceProvider.h ('k') | src/gpu/effects/GrDashingEffect.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698