Remove GrAALevel enum, use explicit sample count

Review URL: http://codereview.appspot.com/5600045/



git-svn-id: http://skia.googlecode.com/svn/trunk@3106 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrAtlas.cpp b/src/gpu/GrAtlas.cpp
index 17464ba..9553cf2 100644
--- a/src/gpu/GrAtlas.cpp
+++ b/src/gpu/GrAtlas.cpp
@@ -179,10 +179,10 @@
     if (NULL == fTexture[format]) {
         GrTextureDesc desc = {
             kDynamicUpdate_GrTextureFlagBit,
-            kNone_GrAALevel,
             GR_ATLAS_TEXTURE_WIDTH,
             GR_ATLAS_TEXTURE_HEIGHT,
-            maskformat2pixelconfig(format)
+            maskformat2pixelconfig(format),
+            {0} // samples
         };
         fTexture[format] = fGpu->createTexture(desc, NULL, 0);
         if (NULL == fTexture[format]) {
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 975f6d0..1e87cab 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -167,6 +167,7 @@
                             GrContext::TextureKey clientKey,
                             int width,
                             int height,
+                            int sampleCnt,
                             bool scratch,
                             uint32_t v[4]) {
     GR_STATIC_ASSERT(sizeof(GrContext::TextureKey) == sizeof(uint64_t));
@@ -178,7 +179,9 @@
     v[1] = (clientKey >> 32) & 0xffffffffUL;
     v[2] = width | (height << 16);
 
-    v[3] = 0;
+    v[3] = (sampleCnt << 24);
+    GrAssert(sampleCnt >= 0 && sampleCnt < 256);
+
     if (!gpu->getCaps().fNPOTTextureTileSupport) {
         bool isPow2 = GrIsPow2(width) && GrIsPow2(height);
 
@@ -227,7 +230,7 @@
         int height,
         const GrSamplerState* sampler) {
     uint32_t v[4];
-    gen_texture_key_values(fGpu, sampler, key, width, height, false, v);
+    gen_texture_key_values(fGpu, sampler, key, width, height, 0, false, v);
     GrResourceKey resourceKey(v);
     return TextureCacheEntry(fTextureCache->findAndLock(resourceKey,
                                             GrResourceCache::kNested_LockType));
@@ -238,7 +241,7 @@
                                  int height,
                                  const GrSamplerState* sampler) const {
     uint32_t v[4];
-    gen_texture_key_values(fGpu, sampler, key, width, height, false, v);
+    gen_texture_key_values(fGpu, sampler, key, width, height, 0, false, v);
     GrResourceKey resourceKey(v);
     return fTextureCache->hasKey(resourceKey);
 }
@@ -313,7 +316,8 @@
     TextureCacheEntry entry;
     uint32_t v[4];
     bool special = gen_texture_key_values(fGpu, sampler, key,
-                                          desc.fWidth, desc.fHeight, false, v);
+                                          desc.fWidth, desc.fHeight,
+                                          desc.fSampleCnt, false, v);
     GrResourceKey resourceKey(v);
 
     if (special) {
@@ -417,13 +421,12 @@
                                        uint32_t v[4]) {
     // Instead of a client-provided key of the texture contents
     // we create a key of from the descriptor.
-    GrContext::TextureKey descKey = desc.fAALevel |
-                                    (desc.fFlags << 8) |
+    GrContext::TextureKey descKey = (desc.fFlags << 8) |
                                     ((uint64_t) desc.fConfig << 32);
     // this code path isn't friendly to tiling with NPOT restricitons
     // We just pass ClampNoFilter()
     gen_texture_key_values(gpu, NULL, descKey, desc.fWidth,
-                           desc.fHeight, true, v);
+                           desc.fHeight, desc.fSampleCnt, true, v);
 }
 }
 
@@ -439,9 +442,6 @@
         desc.fHeight = GrMax(MIN_SIZE, GrNextPow2(desc.fHeight));
     }
 
-    uint32_t p0 = desc.fConfig;
-    uint32_t p1 = (desc.fAALevel << 16) | desc.fFlags;
-    
     GrResourceEntry* entry;
     int origWidth = desc.fWidth;
     int origHeight = desc.fHeight;
@@ -713,13 +713,15 @@
     if (PREFER_MSAA_OFFSCREEN_AA && fGpu->getCaps().fFSAASupport) {
         record->fDownsample = OffscreenRecord::kFSAA_Downsample;
         record->fScale = 1;
-        desc.fAALevel = kMed_GrAALevel;
+        // 16 samples matches what the skia sw rasterizer uses. (There is no
+        // accessible constant to reference from sw code).
+        desc.fSampleCnt = 16;
     } else {
         record->fDownsample = OffscreenRecord::k4x4SinglePass_Downsample;
         record->fScale = OFFSCREEN_SSAA_SCALE;
         // both downsample paths assume this
         GR_STATIC_ASSERT(4 == OFFSCREEN_SSAA_SCALE);
-        desc.fAALevel = kNone_GrAALevel;
+        desc.fSampleCnt = 0;
     }
     
     desc.fWidth *= record->fScale;
