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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 } | 56 } |
57 | 57 |
58 const GrIndexBuffer* GrResourceProvider::createQuadIndexBuffer() { | 58 const GrIndexBuffer* GrResourceProvider::createQuadIndexBuffer() { |
59 static const int kMaxQuads = 1 << 12; // max possible: (1 << 14) - 1; | 59 static const int kMaxQuads = 1 << 12; // max possible: (1 << 14) - 1; |
60 GR_STATIC_ASSERT(4 * kMaxQuads <= 65535); | 60 GR_STATIC_ASSERT(4 * kMaxQuads <= 65535); |
61 static const uint16_t kPattern[] = { 0, 1, 2, 0, 2, 3 }; | 61 static const uint16_t kPattern[] = { 0, 1, 2, 0, 2, 3 }; |
62 | 62 |
63 return this->createInstancedIndexBuffer(kPattern, 6, kMaxQuads, 4, fQuadInde
xBufferKey); | 63 return this->createInstancedIndexBuffer(kPattern, 6, kMaxQuads, 4, fQuadInde
xBufferKey); |
64 } | 64 } |
65 | 65 |
| 66 GrIndexBuffer* GrResourceProvider::refScratchIndexBuffer(size_t size, bool dynam
ic, |
| 67 ScratchMatch match, |
| 68 bool calledDuringFlush)
{ |
| 69 if (this->isAbandoned()) { |
| 70 return NULL; |
| 71 } |
| 72 |
| 73 uint32_t flags = 0; |
| 74 if (kExact_ScratchMatch == match) { |
| 75 flags |= kExact_ScratchFlag; |
| 76 } |
| 77 if (calledDuringFlush) { |
| 78 flags |= kNoPendingIO_ScratchFlag; |
| 79 } |
| 80 return this->internalRefIndexBuffer(size, dynamic, flags); |
| 81 } |
| 82 |
| 83 GrIndexBuffer* GrResourceProvider::internalRefIndexBuffer(size_t size, bool dyna
mic, |
| 84 uint32_t flags) { |
| 85 SkASSERT(!this->isAbandoned()); |
| 86 |
| 87 if (!(kExact_ScratchFlag & flags)) { |
| 88 // bin by pow2 with a reasonable min |
| 89 static const size_t MIN_SIZE = 1 << 12; |
| 90 size = SkTMax(MIN_SIZE, GrNextPow2(size)); |
| 91 } |
| 92 |
| 93 GrScratchKey key; |
| 94 GrIndexBuffer::ComputeScratchKey(size, dynamic, &key); |
| 95 uint32_t scratchFlags = 0; |
| 96 if (kNoPendingIO_ScratchFlag & flags) { |
| 97 scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag; |
| 98 } else { |
| 99 // Prefer no pending IO in order to avoid flushes? |
| 100 scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag; |
| 101 } |
| 102 GrGpuResource* resource = this->cache()->findAndRefScratchResource(key, scra
tchFlags); |
| 103 if (resource) { |
| 104 return static_cast<GrIndexBuffer*>(resource); |
| 105 } |
| 106 |
| 107 if (!(kNoCreate_ScratchFlag & flags)) { |
| 108 return this->gpu()->createIndexBuffer(size, dynamic); |
| 109 } |
| 110 |
| 111 return NULL; |
| 112 } |
| 113 |
| 114 GrVertexBuffer* GrResourceProvider::refScratchVertBuffer(size_t size, bool dynam
ic, |
| 115 ScratchMatch match, |
| 116 bool calledDuringFlush)
{ |
| 117 if (this->isAbandoned()) { |
| 118 return NULL; |
| 119 } |
| 120 |
| 121 uint32_t flags = 0; |
| 122 if (kExact_ScratchMatch == match) { |
| 123 flags |= kExact_ScratchFlag; |
| 124 } |
| 125 if (calledDuringFlush) { |
| 126 flags |= kNoPendingIO_ScratchFlag; |
| 127 } |
| 128 return this->internalRefVertexBuffer(size, dynamic, flags); |
| 129 } |
| 130 |
| 131 GrVertexBuffer* GrResourceProvider::internalRefVertexBuffer(size_t size, bool dy
namic, |
| 132 uint32_t flags) { |
| 133 SkASSERT(!this->isAbandoned()); |
| 134 |
| 135 if (!(kExact_ScratchFlag & flags)) { |
| 136 // bin by pow2 with a reasonable min |
| 137 static const size_t MIN_SIZE = 1 << 15; |
| 138 size = SkTMax(MIN_SIZE, GrNextPow2(size)); |
| 139 } |
| 140 |
| 141 GrScratchKey key; |
| 142 GrVertexBuffer::ComputeScratchKey(size, dynamic, &key); |
| 143 uint32_t scratchFlags = 0; |
| 144 if (kNoPendingIO_ScratchFlag & flags) { |
| 145 scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag; |
| 146 } else { |
| 147 // Prefer no pending IO in order to avoid flushes? |
| 148 scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag; |
| 149 } |
| 150 GrGpuResource* resource = this->cache()->findAndRefScratchResource(key, scra
tchFlags); |
| 151 if (resource) { |
| 152 return static_cast<GrVertexBuffer*>(resource); |
| 153 } |
| 154 |
| 155 if (!(kNoCreate_ScratchFlag & flags)) { |
| 156 return this->gpu()->createVertexBuffer(size, dynamic); |
| 157 } |
| 158 |
| 159 return NULL; |
| 160 } |
OLD | NEW |