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

Side by Side Diff: tests/TextureCompressionTest.cpp

Issue 429683003: Bring LATC in line with other formats (i.e. write a blitter and (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update unit tests Created 6 years, 4 months 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/utils/SkTextureCompressor_LATC.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
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkData.h" 9 #include "SkData.h"
10 #include "SkEndian.h" 10 #include "SkEndian.h"
11 #include "SkImageInfo.h" 11 #include "SkImageInfo.h"
12 #include "SkTextureCompressor.h" 12 #include "SkTextureCompressor.h"
13 #include "Test.h" 13 #include "Test.h"
14 14
15 static const int kLATCBlockDimension = 4;
16 static const int kLATCEncodedBlockSize = 8;
17
18 /** 15 /**
19 * Make sure that we properly fail when we don't have multiple of four image dim ensions. 16 * Make sure that we properly fail when we don't have multiple of four image dim ensions.
20 */ 17 */
21 DEF_TEST(CompressLATCFailDimensions, reporter) { 18 DEF_TEST(CompressAlphaFailDimensions, reporter) {
22 SkBitmap bitmap; 19 SkBitmap bitmap;
23 static const int kWidth = 63; 20 static const int kWidth = 63;
24 static const int kHeight = 63; 21 static const int kHeight = 63;
25 SkImageInfo info = SkImageInfo::MakeA8(kWidth, kHeight); 22 SkImageInfo info = SkImageInfo::MakeA8(kWidth, kHeight);
26 REPORTER_ASSERT(reporter, kWidth % kLATCBlockDimension != 0); 23
27 REPORTER_ASSERT(reporter, kHeight % kLATCBlockDimension != 0); 24 // R11_EAC and LATC are both dimensions of 4, so we need to make sure that w e
25 // are violating those assumptions. And if we are, then we're also violating the
26 // assumptions of ASTC, which is 12x12 since any number not divisible by 4 i s
27 // also not divisible by 12.
28 REPORTER_ASSERT(reporter, kWidth % 4 != 0);
29 REPORTER_ASSERT(reporter, kHeight % 4 != 0);
28 30
29 bool setInfoSuccess = bitmap.setInfo(info); 31 bool setInfoSuccess = bitmap.setInfo(info);
30 REPORTER_ASSERT(reporter, setInfoSuccess); 32 REPORTER_ASSERT(reporter, setInfoSuccess);
31 33
32 bool allocPixelsSuccess = bitmap.allocPixels(info); 34 bool allocPixelsSuccess = bitmap.allocPixels(info);
33 REPORTER_ASSERT(reporter, allocPixelsSuccess); 35 REPORTER_ASSERT(reporter, allocPixelsSuccess);
34 bitmap.unlockPixels(); 36 bitmap.unlockPixels();
35 37
36 const SkTextureCompressor::Format kLATCFormat = SkTextureCompressor::kLATC_F ormat; 38 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) {
37 SkAutoDataUnref latcData(SkTextureCompressor::CompressBitmapToFormat(bitmap, kLATCFormat)); 39 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor: :Format>(i);
38 REPORTER_ASSERT(reporter, NULL == latcData); 40 SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap, fmt));
41 REPORTER_ASSERT(reporter, NULL == data);
42 }
39 } 43 }
40 44
41 /** 45 /**
42 * Make sure that we properly fail when we don't have the correct bitmap type. 46 * Make sure that we properly fail when we don't have the correct bitmap type.
43 * LATC compressed textures can only be created from A8 bitmaps. 47 * compressed textures can (currently) only be created from A8 bitmaps.
44 */ 48 */
45 DEF_TEST(CompressLATCFailColorType, reporter) { 49 DEF_TEST(CompressAlphaFailColorType, reporter) {
46 SkBitmap bitmap; 50 SkBitmap bitmap;
47 static const int kWidth = 64; 51 static const int kWidth = 60;
48 static const int kHeight = 64; 52 static const int kHeight = 60;
49 SkImageInfo info = SkImageInfo::MakeN32Premul(kWidth, kHeight); 53 SkImageInfo info = SkImageInfo::MakeN32Premul(kWidth, kHeight);
50 REPORTER_ASSERT(reporter, kWidth % kLATCBlockDimension == 0); 54
51 REPORTER_ASSERT(reporter, kHeight % kLATCBlockDimension == 0); 55 // ASTC is at most 12x12, and any dimension divisible by 12 is also divisibl e
56 // by 4, which is the dimensions of R11_EAC and LATC
robertphillips 2014/07/30 15:02:23 What about 8 ?
krajcevski 2014/07/30 15:23:27 We don't currently support 8x8 ASTC, if we do ever
57 REPORTER_ASSERT(reporter, kWidth % 12 == 0);
58 REPORTER_ASSERT(reporter, kHeight % 12 == 0);
52 59
53 bool setInfoSuccess = bitmap.setInfo(info); 60 bool setInfoSuccess = bitmap.setInfo(info);
54 REPORTER_ASSERT(reporter, setInfoSuccess); 61 REPORTER_ASSERT(reporter, setInfoSuccess);
55 62
56 bool allocPixelsSuccess = bitmap.allocPixels(info); 63 bool allocPixelsSuccess = bitmap.allocPixels(info);
57 REPORTER_ASSERT(reporter, allocPixelsSuccess); 64 REPORTER_ASSERT(reporter, allocPixelsSuccess);
58 bitmap.unlockPixels(); 65 bitmap.unlockPixels();
59 66
60 const SkTextureCompressor::Format kLATCFormat = SkTextureCompressor::kLATC_F ormat; 67 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) {
61 SkAutoDataUnref latcData(SkTextureCompressor::CompressBitmapToFormat(bitmap, kLATCFormat)); 68 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor: :Format>(i);
62 REPORTER_ASSERT(reporter, NULL == latcData); 69 SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap, fmt));
70 REPORTER_ASSERT(reporter, NULL == data);
71 }
63 } 72 }
64 73
65 /** 74 /**
66 * Make sure that if we pass in a solid color bitmap that we get the appropriate results 75 * Make sure that if we pass in a solid color bitmap that we get the appropriate results
67 */ 76 */
68 DEF_TEST(CompressLATC, reporter) { 77 DEF_TEST(CompressLATC, reporter) {
78
79 const SkTextureCompressor::Format kLATCFormat = SkTextureCompressor::kLATC_F ormat;
80 static const int kLATCEncodedBlockSize = 8;
81
69 SkBitmap bitmap; 82 SkBitmap bitmap;
70 static const int kWidth = 8; 83 static const int kWidth = 8;
71 static const int kHeight = 8; 84 static const int kHeight = 8;
72 SkImageInfo info = SkImageInfo::MakeA8(kWidth, kHeight); 85 SkImageInfo info = SkImageInfo::MakeA8(kWidth, kHeight);
73 86
74 bool setInfoSuccess = bitmap.setInfo(info); 87 bool setInfoSuccess = bitmap.setInfo(info);
75 REPORTER_ASSERT(reporter, setInfoSuccess); 88 REPORTER_ASSERT(reporter, setInfoSuccess);
76 89
77 bool allocPixelsSuccess = bitmap.allocPixels(info); 90 bool allocPixelsSuccess = bitmap.allocPixels(info);
78 REPORTER_ASSERT(reporter, allocPixelsSuccess); 91 REPORTER_ASSERT(reporter, allocPixelsSuccess);
79 bitmap.unlockPixels(); 92 bitmap.unlockPixels();
80 93
81 REPORTER_ASSERT(reporter, kWidth % kLATCBlockDimension == 0); 94 int latcDimX, latcDimY;
82 REPORTER_ASSERT(reporter, kHeight % kLATCBlockDimension == 0); 95 SkTextureCompressor::GetBlockDimensions(kLATCFormat, &latcDimX, &latcDimY);
83 const int numBlocks = (kWidth / kLATCBlockDimension) * (kHeight / kLATCBlock Dimension); 96
84 const size_t kSizeToBe = static_cast<size_t>(kLATCEncodedBlockSize * numBloc ks); 97 REPORTER_ASSERT(reporter, kWidth % latcDimX == 0);
98 REPORTER_ASSERT(reporter, kHeight % latcDimY == 0);
99 const size_t kSizeToBe =
100 SkTextureCompressor::GetCompressedDataSize(kLATCFormat, kWidth, kHeight) ;
101 REPORTER_ASSERT(reporter, kSizeToBe == ((kWidth*kHeight*kLATCEncodedBlockSiz e)/16));
102 REPORTER_ASSERT(reporter, (kSizeToBe % kLATCEncodedBlockSize) == 0);
85 103
86 for (int lum = 0; lum < 256; ++lum) { 104 for (int lum = 0; lum < 256; ++lum) {
87 bitmap.lockPixels(); 105 bitmap.lockPixels();
88 uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap.getPixels()); 106 uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap.getPixels());
89 REPORTER_ASSERT(reporter, NULL != pixels); 107 REPORTER_ASSERT(reporter, NULL != pixels);
90 108
91 for (int i = 0; i < kWidth*kHeight; ++i) { 109 for (int i = 0; i < kWidth*kHeight; ++i) {
92 pixels[i] = lum; 110 pixels[i] = lum;
93 } 111 }
94 bitmap.unlockPixels(); 112 bitmap.unlockPixels();
95 113
96 const SkTextureCompressor::Format kLATCFormat = SkTextureCompressor::kLA TC_Format;
97 SkAutoDataUnref latcData( 114 SkAutoDataUnref latcData(
98 SkTextureCompressor::CompressBitmapToFormat(bitmap, kLATCFormat)); 115 SkTextureCompressor::CompressBitmapToFormat(bitmap, kLATCFormat));
99 REPORTER_ASSERT(reporter, NULL != latcData); 116 REPORTER_ASSERT(reporter, NULL != latcData);
100 REPORTER_ASSERT(reporter, kSizeToBe == latcData->size()); 117 REPORTER_ASSERT(reporter, kSizeToBe == latcData->size());
101 118
102 // Make sure that it all matches a given block encoding. If the entire b itmap 119 // Make sure that it all matches a given block encoding. Since we have
103 // is a single value, then the lower two bytes of the encoded data shoul d be that 120 // COMPRESS_LATC_FAST defined in SkTextureCompressor_LATC.cpp, we are us ing
104 // value. The remaining indices can be any value, and since we try to ma tch the pixels 121 // an approximation scheme that optimizes for speed against coverage map s.
105 // in the chosen palette in increasing index order, each one should be z ero. Hence, 122 // That means that each palette in the encoded block is exactly the same ,
106 // the correct encoding should be just the two luminance values in the b ottom two 123 // and that the three bits saved per pixel are computed from the top thr ee
107 // bytes of the block encoding. 124 // bits of the luminance value.
108 const uint64_t kConstColorEncoding = SkEndian_SwapLE64(lum | (lum << 8)) ; 125 const uint64_t kIndexEncodingMap[8] = { 1, 7, 6, 5, 4, 3, 2, 0 };
126 const uint64_t kIndex = kIndexEncodingMap[lum >> 5];
127 const uint64_t kConstColorEncoding =
128 SkEndian_SwapLE64(
129 255 |
130 (kIndex << 16) | (kIndex << 19) | (kIndex << 22) | (kIndex << 25 ) |
131 (kIndex << 28) | (kIndex << 31) | (kIndex << 34) | (kIndex << 37 ) |
132 (kIndex << 40) | (kIndex << 43) | (kIndex << 46) | (kIndex << 49 ) |
133 (kIndex << 52) | (kIndex << 55) | (kIndex << 58) | (kIndex << 61 ));
134
109 const uint64_t* blockPtr = reinterpret_cast<const uint64_t*>(latcData->d ata()); 135 const uint64_t* blockPtr = reinterpret_cast<const uint64_t*>(latcData->d ata());
110 for (int i = 0; i < numBlocks; ++i) { 136 for (size_t i = 0; i < (kSizeToBe/8); ++i) {
111 REPORTER_ASSERT(reporter, blockPtr[i] == kConstColorEncoding); 137 REPORTER_ASSERT(reporter, blockPtr[i] == kConstColorEncoding);
112 } 138 }
113 } 139 }
114 } 140 }
OLDNEW
« no previous file with comments | « src/utils/SkTextureCompressor_LATC.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698