@@ -1547,10 +1549,10 @@
 
     const GrTextureDesc desc = {
         kNone_GrTextureFlags,
-        kNone_GrAALevel,
         bounds.fRight,
         bounds.fBottom,
-        kAlpha_8_GrPixelConfig
+        kAlpha_8_GrPixelConfig,
+        {0} // samples
     };
 
     tex->set(context, desc);
@@ -1844,9 +1846,9 @@
         // readTexturePixels as of yet (it calls this function).
         const GrTextureDesc desc = {
             kRenderTarget_GrTextureFlagBit,
-            kNone_GrAALevel,
             width, height,
-            config
+            config,
+            {0}, // samples
         };
 
         // When a full readback is faster than a partial we could always make
@@ -1964,7 +1966,7 @@
     }
 
     const GrTextureDesc desc = {
-        kNone_GrTextureFlags, kNone_GrAALevel, width, height, config
+        kNone_GrTextureFlags, width, height, config, {0}
     };
     GrAutoScratchTexture ast(this, desc);
     GrTexture* texture = ast.texture();
diff --git a/src/gpu/GrGpuGL.cpp b/src/gpu/GrGpuGL.cpp
index 83087f4..a4a49ac 100644
--- a/src/gpu/GrGpuGL.cpp
+++ b/src/gpu/GrGpuGL.cpp
@@ -373,12 +373,6 @@
 }
 
 void GrGpuGL::initFSAASupport() {
-    // TODO: Get rid of GrAALevel and use # samples directly.
-    GR_STATIC_ASSERT(0 == kNone_GrAALevel);
-    GR_STATIC_ASSERT(1 == kLow_GrAALevel);
-    GR_STATIC_ASSERT(2 == kMed_GrAALevel);
-    GR_STATIC_ASSERT(3 == kHigh_GrAALevel);
-    memset(fGLCaps.fAASamples, 0, sizeof(fGLCaps.fAASamples));
 
     fGLCaps.fMSFBOType = GLCaps::kNone_MSFBO;
     if (kDesktop_GrGLBinding != this->glBinding()) {
@@ -398,19 +392,7 @@
         }
     }
 
-    if (GLCaps::kNone_MSFBO != fGLCaps.fMSFBOType) {
-        GrGLint maxSamples;
-        GR_GL_GetIntegerv(fGL, GR_GL_MAX_SAMPLES, &maxSamples);
-        if (maxSamples > 1 ) {
-            fGLCaps.fAASamples[kNone_GrAALevel] = 0;
-            fGLCaps.fAASamples[kLow_GrAALevel] =
-                GrMax(2, GrFixedFloorToInt((GR_FixedHalf) * maxSamples));
-            fGLCaps.fAASamples[kMed_GrAALevel] =
-                GrMax(2, GrFixedFloorToInt(((GR_Fixed1*3)/4) * maxSamples));
-            fGLCaps.fAASamples[kHigh_GrAALevel] = maxSamples;
-        }
-    }
-    fCaps.fFSAASupport = fGLCaps.fAASamples[kHigh_GrAALevel] > 0;
+    fCaps.fFSAASupport = GLCaps::kNone_MSFBO != fGLCaps.fMSFBOType;
 }
 
 void GrGpuGL::initStencilFormats() {
@@ -982,10 +964,13 @@
     GrGLTexture::Desc glTexDesc;
     GrGLRenderTarget::Desc  glRTDesc;
 
+    // Attempt to catch un- or wrongly initialized sample counts;
+    GrAssert(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64);
+
     glTexDesc.fWidth  = desc.fWidth;
     glTexDesc.fHeight = desc.fHeight;
-    glTexDesc.fConfig        = desc.fConfig;
-    glTexDesc.fOwnsID        = true;
+    glTexDesc.fConfig = desc.fConfig;
+    glTexDesc.fOwnsID = true;
 
     glRTDesc.fMSColorRenderbufferID = 0;
     glRTDesc.fRTFBOID = 0;
@@ -1003,11 +988,10 @@
     glTexDesc.fOrientation = renderTarget ? GrGLTexture::kBottomUp_Orientation :
                                             GrGLTexture::kTopDown_Orientation;
 
-    GrAssert(as_size_t(desc.fAALevel) < GR_ARRAY_COUNT(fGLCaps.fAASamples));
-    glRTDesc.fSampleCnt = fGLCaps.fAASamples[desc.fAALevel];
+    glRTDesc.fSampleCnt = desc.fSampleCnt;
     if (GLCaps::kNone_MSFBO == fGLCaps.fMSFBOType &&
-        desc.fAALevel != kNone_GrAALevel) {
-        GrPrintf("AA RT requested but not supported on this platform.");
+        desc.fSampleCnt) {
+        GrPrintf("MSAA RT requested but not supported on this platform.");
     }
 
     if (renderTarget) {
@@ -2459,9 +2443,6 @@
         "Apple",
     };
     GrPrintf("MSAA Type: %s\n", gMSFBOExtStr[fMSFBOType]);
-    for (int i = 0; i < (int)GR_ARRAY_COUNT(fAASamples); ++i) {
-        GrPrintf("AA Level %d has %d samples\n", i, fAASamples[i]);
-    }
     GrPrintf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
     GrPrintf("Support RGBA8 Render Buffer: %s\n",
              (fRGBA8RenderbufferSupport ? "YES": "NO"));
diff --git a/src/gpu/GrGpuGL.h b/src/gpu/GrGpuGL.h
index 12b3771..3196c89 100644
--- a/src/gpu/GrGpuGL.h
+++ b/src/gpu/GrGpuGL.h
@@ -60,7 +60,6 @@
             , fPackFlipYSupport(false)
             , fTextureUsageSupport(false)
             , fTexStorageSupport(false) {
-            memset(fAASamples, 0, sizeof(fAASamples));
         }
         SkTArray<GrGLStencilBuffer::Format, true> fStencilFormats;
 
@@ -83,9 +82,6 @@
             kAppleES_MSFBO,
         } fMSFBOType;
 
