need a separate texture for each maskformat in atlasmgr

git-svn-id: http://skia.googlecode.com/svn/trunk@942 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2011-03-15 19:15:15 +00:00
parent 080773ca79
commit 759c16e20d
3 changed files with 19 additions and 9 deletions

View File

@ -72,7 +72,10 @@ public:
GrAtlas* addToAtlas(GrAtlas*, int width, int height, const void*, GrAtlas* addToAtlas(GrAtlas*, int width, int height, const void*,
GrMaskFormat, GrIPoint16*); GrMaskFormat, GrIPoint16*);
GrTexture* getTexture() const { return fTexture; } GrTexture* getTexture(GrMaskFormat format) const {
GrAssert((unsigned)format < kCount_GrMaskFormats);
return fTexture[format];
}
// to be called by ~GrAtlas() // to be called by ~GrAtlas()
void freePlot(int x, int y); void freePlot(int x, int y);
@ -81,7 +84,7 @@ public:
private: private:
GrGpu* fGpu; GrGpu* fGpu;
GrTexture* fTexture; GrTexture* fTexture[kCount_GrMaskFormats];
GrPlotMgr* fPlotMgr; GrPlotMgr* fPlotMgr;
}; };

View File

@ -195,12 +195,14 @@ enum GrBlendCoeff {
}; };
/** /**
* Formats for masks, used by the font cache * Formats for masks, used by the font cache.
* Important that these are 0-based.
*/ */
enum GrMaskFormat { enum GrMaskFormat {
kA8_GrMaskFormat, //!< 1-byte per pixel kA8_GrMaskFormat, //!< 1-byte per pixel
kA565_GrMaskFormat //!< 2-bytes per pixel kA565_GrMaskFormat //!< 2-bytes per pixel
}; };
#define kCount_GrMaskFormats 2
/** /**
* Return the number of bytes-per-pixel for the specified mask format. * Return the number of bytes-per-pixel for the specified mask format.

View File

@ -54,7 +54,7 @@
GrAtlas::GrAtlas(GrAtlasMgr* mgr, int plotX, int plotY, GrMaskFormat format) { GrAtlas::GrAtlas(GrAtlasMgr* mgr, int plotX, int plotY, GrMaskFormat format) {
fAtlasMgr = mgr; // just a pointer, not an owner fAtlasMgr = mgr; // just a pointer, not an owner
fNext = NULL; fNext = NULL;
fTexture = mgr->getTexture(); // we're not an owner, just a pointer fTexture = mgr->getTexture(format); // we're not an owner, just a pointer
fPlot.set(plotX, plotY); fPlot.set(plotX, plotY);
fRects = GrRectanizer::Factory(GR_ATLAS_WIDTH - BORDER, fRects = GrRectanizer::Factory(GR_ATLAS_WIDTH - BORDER,
@ -130,12 +130,14 @@ bool GrAtlas::addSubImage(int width, int height, const void* image,
GrAtlasMgr::GrAtlasMgr(GrGpu* gpu) { GrAtlasMgr::GrAtlasMgr(GrGpu* gpu) {
fGpu = gpu; fGpu = gpu;
gpu->ref(); gpu->ref();
fTexture = NULL; Gr_bzero(fTexture, sizeof(fTexture));
fPlotMgr = new GrPlotMgr(GR_PLOT_WIDTH, GR_PLOT_HEIGHT); fPlotMgr = new GrPlotMgr(GR_PLOT_WIDTH, GR_PLOT_HEIGHT);
} }
GrAtlasMgr::~GrAtlasMgr() { GrAtlasMgr::~GrAtlasMgr() {
GrSafeUnref(fTexture); for (size_t i = 0; i < GR_ARRAY_COUNT(fTexture); i++) {
GrSafeUnref(fTexture[i]);
}
delete fPlotMgr; delete fPlotMgr;
fGpu->unref(); fGpu->unref();
} }
@ -157,6 +159,7 @@ GrAtlas* GrAtlasMgr::addToAtlas(GrAtlas* atlas,
GrMaskFormat format, GrMaskFormat format,
GrIPoint16* loc) { GrIPoint16* loc) {
GrAssert(NULL == atlas || atlas->getMaskFormat() == format); GrAssert(NULL == atlas || atlas->getMaskFormat() == format);
if (atlas && atlas->addSubImage(width, height, image, loc)) { if (atlas && atlas->addSubImage(width, height, image, loc)) {
return atlas; return atlas;
} }
@ -169,7 +172,9 @@ GrAtlas* GrAtlasMgr::addToAtlas(GrAtlas* atlas,
return NULL; return NULL;
} }
if (NULL == fTexture) { GrAssert(0 == kA8_GrMaskFormat);
GrAssert(1 == kA565_GrMaskFormat);
if (NULL == fTexture[format]) {
GrGpu::TextureDesc desc = { GrGpu::TextureDesc desc = {
GrGpu::kDynamicUpdate_TextureFlag, GrGpu::kDynamicUpdate_TextureFlag,
GrGpu::kNone_AALevel, GrGpu::kNone_AALevel,
@ -177,8 +182,8 @@ GrAtlas* GrAtlasMgr::addToAtlas(GrAtlas* atlas,
GR_ATLAS_TEXTURE_HEIGHT, GR_ATLAS_TEXTURE_HEIGHT,
maskformat2pixelconfig(format) maskformat2pixelconfig(format)
}; };
fTexture = fGpu->createTexture(desc, NULL, 0); fTexture[format] = fGpu->createTexture(desc, NULL, 0);
if (NULL == fTexture) { if (NULL == fTexture[format]) {
return NULL; return NULL;
} }
} }