| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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,
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 NULL; |
| 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; |
| 131 GrVertexBuffer::ComputeScratchKey(size, true, &key); | 131 GrVertexBuffer::ComputeScratchKey(size, true, &key); |
| 132 uint32_t scratchFlags = 0; | 132 uint32_t scratchFlags = 0; |
| 133 if (noPendingIO) { | 133 if (noPendingIO) { |
| 134 scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag; | 134 scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag; |
| 135 } else { | 135 } else { |
| 136 scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag; | 136 scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag; |
| 137 } | 137 } |
| 138 GrGpuResource* resource = this->cache()->findAndRefScratchResource(key,
scratchFlags); | 138 GrGpuResource* resource = this->cache()->findAndRefScratchResource(key,
size, scratchFlags); |
| 139 if (resource) { | 139 if (resource) { |
| 140 return static_cast<GrVertexBuffer*>(resource); | 140 return static_cast<GrVertexBuffer*>(resource); |
| 141 } | 141 } |
| 142 } | 142 } |
| 143 return this->gpu()->createVertexBuffer(size, dynamic); | 143 return this->gpu()->createVertexBuffer(size, dynamic); |
| 144 } | 144 } |
| 145 | 145 |
| 146 GrBatchAtlas* GrResourceProvider::createAtlas(GrPixelConfig config, | 146 GrBatchAtlas* GrResourceProvider::createAtlas(GrPixelConfig config, |
| 147 int width, int height, | 147 int width, int height, |
| 148 int numPlotsX, int numPlotsY, | 148 int numPlotsX, int numPlotsY, |
| 149 GrBatchAtlas::EvictionFunc func, v
oid* data) { | 149 GrBatchAtlas::EvictionFunc func, v
oid* data) { |
| 150 GrSurfaceDesc desc; | 150 GrSurfaceDesc desc; |
| 151 desc.fFlags = kNone_GrSurfaceFlags; | 151 desc.fFlags = kNone_GrSurfaceFlags; |
| 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 NULL; |
| 163 } | 163 } |
| 164 return SkNEW_ARGS(GrBatchAtlas, (texture, numPlotsX, numPlotsY)); | 164 return SkNEW_ARGS(GrBatchAtlas, (texture, numPlotsX, numPlotsY)); |
| 165 } | 165 } |
| OLD | NEW |