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 14 matching lines...) Expand all Loading... |
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 // This is typically used in GrBatchs, so we assume kNoPendingIO. | 31 // This is typically used in GrBatchs, so we assume kNoPendingIO. |
32 GrIndexBuffer* buffer = this->createIndexBuffer(bufferSize, kStatic_BufferUs
age, | 32 GrIndexBuffer* buffer = this->createIndexBuffer(bufferSize, kStatic_BufferUs
age, |
33 kNoPendingIO_Flag); | 33 kNoPendingIO_Flag); |
34 if (!buffer) { | 34 if (!buffer) { |
35 return NULL; | 35 return nullptr; |
36 } | 36 } |
37 uint16_t* data = (uint16_t*) buffer->map(); | 37 uint16_t* data = (uint16_t*) buffer->map(); |
38 bool useTempData = (NULL == data); | 38 bool useTempData = (nullptr == data); |
39 if (useTempData) { | 39 if (useTempData) { |
40 data = new uint16_t[reps * patternSize]; | 40 data = new uint16_t[reps * patternSize]; |
41 } | 41 } |
42 for (int i = 0; i < reps; ++i) { | 42 for (int i = 0; i < reps; ++i) { |
43 int baseIdx = i * patternSize; | 43 int baseIdx = i * patternSize; |
44 uint16_t baseVert = (uint16_t)(i * vertCount); | 44 uint16_t baseVert = (uint16_t)(i * vertCount); |
45 for (int j = 0; j < patternSize; ++j) { | 45 for (int j = 0; j < patternSize; ++j) { |
46 data[baseIdx+j] = baseVert + pattern[j]; | 46 data[baseIdx+j] = baseVert + pattern[j]; |
47 } | 47 } |
48 } | 48 } |
49 if (useTempData) { | 49 if (useTempData) { |
50 if (!buffer->updateData(data, bufferSize)) { | 50 if (!buffer->updateData(data, bufferSize)) { |
51 buffer->unref(); | 51 buffer->unref(); |
52 return NULL; | 52 return nullptr; |
53 } | 53 } |
54 delete[] data; | 54 delete[] data; |
55 } else { | 55 } else { |
56 buffer->unmap(); | 56 buffer->unmap(); |
57 } | 57 } |
58 this->assignUniqueKeyToResource(key, buffer); | 58 this->assignUniqueKeyToResource(key, buffer); |
59 return buffer; | 59 return buffer; |
60 } | 60 } |
61 | 61 |
62 const GrIndexBuffer* GrResourceProvider::createQuadIndexBuffer() { | 62 const GrIndexBuffer* GrResourceProvider::createQuadIndexBuffer() { |
(...skipping 18 matching lines...) Expand all Loading... |
81 GrPathRange* GrResourceProvider::createGlyphs(const SkTypeface* tf, const SkDesc
riptor* desc, | 81 GrPathRange* GrResourceProvider::createGlyphs(const SkTypeface* tf, const SkDesc
riptor* desc, |
82 const GrStrokeInfo& stroke) { | 82 const GrStrokeInfo& stroke) { |
83 | 83 |
84 SkASSERT(this->gpu()->pathRendering()); | 84 SkASSERT(this->gpu()->pathRendering()); |
85 return this->gpu()->pathRendering()->createGlyphs(tf, desc, stroke); | 85 return this->gpu()->pathRendering()->createGlyphs(tf, desc, stroke); |
86 } | 86 } |
87 | 87 |
88 GrIndexBuffer* GrResourceProvider::createIndexBuffer(size_t size, BufferUsage us
age, | 88 GrIndexBuffer* GrResourceProvider::createIndexBuffer(size_t size, BufferUsage us
age, |
89 uint32_t flags) { | 89 uint32_t flags) { |
90 if (this->isAbandoned()) { | 90 if (this->isAbandoned()) { |
91 return NULL; | 91 return nullptr; |
92 } | 92 } |
93 | 93 |
94 bool noPendingIO = SkToBool(flags & kNoPendingIO_Flag); | 94 bool noPendingIO = SkToBool(flags & kNoPendingIO_Flag); |
95 bool dynamic = kDynamic_BufferUsage == usage; | 95 bool dynamic = kDynamic_BufferUsage == usage; |
96 if (dynamic) { | 96 if (dynamic) { |
97 // bin by pow2 with a reasonable min | 97 // bin by pow2 with a reasonable min |
98 static const uint32_t MIN_SIZE = 1 << 12; | 98 static const uint32_t MIN_SIZE = 1 << 12; |
99 size = SkTMax(MIN_SIZE, GrNextPow2(SkToUInt(size))); | 99 size = SkTMax(MIN_SIZE, GrNextPow2(SkToUInt(size))); |
100 | 100 |
101 GrScratchKey key; | 101 GrScratchKey key; |
102 GrIndexBuffer::ComputeScratchKey(size, true, &key); | 102 GrIndexBuffer::ComputeScratchKey(size, true, &key); |
103 uint32_t scratchFlags = 0; | 103 uint32_t scratchFlags = 0; |
104 if (noPendingIO) { | 104 if (noPendingIO) { |
105 scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag; | 105 scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag; |
106 } else { | 106 } else { |
107 scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag; | 107 scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag; |
108 } | 108 } |
109 GrGpuResource* resource = this->cache()->findAndRefScratchResource(key,
size, scratchFlags); | 109 GrGpuResource* resource = this->cache()->findAndRefScratchResource(key,
size, scratchFlags); |
110 if (resource) { | 110 if (resource) { |
111 return static_cast<GrIndexBuffer*>(resource); | 111 return static_cast<GrIndexBuffer*>(resource); |
112 } | 112 } |
113 } | 113 } |
114 return this->gpu()->createIndexBuffer(size, dynamic); | 114 return this->gpu()->createIndexBuffer(size, dynamic); |
115 } | 115 } |
116 | 116 |
117 GrVertexBuffer* GrResourceProvider::createVertexBuffer(size_t size, BufferUsage
usage, | 117 GrVertexBuffer* GrResourceProvider::createVertexBuffer(size_t size, BufferUsage
usage, |
118 uint32_t flags) { | 118 uint32_t flags) { |
119 if (this->isAbandoned()) { | 119 if (this->isAbandoned()) { |
120 return NULL; | 120 return nullptr; |
121 } | 121 } |
122 | 122 |
123 bool noPendingIO = SkToBool(flags & kNoPendingIO_Flag); | 123 bool noPendingIO = SkToBool(flags & kNoPendingIO_Flag); |
124 bool dynamic = kDynamic_BufferUsage == usage; | 124 bool dynamic = kDynamic_BufferUsage == usage; |
125 if (dynamic) { | 125 if (dynamic) { |
126 // bin by pow2 with a reasonable min | 126 // bin by pow2 with a reasonable min |
127 static const uint32_t MIN_SIZE = 1 << 12; | 127 static const uint32_t MIN_SIZE = 1 << 12; |
128 size = SkTMax(MIN_SIZE, GrNextPow2(SkToUInt(size))); | 128 size = SkTMax(MIN_SIZE, GrNextPow2(SkToUInt(size))); |
129 | 129 |
130 GrScratchKey key; | 130 GrScratchKey key; |
(...skipping 21 matching lines...) Expand all Loading... |
152 desc.fWidth = width; | 152 desc.fWidth = width; |
153 desc.fHeight = height; | 153 desc.fHeight = height; |
154 desc.fConfig = config; | 154 desc.fConfig = config; |
155 | 155 |
156 // We don't want to flush the context so we claim we're in the middle of flu
shing so as to | 156 // We don't want to flush the context so we claim we're in the middle of flu
shing so as to |
157 // guarantee we do not recieve a texture with pending IO | 157 // guarantee we do not recieve a texture with pending IO |
158 // TODO: Determine how to avoid having to do this. (http://skbug.com/4156) | 158 // TODO: Determine how to avoid having to do this. (http://skbug.com/4156) |
159 static const uint32_t kFlags = GrResourceProvider::kNoPendingIO_Flag; | 159 static const uint32_t kFlags = GrResourceProvider::kNoPendingIO_Flag; |
160 GrTexture* texture = this->createApproxTexture(desc, kFlags); | 160 GrTexture* texture = this->createApproxTexture(desc, kFlags); |
161 if (!texture) { | 161 if (!texture) { |
162 return NULL; | 162 return nullptr; |
163 } | 163 } |
164 return new GrBatchAtlas(texture, numPlotsX, numPlotsY); | 164 return new GrBatchAtlas(texture, numPlotsX, numPlotsY); |
165 } | 165 } |
OLD | NEW |