-        // TODO: get rid of GrAALevel and use sample cnt directly
-        GrGLuint fAASamples[4];
-
         // The maximum number of fragment uniform vectors (GLES has min. 16).
         int fMaxFragmentUniformVectors;
 
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 5a34ef2..d34ef6a 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -216,10 +216,10 @@
 #else
     const GrTextureDesc desc = {
         kRenderTarget_GrTextureFlagBit,
-        kNone_GrAALevel,
         width,
         height,
-        SkGr::Bitmap2PixelConfig(bm)
+        SkGr::Bitmap2PixelConfig(bm),
+        {0} // samples
     };
 
     fTexture = fContext->createUncachedTexture(desc, NULL, 0);
@@ -765,10 +765,10 @@
 
     const GrTextureDesc desc = {
         kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit,
-        kNone_GrAALevel,
         srcRect.width(),
         srcRect.height(),
-        kRGBA_8888_GrPixelConfig
+        kRGBA_8888_GrPixelConfig,
+        {0} // samples 
     };
 
     temp1->set(context, desc);
@@ -900,12 +900,12 @@
     srcRect.offset(offset);
     const GrTextureDesc desc = {
         kRenderTarget_GrTextureFlagBit,
-        kNone_GrAALevel,
         srcRect.width(),
         srcRect.height(),
         // We actually only need A8, but it often isn't supported as a
         // render target
-        kRGBA_8888_PM_GrPixelConfig
+        kRGBA_8888_PM_GrPixelConfig,
+        {0} // samples
     };
 
     GrAutoScratchTexture pathEntry(context, desc);
@@ -1032,10 +1032,10 @@
 
     const GrTextureDesc desc = {
         kNone_GrTextureFlags,
-        kNone_GrAALevel,
         dstM.fBounds.width(),
         dstM.fBounds.height(),
-        kAlpha_8_GrPixelConfig
+        kAlpha_8_GrPixelConfig,
+        {0}, // samples
     };
 
     GrAutoScratchTexture ast(context, desc);
@@ -1783,10 +1783,10 @@
     if (kBitmap_TexType != type) {
         const GrTextureDesc desc = {
             kRenderTarget_GrTextureFlagBit,
-            kNone_GrAALevel,
             bitmap.width(),
             bitmap.height(),
-            SkGr::Bitmap2PixelConfig(bitmap)
+            SkGr::Bitmap2PixelConfig(bitmap),
+            {0} // samples
         };
         GrContext::ScratchTexMatch match;
         if (kSaveLayerDeviceRenderTarget_TexType == type) {
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index cab9d46..519475c 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -73,10 +73,10 @@
 
     GrTextureDesc desc = {
         kNone_GrTextureFlags,
-        kNone_GrAALevel,
         bitmap->width(),
         bitmap->height(),
-        SkGr::Bitmap2PixelConfig(*bitmap)
+        SkGr::Bitmap2PixelConfig(*bitmap),
+        {0} // samples
     };
 
     if (SkBitmap::kIndex8_Config == bitmap->config()) {
diff --git a/src/gpu/SkGrTexturePixelRef.cpp b/src/gpu/SkGrTexturePixelRef.cpp
index 4b546d6..c81e9c0 100644
--- a/src/gpu/SkGrTexturePixelRef.cpp
+++ b/src/gpu/SkGrTexturePixelRef.cpp
@@ -63,7 +63,7 @@
     desc.fHeight = texture->height();
     desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
     desc.fConfig = SkGr::BitmapConfig2PixelConfig(dstConfig, false);
-    desc.fAALevel = kNone_GrAALevel;
+    desc.fSampleCnt = 0;
 
     GrTexture* dst = context->createUncachedTexture(desc, NULL, 0);
     if (NULL == dst) {