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 "GrGpu.h" | 10 #include "GrGpu.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 fQuadIndexBufferKey = gQuadIndexBufferKey; | 21 fQuadIndexBufferKey = gQuadIndexBufferKey; |
22 } | 22 } |
23 | 23 |
24 const GrIndexBuffer* GrResourceProvider::createInstancedIndexBuffer(const uint16
_t* pattern, | 24 const GrIndexBuffer* GrResourceProvider::createInstancedIndexBuffer(const uint16
_t* pattern, |
25 int patternS
ize, | 25 int patternS
ize, |
26 int reps, | 26 int reps, |
27 int vertCoun
t, | 27 int vertCoun
t, |
28 const GrUniq
ueKey& key) { | 28 const GrUniq
ueKey& key) { |
29 size_t bufferSize = patternSize * reps * sizeof(uint16_t); | 29 size_t bufferSize = patternSize * reps * sizeof(uint16_t); |
30 | 30 |
31 GrIndexBuffer* buffer = this->getIndexBuffer(bufferSize, /* dynamic = */ fal
se, true); | 31 GrIndexBuffer* buffer = this->gpu()->createIndexBuffer(bufferSize, /* dynami
c = */ false); |
32 if (!buffer) { | 32 if (!buffer) { |
33 return NULL; | 33 return NULL; |
34 } | 34 } |
35 uint16_t* data = (uint16_t*) buffer->map(); | 35 uint16_t* data = (uint16_t*) buffer->map(); |
36 bool useTempData = (NULL == data); | 36 bool useTempData = (NULL == data); |
37 if (useTempData) { | 37 if (useTempData) { |
38 data = SkNEW_ARRAY(uint16_t, reps * patternSize); | 38 data = SkNEW_ARRAY(uint16_t, reps * patternSize); |
39 } | 39 } |
40 for (int i = 0; i < reps; ++i) { | 40 for (int i = 0; i < reps; ++i) { |
41 int baseIdx = i * patternSize; | 41 int baseIdx = i * patternSize; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 return this->gpu()->pathRendering()->createPathRange(gen, stroke); | 76 return this->gpu()->pathRendering()->createPathRange(gen, stroke); |
77 } | 77 } |
78 | 78 |
79 GrPathRange* GrResourceProvider::createGlyphs(const SkTypeface* tf, const SkDesc
riptor* desc, | 79 GrPathRange* GrResourceProvider::createGlyphs(const SkTypeface* tf, const SkDesc
riptor* desc, |
80 const GrStrokeInfo& stroke) { | 80 const GrStrokeInfo& stroke) { |
81 | 81 |
82 SkASSERT(this->gpu()->pathRendering()); | 82 SkASSERT(this->gpu()->pathRendering()); |
83 return this->gpu()->pathRendering()->createGlyphs(tf, desc, stroke); | 83 return this->gpu()->pathRendering()->createGlyphs(tf, desc, stroke); |
84 } | 84 } |
85 | 85 |
86 GrIndexBuffer* GrResourceProvider::getIndexBuffer(size_t size, bool dynamic, | |
87 bool calledDuringFlush) { | |
88 if (this->isAbandoned()) { | |
89 return NULL; | |
90 } | |
91 | |
92 if (dynamic) { | |
93 // bin by pow2 with a reasonable min | |
94 static const uint32_t MIN_SIZE = 1 << 12; | |
95 size = SkTMax(MIN_SIZE, GrNextPow2(SkToUInt(size))); | |
96 | |
97 GrScratchKey key; | |
98 GrIndexBuffer::ComputeScratchKey(size, dynamic, &key); | |
99 uint32_t scratchFlags = 0; | |
100 if (calledDuringFlush) { | |
101 scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag; | |
102 } else { | |
103 scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag; | |
104 } | |
105 GrGpuResource* resource = this->cache()->findAndRefScratchResource(key,
scratchFlags); | |
106 if (resource) { | |
107 return static_cast<GrIndexBuffer*>(resource); | |
108 } | |
109 } | |
110 | |
111 return this->gpu()->createIndexBuffer(size, dynamic); | |
112 } | |
113 | |
114 GrVertexBuffer* GrResourceProvider::getVertexBuffer(size_t size, bool dynamic, | |
115 bool calledDuringFlush) { | |
116 if (this->isAbandoned()) { | |
117 return NULL; | |
118 } | |
119 | |
120 if (dynamic) { | |
121 // bin by pow2 with a reasonable min | |
122 static const uint32_t MIN_SIZE = 1 << 15; | |
123 size = SkTMax(MIN_SIZE, GrNextPow2(SkToUInt(size))); | |
124 | |
125 GrScratchKey key; | |
126 GrVertexBuffer::ComputeScratchKey(size, dynamic, &key); | |
127 uint32_t scratchFlags = 0; | |
128 if (calledDuringFlush) { | |
129 scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag; | |
130 } else { | |
131 scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag; | |
132 } | |
133 GrGpuResource* resource = this->cache()->findAndRefScratchResource(key,
scratchFlags); | |
134 if (resource) { | |
135 return static_cast<GrVertexBuffer*>(resource); | |
136 } | |
137 } | |
138 | |
139 return this->gpu()->createVertexBuffer(size, dynamic); | |
140 } | |
OLD | NEW |