aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/text
diff options
context:
space:
mode:
authorGravatar Ben Wagner <bungeman@google.com>2016-11-08 14:13:39 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2016-11-08 19:48:16 +0000
commit594f9ed9c9cf0fcbbc2fa111b09d376014314315 (patch)
treee41486dee3f05d94cc3e64a04e2ac641f9e36b8b /src/gpu/text
parent08c896378ee2090f27d6ea782839701679dc68df (diff)
Smart pointers for GrBatchAtlas.
While navigating this code the ownership rules were found to not be entirely clear. This updates GrBatchAtlas:: fPlotArray and fTexture to be smart pointers and propagates some clarifying changes. Change-Id: I6ca67247575c2d7c4e7986c10b948201fe0080f1 Reviewed-on: https://skia-review.googlesource.com/4549 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Ben Wagner <bungeman@google.com>
Diffstat (limited to 'src/gpu/text')
-rw-r--r--src/gpu/text/GrBatchFontCache.cpp25
-rw-r--r--src/gpu/text/GrBatchFontCache.h4
2 files changed, 9 insertions, 20 deletions
diff --git a/src/gpu/text/GrBatchFontCache.cpp b/src/gpu/text/GrBatchFontCache.cpp
index 3e212cd171..baed514e38 100644
--- a/src/gpu/text/GrBatchFontCache.cpp
+++ b/src/gpu/text/GrBatchFontCache.cpp
@@ -24,11 +24,10 @@ bool GrBatchFontCache::initAtlas(GrMaskFormat format) {
int numPlotsX = fAtlasConfigs[index].numPlotsX();
int numPlotsY = fAtlasConfigs[index].numPlotsY();
- fAtlases[index] =
- fContext->resourceProvider()->createAtlas(config, width, height,
- numPlotsX, numPlotsY,
- &GrBatchFontCache::HandleEviction,
- (void*)this);
+ fAtlases[index] = fContext->resourceProvider()->makeAtlas(config, width, height,
+ numPlotsX, numPlotsY,
+ &GrBatchFontCache::HandleEviction,
+ (void*)this);
if (!fAtlases[index]) {
return false;
}
@@ -39,9 +38,6 @@ bool GrBatchFontCache::initAtlas(GrMaskFormat format) {
GrBatchFontCache::GrBatchFontCache(GrContext* context)
: fContext(context)
, fPreserveStrike(nullptr) {
- for (int i = 0; i < kMaskFormatCount; ++i) {
- fAtlases[i] = nullptr;
- }
// setup default atlas configs
fAtlasConfigs[kA8_GrMaskFormat].fWidth = 2048;
@@ -73,9 +69,6 @@ GrBatchFontCache::~GrBatchFontCache() {
(*iter).unref();
++iter;
}
- for (int i = 0; i < kMaskFormatCount; ++i) {
- delete fAtlases[i];
- }
}
void GrBatchFontCache::freeAll() {
@@ -87,7 +80,6 @@ void GrBatchFontCache::freeAll() {
}
fCache.rewind();
for (int i = 0; i < kMaskFormatCount; ++i) {
- delete fAtlases[i];
fAtlases[i] = nullptr;
}
}
@@ -130,13 +122,10 @@ void GrBatchFontCache::dump() const {
}
void GrBatchFontCache::setAtlasSizes_ForTesting(const GrBatchAtlasConfig configs[3]) {
- // delete any old atlases, this should be safe to do as long as we are not in the middle of a
- // flush
+ // Delete any old atlases.
+ // This should be safe to do as long as we are not in the middle of a flush.
for (int i = 0; i < kMaskFormatCount; i++) {
- if (fAtlases[i]) {
- delete fAtlases[i];
- fAtlases[i] = nullptr;
- }
+ fAtlases[i] = nullptr;
}
memcpy(fAtlasConfigs, configs, sizeof(fAtlasConfigs));
}
diff --git a/src/gpu/text/GrBatchFontCache.h b/src/gpu/text/GrBatchFontCache.h
index 9bb19f5274..d7503b1720 100644
--- a/src/gpu/text/GrBatchFontCache.h
+++ b/src/gpu/text/GrBatchFontCache.h
@@ -225,7 +225,7 @@ private:
GrBatchAtlas* getAtlas(GrMaskFormat format) const {
int atlasIndex = MaskFormatToAtlasIndex(format);
SkASSERT(fAtlases[atlasIndex]);
- return fAtlases[atlasIndex];
+ return fAtlases[atlasIndex].get();
}
static void HandleEviction(GrBatchAtlas::AtlasID, void*);
@@ -233,7 +233,7 @@ private:
using StrikeHash = SkTDynamicHash<GrBatchTextStrike, SkDescriptor>;
GrContext* fContext;
StrikeHash fCache;
- GrBatchAtlas* fAtlases[kMaskFormatCount];
+ std::unique_ptr<GrBatchAtlas> fAtlases[kMaskFormatCount];
GrBatchTextStrike* fPreserveStrike;
GrBatchAtlasConfig fAtlasConfigs[kMaskFormatCount];
};