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 "GrBuffer.h" | 10 #include "GrBuffer.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 } | 25 } |
26 | 26 |
27 const GrBuffer* GrResourceProvider::createInstancedIndexBuffer(const uint16_t* p
attern, | 27 const GrBuffer* GrResourceProvider::createInstancedIndexBuffer(const uint16_t* p
attern, |
28 int patternSize, | 28 int patternSize, |
29 int reps, | 29 int reps, |
30 int vertCount, | 30 int vertCount, |
31 const GrUniqueKey
& key) { | 31 const GrUniqueKey
& key) { |
32 size_t bufferSize = patternSize * reps * sizeof(uint16_t); | 32 size_t bufferSize = patternSize * reps * sizeof(uint16_t); |
33 | 33 |
34 // This is typically used in GrBatchs, so we assume kNoPendingIO. | 34 // This is typically used in GrBatchs, so we assume kNoPendingIO. |
35 GrBuffer* buffer = this->createBuffer(bufferSize, kIndex_GrBufferType, kStat
ic_GrAccessPattern, | 35 GrBuffer* buffer = this->createBuffer(kIndex_GrBufferType, bufferSize, kStat
ic_GrAccessPattern, |
36 kNoPendingIO_Flag); | 36 kNoPendingIO_Flag); |
37 if (!buffer) { | 37 if (!buffer) { |
38 return nullptr; | 38 return nullptr; |
39 } | 39 } |
40 uint16_t* data = (uint16_t*) buffer->map(); | 40 uint16_t* data = (uint16_t*) buffer->map(); |
41 bool useTempData = (nullptr == data); | 41 bool useTempData = (nullptr == data); |
42 if (useTempData) { | 42 if (useTempData) { |
43 data = new uint16_t[reps * patternSize]; | 43 data = new uint16_t[reps * patternSize]; |
44 } | 44 } |
45 for (int i = 0; i < reps; ++i) { | 45 for (int i = 0; i < reps; ++i) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 return this->gpu()->pathRendering()->createPathRange(gen, stroke); | 81 return this->gpu()->pathRendering()->createPathRange(gen, stroke); |
82 } | 82 } |
83 | 83 |
84 GrPathRange* GrResourceProvider::createGlyphs(const SkTypeface* tf, const SkDesc
riptor* desc, | 84 GrPathRange* GrResourceProvider::createGlyphs(const SkTypeface* tf, const SkDesc
riptor* desc, |
85 const GrStrokeInfo& stroke) { | 85 const GrStrokeInfo& stroke) { |
86 | 86 |
87 SkASSERT(this->gpu()->pathRendering()); | 87 SkASSERT(this->gpu()->pathRendering()); |
88 return this->gpu()->pathRendering()->createGlyphs(tf, desc, stroke); | 88 return this->gpu()->pathRendering()->createGlyphs(tf, desc, stroke); |
89 } | 89 } |
90 | 90 |
91 GrBuffer* GrResourceProvider::createBuffer(size_t size, GrBufferType intendedTyp
e, | 91 GrBuffer* GrResourceProvider::createBuffer(GrBufferType type, size_t size, |
92 GrAccessPattern accessPattern, uint32
_t flags) { | 92 GrAccessPattern accessPattern, uint32
_t flags) { |
93 if (this->isAbandoned()) { | 93 if (this->isAbandoned()) { |
94 return nullptr; | 94 return nullptr; |
95 } | 95 } |
96 | 96 |
97 if (kDynamic_GrAccessPattern == accessPattern) { | 97 if (kDynamic_GrAccessPattern == accessPattern) { |
98 // bin by pow2 with a reasonable min | 98 // bin by pow2 with a reasonable min |
99 static const uint32_t MIN_SIZE = 1 << 12; | 99 static const uint32_t MIN_SIZE = 1 << 12; |
100 size = SkTMax(MIN_SIZE, GrNextPow2(SkToUInt(size))); | 100 size = SkTMax(MIN_SIZE, GrNextPow2(SkToUInt(size))); |
101 | 101 |
102 GrScratchKey key; | 102 GrScratchKey key; |
103 GrBuffer::ComputeScratchKeyForDynamicBuffer(size, intendedType, &key); | 103 GrBuffer::ComputeScratchKeyForDynamicBuffer(type, size, &key); |
104 uint32_t scratchFlags = 0; | 104 uint32_t scratchFlags = 0; |
105 if (flags & kNoPendingIO_Flag) { | 105 if (flags & kNoPendingIO_Flag) { |
106 scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag; | 106 scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag; |
107 } else { | 107 } else { |
108 scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag; | 108 scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag; |
109 } | 109 } |
110 GrGpuResource* resource = this->cache()->findAndRefScratchResource(key,
size, scratchFlags); | 110 GrGpuResource* resource = this->cache()->findAndRefScratchResource(key,
size, scratchFlags); |
111 if (resource) { | 111 if (resource) { |
112 return static_cast<GrBuffer*>(resource); | 112 return static_cast<GrBuffer*>(resource); |
113 } | 113 } |
114 } | 114 } |
115 return this->gpu()->createBuffer(size, intendedType, accessPattern); | 115 return this->gpu()->createBuffer(type, size, accessPattern); |
116 } | 116 } |
117 | 117 |
118 GrBatchAtlas* GrResourceProvider::createAtlas(GrPixelConfig config, | 118 GrBatchAtlas* GrResourceProvider::createAtlas(GrPixelConfig config, |
119 int width, int height, | 119 int width, int height, |
120 int numPlotsX, int numPlotsY, | 120 int numPlotsX, int numPlotsY, |
121 GrBatchAtlas::EvictionFunc func, v
oid* data) { | 121 GrBatchAtlas::EvictionFunc func, v
oid* data) { |
122 GrSurfaceDesc desc; | 122 GrSurfaceDesc desc; |
123 desc.fFlags = kNone_GrSurfaceFlags; | 123 desc.fFlags = kNone_GrSurfaceFlags; |
124 desc.fWidth = width; | 124 desc.fWidth = width; |
125 desc.fHeight = height; | 125 desc.fHeight = height; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 return rt->renderTargetPriv().getStencilAttachment(); | 185 return rt->renderTargetPriv().getStencilAttachment(); |
186 } | 186 } |
187 | 187 |
188 GrRenderTarget* GrResourceProvider::wrapBackendTextureAsRenderTarget( | 188 GrRenderTarget* GrResourceProvider::wrapBackendTextureAsRenderTarget( |
189 const GrBackendTextureDesc& desc) { | 189 const GrBackendTextureDesc& desc) { |
190 if (this->isAbandoned()) { | 190 if (this->isAbandoned()) { |
191 return nullptr; | 191 return nullptr; |
192 } | 192 } |
193 return this->gpu()->wrapBackendTextureAsRenderTarget(desc); | 193 return this->gpu()->wrapBackendTextureAsRenderTarget(desc); |
194 } | 194 } |
OLD | NEW |