blob: 211e8daff06e636925fd118e46f30b21d55d0c20 [file] [log] [blame]
krajcevski95b1b3d2014-08-07 12:58:38 -07001/*
2 * Copyright 2014 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 "gm.h"
9
10#include "Resources.h"
11#include "SkCanvas.h"
12#include "SkData.h"
reed5965c8a2015-01-07 18:04:45 -080013#include "SkImageGenerator.h"
krajcevski95b1b3d2014-08-07 12:58:38 -070014#include "SkImageDecoder.h"
15#include "SkOSFile.h"
16#include "SkTextureCompressor.h"
17
18static const char *kASTCFilenames[] = {
19 "mandrill_128x128_4x4.astc", // kASTC_4x4_Format
20 "mandrill_130x128_5x4.astc", // kASTC_5x4_Format
21 "mandrill_130x130_5x5.astc", // kASTC_5x5_Format
22 "mandrill_132x130_6x5.astc", // kASTC_6x5_Format
23 "mandrill_132x132_6x6.astc", // kASTC_6x6_Format
24 "mandrill_128x130_8x5.astc", // kASTC_8x5_Format
25 "mandrill_128x132_8x6.astc", // kASTC_8x6_Format
26 "mandrill_128x128_8x8.astc", // kASTC_8x8_Format
27 "mandrill_130x130_10x5.astc", // kASTC_10x5_Format
28 "mandrill_130x132_10x6.astc", // kASTC_10x6_Format
29 "mandrill_130x128_10x8.astc", // kASTC_10x8_Format
30 "mandrill_130x130_10x10.astc", // kASTC_10x10_Format
31 "mandrill_132x130_12x10.astc", // kASTC_12x10_Format
32 "mandrill_132x132_12x12.astc", // kASTC_12x12_Format
33};
34
35static const int kNumASTCFilenames = SK_ARRAY_COUNT(kASTCFilenames);
36
37static inline const char *get_astc_filename(int idx) {
38 if (idx < 0 || kNumASTCFilenames <= idx) {
39 return "";
40 }
krajcevski95b1b3d2014-08-07 12:58:38 -070041 return kASTCFilenames[idx];
42}
43
halcanary2a243382015-09-09 08:16:41 -070044namespace {
45const int kGMDimension = 600;
46const int kBitmapDimension = kGMDimension / 4;
47} // namespace
krajcevski95b1b3d2014-08-07 12:58:38 -070048
halcanary2a243382015-09-09 08:16:41 -070049DEF_SIMPLE_GM(astcbitmap, canvas, kGMDimension, kGMDimension) {
reed74bd9532015-09-14 08:52:12 -070050 for (int j = 0; j < 4; ++j) {
51 for (int i = 0; i < 4; ++i) {
52 SkBitmap bm;
53 if (GetResourceAsBitmap(get_astc_filename(j*4+i), &bm)) {
krajcevski95b1b3d2014-08-07 12:58:38 -070054 const SkScalar bmX = static_cast<SkScalar>(i*kBitmapDimension);
55 const SkScalar bmY = static_cast<SkScalar>(j*kBitmapDimension);
56 canvas->drawBitmap(bm, bmX, bmY);
57 }
58 }
reed74bd9532015-09-14 08:52:12 -070059 }
60}
61
62DEF_SIMPLE_GM(astc_image, canvas, kGMDimension, kGMDimension) {
63 for (int j = 0; j < 4; ++j) {
64 for (int i = 0; i < 4; ++i) {
65 SkAutoTUnref<SkImage> image(GetResourceAsImage(get_astc_filename(j*4+i)));
66 if (image) {
67 const SkScalar bmX = static_cast<SkScalar>(i*kBitmapDimension);
68 const SkScalar bmY = static_cast<SkScalar>(j*kBitmapDimension);
69 canvas->drawImage(image, bmX, bmY);
70 }
71 }
72 }
halcanary2a243382015-09-09 08:16:41 -070073}