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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/gpu/effects/GrIndex8toRGBEffect.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "GrContextFactory.h"
9 #include "SkGr.h"
10 #include "SkGrPriv.h"
11 #include "SkConfig8888.h"
12 #include "Test.h"
13
14 #if SK_SUPPORT_GPU
15
16 static void make_index8_bitmap(SkBitmap* result, int width, int height, int ccou nt, bool opaque) {
17 SkAutoMalloc storage(ccount * sizeof(SkPMColor));
18 SkPMColor* palette = static_cast<SkPMColor*>(storage.get());
19 for (int i = 0; i < ccount; ++i) {
20 palette[i] = SkPreMultiplyARGB(opaque ? 0xFF : i, 0xFF - i, i, 0xFF - i) ;
21 }
22 result->setInfo(SkImageInfo::Make(width, height, kIndex_8_SkColorType,
23 opaque ? kOpaque_SkAlphaType : kPremul_SkA lphaType));
24 SkAutoTUnref<SkColorTable> ctable(new SkColorTable(palette, ccount));
25 result->allocPixels(ctable);
26 for (int j = 0; j < height; ++j) {
27 uint8_t* scanline = result->getAddr8(0, j);
28 int c = (j * height);
29 for (int i = 0; i < width; ++i)
30 *scanline++ = ((c++) % ccount);
31 }
32 result->setImmutable();
33 }
34
35 static void compare_texture_with_bitmap(skiatest::Reporter* reporter, GrTexture* txa,
36 const SkBitmap& bm) {
37 SkAutoLockPixels alp(bm);
38 REPORTER_ASSERT(reporter, txa->width() == bm.width());
39 REPORTER_ASSERT(reporter, txa->height() == bm.height());
40 REPORTER_ASSERT(reporter, bm.colorType() == kN32_SkColorType);
41 SkAutoMalloc storage(bm.width() * bm.height() * sizeof(SkPMColor));
42 SkPMColor* pixels = static_cast<SkPMColor*>(storage.get());
43 REPORTER_ASSERT(reporter, txa->readPixels(0, 0, bm.width(), bm.height(), txa ->config(),
44 pixels));
45
46 SkDstPixelInfo dstPI;
47 dstPI.fColorType = kN32_SkColorType;
48 dstPI.fAlphaType = bm.alphaType();
49 dstPI.fPixels = pixels;
50 dstPI.fRowBytes = bm.width() * sizeof(SkPMColor);
51
52 SkSrcPixelInfo srcPI;
53 memcpy(&srcPI, &dstPI, sizeof(SkSrcPixelInfo));
54 srcPI.fColorType = kRGBA_8888_SkColorType;
55
56 srcPI.convertPixelsTo(&dstPI, bm.width(), bm.height());
57
58 for (int j = 0; j < bm.height(); ++j) {
59 for (int i = 0; i < bm.width(); ++i) {
60 REPORTER_ASSERT(reporter, pixels[i + bm.width() * j] == *bm.getAddr3 2(i, j));
61 }
62 }
63 }
64
65 /*
66 * Test two different ways to upload Index8 bitmap to texture.
67 */
68 DEF_GPUTEST(Index8_Texture_Upload, reporter, factory) {
69 GrContext* ctx = factory->get(GrContextFactory::kNative_GLContextType);
70 if (!ctx) {
71 REPORTER_ASSERT(reporter, false);
72 return;
73 }
74
75 for (int opaque = 0; opaque < 2; ++opaque) {
76 SkBitmap bitmap;
77 make_index8_bitmap(&bitmap, 37, 39, 254, false);
78 SkBitmap bitmapN32;
79 bitmap.copyTo(&bitmapN32, kN32_SkColorType);
80
81 // make two textures...
82 SkAutoTUnref<GrTexture> i8tex(GrUploadBitmapToTexture(ctx, bitmap));
83 SkAutoTUnref<GrTexture> rgbatex(GrUploadBitmapToTexture(ctx, bitmapN32)) ;
84
85 REPORTER_ASSERT(reporter, i8tex->width() == bitmap.width());
86 REPORTER_ASSERT(reporter, i8tex->height() == bitmap.height());
87
88 // Did we get the same?
89 compare_texture_with_bitmap(reporter, rgbatex, bitmapN32);
90 compare_texture_with_bitmap(reporter, i8tex, bitmapN32);
91 }
92 }
93 #endif
OLDNEW
« 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