need a separate texture for each maskformat in atlasmgr
authorreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 15 Mar 2011 19:15:15 +0000 (19:15 +0000)
committerreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 15 Mar 2011 19:15:15 +0000 (19:15 +0000)
git-svn-id: http://skia.googlecode.com/svn/trunk@942 2bbb7eff-a529-9590-31e7-b0007b416f81

gpu/include/GrAtlas.h
gpu/include/GrTypes.h
gpu/src/GrAtlas.cpp

index 9fd2cab..a933842 100644 (file)
@@ -72,7 +72,10 @@ public:
     GrAtlas* addToAtlas(GrAtlas*, int width, int height, const void*,
                         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()
     void freePlot(int x, int y);
@@ -81,7 +84,7 @@ public:
 
 private:
     GrGpu*      fGpu;
-    GrTexture*  fTexture;
+    GrTexture*  fTexture[kCount_GrMaskFormats];
     GrPlotMgr*  fPlotMgr;
 };
 
index 8e219f7..cc78c3e 100644 (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 {
     kA8_GrMaskFormat,   //!< 1-byte per pixel
     kA565_GrMaskFormat  //!< 2-bytes per pixel
 };
+#define kCount_GrMaskFormats    2
 
 /**
  *  Return the number of bytes-per-pixel for the specified mask format.
index ea32719..ab99d9a 100644 (file)
@@ -54,7 +54,7 @@
 GrAtlas::GrAtlas(GrAtlasMgr* mgr, int plotX, int plotY, GrMaskFormat format) {
     fAtlasMgr = mgr;    // just a pointer, not an owner
     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);
 
     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) {
     fGpu = gpu;
     gpu->ref();
-    fTexture = NULL;
+    Gr_bzero(fTexture, sizeof(fTexture));
     fPlotMgr = new GrPlotMgr(GR_PLOT_WIDTH, GR_PLOT_HEIGHT);
 }
 
 GrAtlasMgr::~GrAtlasMgr() {
-    GrSafeUnref(fTexture);
+    for (size_t i = 0; i < GR_ARRAY_COUNT(fTexture); i++) {
+        GrSafeUnref(fTexture[i]);
+    }
     delete fPlotMgr;
     fGpu->unref();
 }
@@ -157,6 +159,7 @@ GrAtlas* GrAtlasMgr::addToAtlas(GrAtlas* atlas,
                                 GrMaskFormat format,
                                 GrIPoint16* loc) {
     GrAssert(NULL == atlas || atlas->getMaskFormat() == format);
+
     if (atlas && atlas->addSubImage(width, height, image, loc)) {
         return atlas;
     }
@@ -169,7 +172,9 @@ GrAtlas* GrAtlasMgr::addToAtlas(GrAtlas* atlas,
         return NULL;
     }
 
-    if (NULL == fTexture) {
+    GrAssert(0 == kA8_GrMaskFormat);
+    GrAssert(1 == kA565_GrMaskFormat);
+    if (NULL == fTexture[format]) {
         GrGpu::TextureDesc desc = {
             GrGpu::kDynamicUpdate_TextureFlag,
             GrGpu::kNone_AALevel,
@@ -177,8 +182,8 @@ GrAtlas* GrAtlasMgr::addToAtlas(GrAtlas* atlas,
             GR_ATLAS_TEXTURE_HEIGHT,
             maskformat2pixelconfig(format)
         };
-        fTexture = fGpu->createTexture(desc, NULL, 0);
-        if (NULL == fTexture) {
+        fTexture[format] = fGpu->createTexture(desc, NULL, 0);
+        if (NULL == fTexture[format]) {
             return NULL;
         }
     }