fixes around isOpaque and dithering

- copyTo() now preserves isOpaqueness, and BitmapCopyTest tests it
- bitmap shader doesn't claim to have shadespan16 if dithering is on, since its
  sampler doesn't auto-dither (note that gradients do auto-dither in their
  16bit sampler)
- blitter setup just relies on the shader to report if its 16bit sampler can be
  called (allowing gradients to say yes regardless of dither, but bitmaps to say
  no if dithering is on)



git-svn-id: http://skia.googlecode.com/svn/trunk@331 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tests/BitmapCopyTest.cpp b/tests/BitmapCopyTest.cpp
index e54cde3..2ae7b0a 100644
--- a/tests/BitmapCopyTest.cpp
+++ b/tests/BitmapCopyTest.cpp
@@ -11,6 +11,57 @@
     "None", "A1", "A8", "Index8", "565", "4444", "8888", "RLE_Index8"
 };
 
+static void report_opaqueness(skiatest::Reporter* reporter, const SkBitmap& src,
+                              const SkBitmap& dst) {
+    SkString str;
+    str.printf("src %s opaque:%d, dst %s opaque:%d",
+               gConfigName[src.config()], src.isOpaque(),
+               gConfigName[dst.config()], dst.isOpaque());
+    reporter->reportFailed(str);
+}
+
+static bool canHaveAlpha(SkBitmap::Config config) {
+    return config != SkBitmap::kRGB_565_Config;
+}
+
+// copyTo() should preserve isOpaque when it makes sense
+static void test_isOpaque(skiatest::Reporter* reporter, const SkBitmap& src,
+                          SkBitmap::Config dstConfig) {
+    SkBitmap bitmap(src);
+    SkBitmap dst;
+
+    // we need the lock so that we get a valid colorTable (when available)
+    SkAutoLockPixels alp(bitmap);
+    SkColorTable* ctable = bitmap.getColorTable();
+    unsigned ctableFlags = ctable ? ctable->getFlags() : 0;
+
+    if (canHaveAlpha(bitmap.config()) && canHaveAlpha(dstConfig)) {
+        bitmap.setIsOpaque(false);
+        if (ctable) {
+            ctable->setFlags(ctableFlags & ~SkColorTable::kColorsAreOpaque_Flag);
+        }
+        REPORTER_ASSERT(reporter, bitmap.copyTo(&dst, dstConfig));
+        REPORTER_ASSERT(reporter, dst.config() == dstConfig);
+        if (bitmap.isOpaque() != dst.isOpaque()) {
+            report_opaqueness(reporter, bitmap, dst);
+        }
+    }
+
+    bitmap.setIsOpaque(true);
+    if (ctable) {
+        ctable->setFlags(ctableFlags | SkColorTable::kColorsAreOpaque_Flag);
+    }
+    REPORTER_ASSERT(reporter, bitmap.copyTo(&dst, dstConfig));
+    REPORTER_ASSERT(reporter, dst.config() == dstConfig);
+    if (bitmap.isOpaque() != dst.isOpaque()) {
+        report_opaqueness(reporter, bitmap, dst);
+    }
+
+    if (ctable) {
+        ctable->setFlags(ctableFlags);
+    }
+}
+
 static void init_src(const SkBitmap& bitmap) {
     SkAutoLockPixels lock(bitmap);
     if (bitmap.getPixels()) {
@@ -83,6 +134,7 @@
                 REPORTER_ASSERT(reporter, src.width() == dst.width());
                 REPORTER_ASSERT(reporter, src.height() == dst.height());
                 REPORTER_ASSERT(reporter, dst.config() == gPairs[j].fConfig);
+                test_isOpaque(reporter, src, dst.config());
                 if (src.config() == dst.config()) {
                     SkAutoLockPixels srcLock(src);
                     SkAutoLockPixels dstLock(dst);