Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: src/gpu/GrResourceProvider.cpp

Issue 1129863008: Revert of Refactor GrBufferAllocPools to use resource cache (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrResourceProvider.h ('k') | src/gpu/GrVertexBuffer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "GrResourceCache.h" 11 #include "GrResourceCache.h"
12 #include "GrResourceKey.h" 12 #include "GrResourceKey.h"
13 #include "GrVertexBuffer.h" 13 #include "GrVertexBuffer.h"
14 14
15 GR_DECLARE_STATIC_UNIQUE_KEY(gQuadIndexBufferKey); 15 GR_DECLARE_STATIC_UNIQUE_KEY(gQuadIndexBufferKey);
16 16
17 GrResourceProvider::GrResourceProvider(GrGpu* gpu, GrResourceCache* cache) : INH ERITED(gpu, cache) { 17 GrResourceProvider::GrResourceProvider(GrGpu* gpu, GrResourceCache* cache) : INH ERITED(gpu, cache) {
18 GR_DEFINE_STATIC_UNIQUE_KEY(gQuadIndexBufferKey); 18 GR_DEFINE_STATIC_UNIQUE_KEY(gQuadIndexBufferKey);
19 fQuadIndexBufferKey = gQuadIndexBufferKey; 19 fQuadIndexBufferKey = gQuadIndexBufferKey;
20 } 20 }
21 21
22 const GrIndexBuffer* GrResourceProvider::createInstancedIndexBuffer(const uint16 _t* pattern, 22 const GrIndexBuffer* GrResourceProvider::createInstancedIndexBuffer(const uint16 _t* pattern,
23 int patternS ize, 23 int patternS ize,
24 int reps, 24 int reps,
25 int vertCoun t, 25 int vertCoun t,
26 const GrUniq ueKey& key) { 26 const GrUniq ueKey& key) {
27 size_t bufferSize = patternSize * reps * sizeof(uint16_t); 27 size_t bufferSize = patternSize * reps * sizeof(uint16_t);
28 28
29 GrIndexBuffer* buffer = this->getIndexBuffer(bufferSize, /* dynamic = */ fal se, true); 29 GrIndexBuffer* buffer = this->gpu()->createIndexBuffer(bufferSize, /* dynami c = */ false);
30 if (!buffer) { 30 if (!buffer) {
31 return NULL; 31 return NULL;
32 } 32 }
33 uint16_t* data = (uint16_t*) buffer->map(); 33 uint16_t* data = (uint16_t*) buffer->map();
34 bool useTempData = (NULL == data); 34 bool useTempData = (NULL == data);
35 if (useTempData) { 35 if (useTempData) {
36 data = SkNEW_ARRAY(uint16_t, reps * patternSize); 36 data = SkNEW_ARRAY(uint16_t, reps * patternSize);
37 } 37 }
38 for (int i = 0; i < reps; ++i) { 38 for (int i = 0; i < reps; ++i) {
39 int baseIdx = i * patternSize; 39 int baseIdx = i * patternSize;
(...skipping 16 matching lines...) Expand all
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::getIndexBuffer(size_t size, bool dynamic,
67 bool calledDuringFlush) {
68 if (this->isAbandoned()) {
69 return NULL;
70 }
71
72 if (dynamic) {
73 // bin by pow2 with a reasonable min
74 static const uint32_t MIN_SIZE = 1 << 12;
75 size = SkTMax(MIN_SIZE, GrNextPow2(SkToUInt(size)));
76
77 GrScratchKey key;
78 GrIndexBuffer::ComputeScratchKey(size, dynamic, &key);
79 uint32_t scratchFlags = 0;
80 if (calledDuringFlush) {
81 scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag;
82 } else {
83 scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag;
84 }
85 GrGpuResource* resource = this->cache()->findAndRefScratchResource(key, scratchFlags);
86 if (resource) {
87 return static_cast<GrIndexBuffer*>(resource);
88 }
89 }
90
91 return this->gpu()->createIndexBuffer(size, dynamic);
92 }
93
94 GrVertexBuffer* GrResourceProvider::getVertexBuffer(size_t size, bool dynamic,
95 bool calledDuringFlush) {
96 if (this->isAbandoned()) {
97 return NULL;
98 }
99
100 if (dynamic) {
101 // bin by pow2 with a reasonable min
102 static const uint32_t MIN_SIZE = 1 << 15;
103 size = SkTMax(MIN_SIZE, GrNextPow2(SkToUInt(size)));
104
105 GrScratchKey key;
106 GrVertexBuffer::ComputeScratchKey(size, dynamic, &key);
107 uint32_t scratchFlags = 0;
108 if (calledDuringFlush) {
109 scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag;
110 } else {
111 scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag;
112 }
113 GrGpuResource* resource = this->cache()->findAndRefScratchResource(key, scratchFlags);
114 if (resource) {
115 return static_cast<GrVertexBuffer*>(resource);
116 }
117 }
118
119 return this->gpu()->createVertexBuffer(size, dynamic);
120 }
OLDNEW
« no previous file with comments | « src/gpu/GrResourceProvider.h ('k') | src/gpu/GrVertexBuffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698