From 952944144758dd3f9a8a010ec1d99cb4bd035ae4 Mon Sep 17 00:00:00 2001 From: "commit-bot@chromium.org" Date: Thu, 26 Sep 2013 15:28:40 +0000 Subject: [PATCH] GrAtlas refactor: Replace GrMaskFormat usage in GrAtlas with GrPixelConfig. This gets the font-specific GrMaskFormat out of GrAtlas and replaces it with more generic configs, allowing GrAtlas to be used for other things. R=robertphillips@google.com Author: jvanverth@google.com Review URL: https://chromiumcodereview.appspot.com/24751003 git-svn-id: http://skia.googlecode.com/svn/trunk@11474 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/gpu/GrAtlas.cpp | 40 +++++++++++++--------------------------- src/gpu/GrAtlas.h | 15 +++++++-------- src/gpu/GrTextStrike.cpp | 20 +++++++++++++++++--- src/gpu/GrTextStrike.h | 2 +- 4 files changed, 38 insertions(+), 39 deletions(-) diff --git a/src/gpu/GrAtlas.cpp b/src/gpu/GrAtlas.cpp index b3f2e34c40..29f2a54ed7 100644 --- a/src/gpu/GrAtlas.cpp +++ b/src/gpu/GrAtlas.cpp @@ -50,7 +50,7 @@ static int g_UploadCount = 0; #endif -GrAtlas::GrAtlas(GrAtlasMgr* mgr, int plotX, int plotY, GrMaskFormat format) : +GrAtlas::GrAtlas(GrAtlasMgr* mgr, int plotX, int plotY, int bpp) : fDrawToken(NULL, 0) { fAtlasMgr = mgr; // just a pointer, not an owner fNext = NULL; @@ -61,7 +61,7 @@ GrAtlas::GrAtlas(GrAtlasMgr* mgr, int plotX, int plotY, GrMaskFormat format) : fRects = GrRectanizer::Factory(GR_ATLAS_WIDTH - BORDER, GR_ATLAS_HEIGHT - BORDER); - fMaskFormat = format; + fBytesPerPixel = bpp; #ifdef SK_DEBUG // GrPrintf(" GrAtlas %p [%d %d] %d\n", this, plotX, plotY, gCounter); @@ -123,17 +123,16 @@ bool GrAtlas::addSubImage(int width, int height, const void* image, int dstW = width + 2*BORDER; int dstH = height + 2*BORDER; if (BORDER) { - const int bpp = GrMaskFormatBytesPerPixel(fMaskFormat); - const size_t dstRB = dstW * bpp; + const size_t dstRB = dstW * fBytesPerPixel; uint8_t* dst = (uint8_t*)storage.reset(dstH * dstRB); Gr_bzero(dst, dstRB); // zero top row dst += dstRB; for (int y = 0; y < height; y++) { - dst = zerofill(dst, bpp); // zero left edge - memcpy(dst, image, width * bpp); - dst += width * bpp; - dst = zerofill(dst, bpp); // zero right edge - image = (const void*)((const char*)image + width * bpp); + dst = zerofill(dst, fBytesPerPixel); // zero left edge + memcpy(dst, image, width * fBytesPerPixel); + dst += width * fBytesPerPixel; + dst = zerofill(dst, fBytesPerPixel); // zero right edge + image = (const void*)((const char*)image + width * fBytesPerPixel); } Gr_bzero(dst, dstRB); // zero bottom row image = storage.get(); @@ -161,9 +160,9 @@ bool GrAtlas::addSubImage(int width, int height, const void* image, /////////////////////////////////////////////////////////////////////////////// -GrAtlasMgr::GrAtlasMgr(GrGpu* gpu, GrMaskFormat format) { +GrAtlasMgr::GrAtlasMgr(GrGpu* gpu, GrPixelConfig config) { fGpu = gpu; - fMaskFormat = format; + fPixelConfig = config; gpu->ref(); fTexture = NULL; fPlotMgr = SkNEW_ARGS(GrPlotMgr, (GR_PLOT_WIDTH, GR_PLOT_HEIGHT)); @@ -179,20 +178,6 @@ GrAtlasMgr::~GrAtlasMgr() { #endif } -static GrPixelConfig maskformat2pixelconfig(GrMaskFormat format) { - switch (format) { - case kA8_GrMaskFormat: - return kAlpha_8_GrPixelConfig; - case kA565_GrMaskFormat: - return kRGB_565_GrPixelConfig; - case kA888_GrMaskFormat: - return kSkia8888_GrPixelConfig; - default: - SkDEBUGFAIL("unknown maskformat"); - } - return kUnknown_GrPixelConfig; -} - GrAtlas* GrAtlasMgr::addToAtlas(GrAtlas** atlas, int width, int height, const void* image, GrIPoint16* loc) { @@ -219,7 +204,7 @@ GrAtlas* GrAtlasMgr::addToAtlas(GrAtlas** atlas, desc.fFlags = kDynamicUpdate_GrTextureFlagBit; desc.fWidth = GR_ATLAS_TEXTURE_WIDTH; desc.fHeight = GR_ATLAS_TEXTURE_HEIGHT; - desc.fConfig = maskformat2pixelconfig(fMaskFormat); + desc.fConfig = fPixelConfig; fTexture = fGpu->createTexture(desc, NULL, 0); if (NULL == fTexture) { @@ -227,7 +212,8 @@ GrAtlas* GrAtlasMgr::addToAtlas(GrAtlas** atlas, } } - GrAtlas* newAtlas = SkNEW_ARGS(GrAtlas, (this, plot.fX, plot.fY, fMaskFormat)); + int bpp = GrBytesPerPixel(fPixelConfig); + GrAtlas* newAtlas = SkNEW_ARGS(GrAtlas, (this, plot.fX, plot.fY, bpp)); if (!newAtlas->addSubImage(width, height, image, loc)) { delete newAtlas; return NULL; diff --git a/src/gpu/GrAtlas.h b/src/gpu/GrAtlas.h index 3f9da8cb13..b2acaee8e2 100644 --- a/src/gpu/GrAtlas.h +++ b/src/gpu/GrAtlas.h @@ -23,7 +23,6 @@ class GrAtlas { public: int getPlotX() const { return fPlot.fX; } int getPlotY() const { return fPlot.fY; } - GrMaskFormat getMaskFormat() const { return fMaskFormat; } GrTexture* texture() const { return fTexture; } @@ -43,7 +42,7 @@ public: void setDrawToken(GrDrawTarget::DrawToken draw) { fDrawToken = draw; } private: - GrAtlas(GrAtlasMgr*, int plotX, int plotY, GrMaskFormat format); + GrAtlas(GrAtlasMgr*, int plotX, int plotY, int bpp); ~GrAtlas(); // does not try to delete the fNext field // for recycling @@ -55,7 +54,7 @@ private: GrRectanizer* fRects; GrAtlasMgr* fAtlasMgr; GrIPoint16 fPlot; - GrMaskFormat fMaskFormat; + int fBytesPerPixel; friend class GrAtlasMgr; }; @@ -64,7 +63,7 @@ class GrPlotMgr; class GrAtlasMgr { public: - GrAtlasMgr(GrGpu*, GrMaskFormat); + GrAtlasMgr(GrGpu*, GrPixelConfig); ~GrAtlasMgr(); GrAtlas* addToAtlas(GrAtlas**, int width, int height, const void*, GrIPoint16*); @@ -78,10 +77,10 @@ public: void freePlot(int x, int y); private: - GrGpu* fGpu; - GrMaskFormat fMaskFormat; - GrTexture* fTexture; - GrPlotMgr* fPlotMgr; + GrGpu* fGpu; + GrPixelConfig fPixelConfig; + GrTexture* fTexture; + GrPlotMgr* fPlotMgr; }; #endif diff --git a/src/gpu/GrTextStrike.cpp b/src/gpu/GrTextStrike.cpp index 5798e5f350..d1f1861abd 100644 --- a/src/gpu/GrTextStrike.cpp +++ b/src/gpu/GrTextStrike.cpp @@ -41,15 +41,29 @@ GrFontCache::~GrFontCache() { #endif } +static GrPixelConfig mask_format_to_pixel_config(GrMaskFormat format) { + switch (format) { + case kA8_GrMaskFormat: + return kAlpha_8_GrPixelConfig; + case kA565_GrMaskFormat: + return kRGB_565_GrPixelConfig; + case kA888_GrMaskFormat: + return kSkia8888_GrPixelConfig; + default: + SkDEBUGFAIL("unknown maskformat"); + } + return kUnknown_GrPixelConfig; +} + GrTextStrike* GrFontCache::generateStrike(GrFontScaler* scaler, const Key& key) { GrMaskFormat format = scaler->getMaskFormat(); + GrPixelConfig config = mask_format_to_pixel_config(format); if (NULL == fAtlasMgr[format]) { - fAtlasMgr[format] = SkNEW_ARGS(GrAtlasMgr, (fGpu, format)); + fAtlasMgr[format] = SkNEW_ARGS(GrAtlasMgr, (fGpu, config)); } GrTextStrike* strike = SkNEW_ARGS(GrTextStrike, - (this, scaler->getKey(), - scaler->getMaskFormat(), fAtlasMgr[format])); + (this, scaler->getKey(), format, fAtlasMgr[format])); fCache.insert(key, strike); if (fHead) { diff --git a/src/gpu/GrTextStrike.h b/src/gpu/GrTextStrike.h index 7771e4a07c..66bbb0d93c 100644 --- a/src/gpu/GrTextStrike.h +++ b/src/gpu/GrTextStrike.h @@ -65,7 +65,7 @@ private: GrAtlasMgr* fAtlasMgr; GrAtlas* fAtlas; // linklist - GrMaskFormat fMaskFormat; + GrMaskFormat fMaskFormat; GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler); // returns true if after the purge, the strike is empty