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

Side by Side Diff: src/utils/SkTextureCompressor.cpp

Issue 1273103002: Port SkTextureCompression opts to SkOpts (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update include_dirs Created 5 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.h ('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 "SkTextureCompressor.h" 8 #include "SkTextureCompressor.h"
9 #include "SkTextureCompressor_ASTC.h" 9 #include "SkTextureCompressor_ASTC.h"
10 #include "SkTextureCompressor_LATC.h" 10 #include "SkTextureCompressor_LATC.h"
11 #include "SkTextureCompressor_R11EAC.h" 11 #include "SkTextureCompressor_R11EAC.h"
12 12
13 #include "SkBitmap.h" 13 #include "SkBitmap.h"
14 #include "SkBitmapProcShader.h" 14 #include "SkBitmapProcShader.h"
15 #include "SkData.h" 15 #include "SkData.h"
16 #include "SkEndian.h" 16 #include "SkEndian.h"
17 17 #include "SkOpts.h"
18 #include "SkTextureCompression_opts.h"
19 18
20 #ifndef SK_IGNORE_ETC1_SUPPORT 19 #ifndef SK_IGNORE_ETC1_SUPPORT
21 # include "etc1.h" 20 # include "etc1.h"
22 #endif 21 #endif
23 22
24 // Convert ETC1 functions to our function signatures 23 // Convert ETC1 functions to our function signatures
25 static bool compress_etc1_565(uint8_t* dst, const uint8_t* src, 24 static bool compress_etc1_565(uint8_t* dst, const uint8_t* src,
26 int width, int height, size_t rowBytes) { 25 int width, int height, size_t rowBytes) {
27 #ifndef SK_IGNORE_ETC1_SUPPORT 26 #ifndef SK_IGNORE_ETC1_SUPPORT
28 return 0 == etc1_encode_image(src, width, height, 2, SkToInt(rowBytes), dst) ; 27 return 0 == etc1_encode_image(src, width, height, 2, SkToInt(rowBytes), dst) ;
29 #else 28 #else
30 return false; 29 return false;
31 #endif 30 #endif
32 } 31 }
33 32
34 //////////////////////////////////////////////////////////////////////////////// 33 ////////////////////////////////////////////////////////////////////////////////
35 34
36 namespace SkTextureCompressor { 35 namespace SkTextureCompressor {
37 36
38 void GetBlockDimensions(Format format, int* dimX, int* dimY, bool matchSpec) { 37 void GetBlockDimensions(Format format, int* dimX, int* dimY, bool matchSpec) {
39 if (NULL == dimX || NULL == dimY) { 38 if (NULL == dimX || NULL == dimY) {
40 return; 39 return;
41 } 40 }
42 41
43 if (!matchSpec && SkTextureCompressorGetPlatformDims(format, dimX, dimY)) { 42 if (!matchSpec && SkOpts::fill_block_dimensions(format, dimX, dimY)) {
44 return; 43 return;
45 } 44 }
46 45
47 // No specialized arguments, return the dimensions as they are in the spec. 46 // No specialized arguments, return the dimensions as they are in the spec.
48 static const struct FormatDimensions { 47 static const struct FormatDimensions {
49 const int fBlockSizeX; 48 const int fBlockSizeX;
50 const int fBlockSizeY; 49 const int fBlockSizeY;
51 } kFormatDimensions[kFormatCnt] = { 50 } kFormatDimensions[kFormatCnt] = {
52 { 4, 4 }, // kLATC_Format 51 { 4, 4 }, // kLATC_Format
53 { 4, 4 }, // kR11_EAC_Format 52 { 4, 4 }, // kR11_EAC_Format
(...skipping 16 matching lines...) Expand all
70 69
71 *dimX = kFormatDimensions[format].fBlockSizeX; 70 *dimX = kFormatDimensions[format].fBlockSizeX;
72 *dimY = kFormatDimensions[format].fBlockSizeY; 71 *dimY = kFormatDimensions[format].fBlockSizeY;
73 } 72 }
74 73
75 int GetCompressedDataSize(Format fmt, int width, int height) { 74 int GetCompressedDataSize(Format fmt, int width, int height) {
76 int dimX, dimY; 75 int dimX, dimY;
77 GetBlockDimensions(fmt, &dimX, &dimY, true); 76 GetBlockDimensions(fmt, &dimX, &dimY, true);
78 77
79 int encodedBlockSize = 0; 78 int encodedBlockSize = 0;
80 79
81 switch (fmt) { 80 switch (fmt) {
82 // These formats are 64 bits per 4x4 block. 81 // These formats are 64 bits per 4x4 block.
83 case kLATC_Format: 82 case kLATC_Format:
84 case kR11_EAC_Format: 83 case kR11_EAC_Format:
85 case kETC1_Format: 84 case kETC1_Format:
86 encodedBlockSize = 8; 85 encodedBlockSize = 8;
87 break; 86 break;
88 87
89 // This format is 128 bits. 88 // This format is 128 bits.
90 case kASTC_4x4_Format: 89 case kASTC_4x4_Format:
(...skipping 22 matching lines...) Expand all
113 const int blocksX = width / dimX; 112 const int blocksX = width / dimX;
114 const int blocksY = height / dimY; 113 const int blocksY = height / dimY;
115 114
116 return blocksX * blocksY * encodedBlockSize; 115 return blocksX * blocksY * encodedBlockSize;
117 } 116 }
118 117
119 return -1; 118 return -1;
120 } 119 }
121 120
122 bool CompressBufferToFormat(uint8_t* dst, const uint8_t* src, SkColorType srcCol orType, 121 bool CompressBufferToFormat(uint8_t* dst, const uint8_t* src, SkColorType srcCol orType,
123 int width, int height, size_t rowBytes, Format forma t, bool opt) { 122 int width, int height, size_t rowBytes, Format forma t) {
124 CompressionProc proc = NULL; 123 SkOpts::TextureCompressor proc = SkOpts::texture_compressor(srcColorType, fo rmat);
125 if (opt) { 124 if (proc && proc(dst, src, width, height, rowBytes)) {
126 proc = SkTextureCompressorGetPlatformProc(srcColorType, format); 125 return true;
127 } 126 }
128 127
129 if (NULL == proc) { 128 switch (srcColorType) {
130 switch (srcColorType) { 129 case kAlpha_8_SkColorType:
131 case kAlpha_8_SkColorType: 130 if (format == kLATC_Format) { proc = CompressA8ToLATC; }
132 { 131 if (format == kR11_EAC_Format) { proc = CompressA8ToR11EAC; }
133 switch (format) { 132 if (format == kASTC_12x12_Format) { proc = CompressA8To12x12ASTC; }
134 case kLATC_Format:
135 proc = CompressA8ToLATC;
136 break;
137 case kR11_EAC_Format:
138 proc = CompressA8ToR11EAC;
139 break;
140 case kASTC_12x12_Format:
141 proc = CompressA8To12x12ASTC;
142 break;
143 default:
144 // Do nothing...
145 break;
146 }
147 }
148 break; 133 break;
149 134 case kRGB_565_SkColorType:
150 case kRGB_565_SkColorType: 135 if (format == kETC1_Format) { proc = compress_etc1_565; }
151 {
152 switch (format) {
153 case kETC1_Format:
154 proc = compress_etc1_565;
155 break;
156 default:
157 // Do nothing...
158 break;
159 }
160 }
161 break; 136 break;
162 137 default:
163 default: 138 break;
164 // Do nothing...
165 break;
166 }
167 } 139 }
168 140 if (proc && proc(dst, src, width, height, rowBytes)) {
169 if (proc) { 141 return true;
170 return proc(dst, src, width, height, rowBytes);
171 } 142 }
172 143
173 return false; 144 return false;
174 } 145 }
175 146
176 SkData* CompressBitmapToFormat(const SkPixmap& pixmap, Format format) { 147 SkData* CompressBitmapToFormat(const SkPixmap& pixmap, Format format) {
177 int compressedDataSize = GetCompressedDataSize(format, pixmap.width(), pixma p.height()); 148 int compressedDataSize = GetCompressedDataSize(format, pixmap.width(), pixma p.height());
178 if (compressedDataSize < 0) { 149 if (compressedDataSize < 0) {
179 return NULL; 150 return NULL;
180 } 151 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 222
252 default: 223 default:
253 // Do nothing... 224 // Do nothing...
254 break; 225 break;
255 } 226 }
256 227
257 return false; 228 return false;
258 } 229 }
259 230
260 } // namespace SkTextureCompressor 231 } // namespace SkTextureCompressor
OLDNEW
« no previous file with comments | « src/utils/SkTextureCompressor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698