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 // This is typically used in GrBatchs, so we assume kNoPendingIO. |
| 32 GrIndexBuffer* buffer = this->createIndexBuffer(bufferSize, kStatic_BufferUs
age, |
| 33 kNoPendingIO_Flag); |
32 if (!buffer) { | 34 if (!buffer) { |
33 return NULL; | 35 return NULL; |
34 } | 36 } |
35 uint16_t* data = (uint16_t*) buffer->map(); | 37 uint16_t* data = (uint16_t*) buffer->map(); |
36 bool useTempData = (NULL == data); | 38 bool useTempData = (NULL == data); |
37 if (useTempData) { | 39 if (useTempData) { |
38 data = SkNEW_ARRAY(uint16_t, reps * patternSize); | 40 data = SkNEW_ARRAY(uint16_t, reps * patternSize); |
39 } | 41 } |
40 for (int i = 0; i < reps; ++i) { | 42 for (int i = 0; i < reps; ++i) { |
41 int baseIdx = i * patternSize; | 43 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); | 78 return this->gpu()->pathRendering()->createPathRange(gen, stroke); |
77 } | 79 } |
78 | 80 |
79 GrPathRange* GrResourceProvider::createGlyphs(const SkTypeface* tf, const SkDesc
riptor* desc, | 81 GrPathRange* GrResourceProvider::createGlyphs(const SkTypeface* tf, const SkDesc
riptor* desc, |
80 const GrStrokeInfo& stroke) { | 82 const GrStrokeInfo& stroke) { |
81 | 83 |
82 SkASSERT(this->gpu()->pathRendering()); | 84 SkASSERT(this->gpu()->pathRendering()); |
83 return this->gpu()->pathRendering()->createGlyphs(tf, desc, stroke); | 85 return this->gpu()->pathRendering()->createGlyphs(tf, desc, stroke); |
84 } | 86 } |
85 | 87 |
86 GrIndexBuffer* GrResourceProvider::getIndexBuffer(size_t size, bool dynamic, | 88 GrIndexBuffer* GrResourceProvider::createIndexBuffer(size_t size, BufferUsage us
age, |
87 bool calledDuringFlush) { | 89 uint32_t flags) { |
88 if (this->isAbandoned()) { | 90 if (this->isAbandoned()) { |
89 return NULL; | 91 return NULL; |
90 } | 92 } |
91 | 93 |
| 94 bool noPendingIO = SkToBool(flags & kNoPendingIO_Flag); |
| 95 bool dynamic = kDynamic_BufferUsage == usage; |
92 if (dynamic) { | 96 if (dynamic) { |
93 // bin by pow2 with a reasonable min | 97 // bin by pow2 with a reasonable min |
94 static const uint32_t MIN_SIZE = 1 << 12; | 98 static const uint32_t MIN_SIZE = 1 << 12; |
95 size = SkTMax(MIN_SIZE, GrNextPow2(SkToUInt(size))); | 99 size = SkTMax(MIN_SIZE, GrNextPow2(SkToUInt(size))); |
96 | 100 |
97 GrScratchKey key; | 101 GrScratchKey key; |
98 GrIndexBuffer::ComputeScratchKey(size, dynamic, &key); | 102 GrIndexBuffer::ComputeScratchKey(size, true, &key); |
99 uint32_t scratchFlags = 0; | 103 uint32_t scratchFlags = 0; |
100 if (calledDuringFlush) { | 104 if (noPendingIO) { |
101 scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag; | 105 scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag; |
102 } else { | 106 } else { |
103 scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag; | 107 scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag; |
104 } | 108 } |
105 GrGpuResource* resource = this->cache()->findAndRefScratchResource(key,
scratchFlags); | 109 GrGpuResource* resource = this->cache()->findAndRefScratchResource(key,
scratchFlags); |
106 if (resource) { | 110 if (resource) { |
107 return static_cast<GrIndexBuffer*>(resource); | 111 return static_cast<GrIndexBuffer*>(resource); |
108 } | 112 } |
109 } | 113 } |
110 | 114 return this->gpu()->createIndexBuffer(size, dynamic); |
111 return this->gpu()->createIndexBuffer(size, dynamic); | |
112 } | 115 } |
113 | 116 |
114 GrVertexBuffer* GrResourceProvider::getVertexBuffer(size_t size, bool dynamic, | 117 GrVertexBuffer* GrResourceProvider::createVertexBuffer(size_t size, BufferUsage
usage, |
115 bool calledDuringFlush) { | 118 uint32_t flags) { |
116 if (this->isAbandoned()) { | 119 if (this->isAbandoned()) { |
117 return NULL; | 120 return NULL; |
118 } | 121 } |
119 | 122 |
| 123 bool noPendingIO = SkToBool(flags & kNoPendingIO_Flag); |
| 124 bool dynamic = kDynamic_BufferUsage == usage; |
120 if (dynamic) { | 125 if (dynamic) { |
121 // bin by pow2 with a reasonable min | 126 // bin by pow2 with a reasonable min |
122 static const uint32_t MIN_SIZE = 1 << 15; | 127 static const uint32_t MIN_SIZE = 1 << 12; |
123 size = SkTMax(MIN_SIZE, GrNextPow2(SkToUInt(size))); | 128 size = SkTMax(MIN_SIZE, GrNextPow2(SkToUInt(size))); |
124 | 129 |
125 GrScratchKey key; | 130 GrScratchKey key; |
126 GrVertexBuffer::ComputeScratchKey(size, dynamic, &key); | 131 GrVertexBuffer::ComputeScratchKey(size, true, &key); |
127 uint32_t scratchFlags = 0; | 132 uint32_t scratchFlags = 0; |
128 if (calledDuringFlush) { | 133 if (noPendingIO) { |
129 scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag; | 134 scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag; |
130 } else { | 135 } else { |
131 scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag; | 136 scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag; |
132 } | 137 } |
133 GrGpuResource* resource = this->cache()->findAndRefScratchResource(key,
scratchFlags); | 138 GrGpuResource* resource = this->cache()->findAndRefScratchResource(key,
scratchFlags); |
134 if (resource) { | 139 if (resource) { |
135 return static_cast<GrVertexBuffer*>(resource); | 140 return static_cast<GrVertexBuffer*>(resource); |
136 } | 141 } |
137 } | 142 } |
138 | |
139 return this->gpu()->createVertexBuffer(size, dynamic); | 143 return this->gpu()->createVertexBuffer(size, dynamic); |
140 } | 144 } |
OLD | NEW |