Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(365)

Unified Diff: tests/Index8Test.cpp

Issue 1495693003: Index8 GPU and CPU raster support. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: revert SkImageGenerator&SkImageCacherator changes. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/effects/GrIndex8toRGBEffect.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/Index8Test.cpp
diff --git a/tests/Index8Test.cpp b/tests/Index8Test.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..810cd81070cec67921209bd0768d8aa2afbe3def
--- /dev/null
+++ b/tests/Index8Test.cpp
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "GrContextFactory.h"
+#include "SkGr.h"
+#include "SkGrPriv.h"
+#include "SkConfig8888.h"
+#include "Test.h"
+
+#if SK_SUPPORT_GPU
+
+static void make_index8_bitmap(SkBitmap* result, int width, int height, int ccount, bool opaque) {
+ SkAutoMalloc storage(ccount * sizeof(SkPMColor));
+ SkPMColor* palette = static_cast<SkPMColor*>(storage.get());
+ for (int i = 0; i < ccount; ++i) {
+ palette[i] = SkPreMultiplyARGB(opaque ? 0xFF : i, 0xFF - i, i, 0xFF - i);
+ }
+ result->setInfo(SkImageInfo::Make(width, height, kIndex_8_SkColorType,
+ opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType));
+ SkAutoTUnref<SkColorTable> ctable(new SkColorTable(palette, ccount));
+ result->allocPixels(ctable);
+ for (int j = 0; j < height; ++j) {
+ uint8_t* scanline = result->getAddr8(0, j);
+ int c = (j * height);
+ for (int i = 0; i < width; ++i)
+ *scanline++ = ((c++) % ccount);
+ }
+ result->setImmutable();
+}
+
+static void compare_texture_with_bitmap(skiatest::Reporter* reporter, GrTexture* txa,
+ const SkBitmap& bm) {
+ SkAutoLockPixels alp(bm);
+ REPORTER_ASSERT(reporter, txa->width() == bm.width());
+ REPORTER_ASSERT(reporter, txa->height() == bm.height());
+ REPORTER_ASSERT(reporter, bm.colorType() == kN32_SkColorType);
+ SkAutoMalloc storage(bm.width() * bm.height() * sizeof(SkPMColor));
+ SkPMColor* pixels = static_cast<SkPMColor*>(storage.get());
+ REPORTER_ASSERT(reporter, txa->readPixels(0, 0, bm.width(), bm.height(), txa->config(),
+ pixels));
+
+ SkDstPixelInfo dstPI;
+ dstPI.fColorType = kN32_SkColorType;
+ dstPI.fAlphaType = bm.alphaType();
+ dstPI.fPixels = pixels;
+ dstPI.fRowBytes = bm.width() * sizeof(SkPMColor);
+
+ SkSrcPixelInfo srcPI;
+ memcpy(&srcPI, &dstPI, sizeof(SkSrcPixelInfo));
+ srcPI.fColorType = kRGBA_8888_SkColorType;
+
+ srcPI.convertPixelsTo(&dstPI, bm.width(), bm.height());
+
+ for (int j = 0; j < bm.height(); ++j) {
+ for (int i = 0; i < bm.width(); ++i) {
+ REPORTER_ASSERT(reporter, pixels[i + bm.width() * j] == *bm.getAddr32(i, j));
+ }
+ }
+}
+
+/*
+ * Test two different ways to upload Index8 bitmap to texture.
+ */
+DEF_GPUTEST(Index8_Texture_Upload, reporter, factory) {
+ GrContext* ctx = factory->get(GrContextFactory::kNative_GLContextType);
+ if (!ctx) {
+ REPORTER_ASSERT(reporter, false);
+ return;
+ }
+
+ for (int opaque = 0; opaque < 2; ++opaque) {
+ SkBitmap bitmap;
+ make_index8_bitmap(&bitmap, 37, 39, 254, false);
+ SkBitmap bitmapN32;
+ bitmap.copyTo(&bitmapN32, kN32_SkColorType);
+
+ // make two textures...
+ SkAutoTUnref<GrTexture> i8tex(GrUploadBitmapToTexture(ctx, bitmap));
+ SkAutoTUnref<GrTexture> rgbatex(GrUploadBitmapToTexture(ctx, bitmapN32));
+
+ REPORTER_ASSERT(reporter, i8tex->width() == bitmap.width());
+ REPORTER_ASSERT(reporter, i8tex->height() == bitmap.height());
+
+ // Did we get the same?
+ compare_texture_with_bitmap(reporter, rgbatex, bitmapN32);
+ compare_texture_with_bitmap(reporter, i8tex, bitmapN32);
+ }
+}
+#endif
« no previous file with comments | « src/gpu/effects/GrIndex8toRGBEffect.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698