OLD | NEW |
| (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 return buffer; | |
55 } | |
56 | |
57 const GrIndexBuffer* GrResourceProvider::createQuadIndexBuffer() { | |
58 static const int kMaxQuads = 1 << 12; // max possible: (1 << 14) - 1; | |
59 GR_STATIC_ASSERT(4 * kMaxQuads <= 65535); | |
60 static const uint16_t kPattern[] = { 0, 1, 2, 0, 2, 3 }; | |
61 | |
62 return this->createInstancedIndexBuffer(kPattern, 6, kMaxQuads, 4, fQuadInde
xBufferKey); | |
63 } | |
64 | |
OLD | NEW |