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

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

Issue 406693002: First pass at a blitter for R11 EAC alpha masks. This shaves 10ms off (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Get rid of SK_OVERRIDE in module Created 6 years, 5 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 | « no previous file | src/utils/SkTextureCompressor.cpp » ('j') | 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 #ifndef SkTextureCompressor_DEFINED 8 #ifndef SkTextureCompressor_DEFINED
9 #define SkTextureCompressor_DEFINED 9 #define SkTextureCompressor_DEFINED
10 10
11 #include "SkImageInfo.h" 11 #include "SkImageInfo.h"
12 #include "SkBlitter.h"
12 13
13 class SkBitmap; 14 class SkBitmap;
14 class SkData; 15 class SkData;
15 16
16 namespace SkTextureCompressor { 17 namespace SkTextureCompressor {
17 // Various texture compression formats that we support. 18 // Various texture compression formats that we support.
18 enum Format { 19 enum Format {
19 // Alpha only formats. 20 // Alpha only formats.
20 kLATC_Format, 21 kLATC_Format,
21 kR11_EAC_Format, 22 kR11_EAC_Format,
(...skipping 13 matching lines...) Expand all
35 // be large enough to hold the compressed data according to the format. 36 // be large enough to hold the compressed data according to the format.
36 bool CompressBufferToFormat(uint8_t* dst, const uint8_t* src, SkColorType sr cColorType, 37 bool CompressBufferToFormat(uint8_t* dst, const uint8_t* src, SkColorType sr cColorType,
37 int width, int height, int rowBytes, Format form at, 38 int width, int height, int rowBytes, Format form at,
38 bool opt = true /* Use optimization if available */); 39 bool opt = true /* Use optimization if available */);
39 40
40 // This typedef defines what the nominal aspects of a compression function 41 // This typedef defines what the nominal aspects of a compression function
41 // are. The typedef is not meant to be used by clients of the API, but rathe r 42 // are. The typedef is not meant to be used by clients of the API, but rathe r
42 // allows SIMD optimized compression functions to be implemented. 43 // allows SIMD optimized compression functions to be implemented.
43 typedef bool (*CompressionProc)(uint8_t* dst, const uint8_t* src, 44 typedef bool (*CompressionProc)(uint8_t* dst, const uint8_t* src,
44 int width, int height, int rowBytes); 45 int width, int height, int rowBytes);
46
47 // This class implements a blitter that blits directly into a buffer that wi ll
48 // be used as an R11 EAC compressed texture. We compute this buffer by
49 // buffering four scan lines and then outputting them all at once. This blit ter
50 // is only expected to be used with alpha masks, i.e. kAlpha8_SkColorType.
51 class R11_EACBlitter : public SkBlitter {
52 public:
53 R11_EACBlitter(int width, int height, void *compressedBuffer);
54 virtual ~R11_EACBlitter() { this->flushRuns(); }
55
56 // Blit a horizontal run of one or more pixels.
57 virtual void blitH(int x, int y, int width) SK_OVERRIDE {
58 // This function is intended to be called from any standard RGB
59 // buffer, so we should never encounter it. However, if some code
60 // path does end up here, then this needs to be investigated.
61 SkFAIL("Not implemented!");
62 }
63
64 /// Blit a horizontal run of antialiased pixels; runs[] is a *sparse*
65 /// zero-terminated run-length encoding of spans of constant alpha value s.
66 virtual void blitAntiH(int x, int y,
67 const SkAlpha antialias[],
68 const int16_t runs[]) SK_OVERRIDE;
69
70 // Blit a vertical run of pixels with a constant alpha value.
71 virtual void blitV(int x, int y, int height, SkAlpha alpha) SK_OVERRIDE {
72 // This function is currently not implemented. It is not explicitly
73 // required by the contract, but if at some time a code path runs in to
74 // this function (which is entirely possible), it needs to be implem ented.
75 //
76 // TODO (krajcevski):
77 // This function will be most easily implemented in one of two ways:
78 // 1. Buffer each vertical column value and then construct a list
79 // of alpha values and output all of the blocks at once. This onl y
80 // requires a write to the compressed buffer
81 // 2. Replace the indices of each block with the proper indices base d
82 // on the alpha value. This requires a read and write of the comp ressed
83 // buffer, but much less overhead.
84 SkFAIL("Not implemented!");
85 }
86
87 // Blit a solid rectangle one or more pixels wide.
88 virtual void blitRect(int x, int y, int width, int height) SK_OVERRIDE {
89 // Analogous to blitRow, this function is intended for RGB targets
90 // and should never be called by this blitter. Any calls to this fun ction
91 // are probably a bug and should be investigated.
92 SkFAIL("Not implemented!");
93 }
94
95 // Blit a rectangle with one alpha-blended column on the left,
96 // width (zero or more) opaque pixels, and one alpha-blended column
97 // on the right. The result will always be at least two pixels wide.
98 virtual void blitAntiRect(int x, int y, int width, int height,
99 SkAlpha leftAlpha, SkAlpha rightAlpha) SK_OVER RIDE {
100 // This function is currently not implemented. It is not explicitly
101 // required by the contract, but if at some time a code path runs in to
102 // this function (which is entirely possible), it needs to be implem ented.
103 //
104 // TODO (krajcevski):
105 // This function will be most easily implemented as follows:
106 // 1. If width/height are smaller than a block, then update the
107 // indices of the affected blocks.
108 // 2. If width/height are larger than a block, then construct a 9-pa tch
109 // of block encodings that represent the rectangle, and write the m
110 // to the compressed buffer as necessary. Whether or not the bloc ks
111 // are overwritten by zeros or just their indices are updated is up
112 // to debate.
113 SkFAIL("Not implemented!");
114 }
115
116 // Blit a pattern of pixels defined by a rectangle-clipped mask;
117 // typically used for text.
118 virtual void blitMask(const SkMask&, const SkIRect& clip) SK_OVERRIDE {
119 // This function is currently not implemented. It is not explicitly
120 // required by the contract, but if at some time a code path runs in to
121 // this function (which is entirely possible), it needs to be implem ented.
122 //
123 // TODO (krajcevski):
124 // This function will be most easily implemented in the same way as
125 // blitAntiRect above.
126 SkFAIL("Not implemented!");
127 }
128
129 // If the blitter just sets a single value for each pixel, return the
130 // bitmap it draws into, and assign value. If not, return NULL and ignor e
131 // the value parameter.
132 virtual const SkBitmap* justAnOpaqueColor(uint32_t* value) SK_OVERRIDE {
133 return NULL;
134 }
135
136 /**
137 * Compressed texture blitters only really work correctly if they get
138 * four blocks at a time. That being said, this blitter tries it's best
139 * to preserve semantics if blitAntiH doesn't get called in too many
140 * weird ways...
141 */
142 virtual int requestRowsPreserved() const { return kR11_EACBlockSz; }
143
144 protected:
145 virtual void onNotifyFinished() { this->flushRuns(); }
146
147 private:
148 static const int kR11_EACBlockSz = 4;
149 static const int kPixelsPerBlock = kR11_EACBlockSz * kR11_EACBlockSz;
150
151 // The longest possible run of pixels that this blitter will receive.
152 // This is initialized in the constructor to 0x7FFE, which is one less
153 // than the largest positive 16-bit integer. We make sure that it's one
154 // less for debugging purposes. We also don't make this variable static
155 // in order to make sure that we can construct a valid pointer to it.
156 const int16_t kLongestRun;
157
158 // Usually used in conjunction with kLongestRun. This is initialized to
159 // zero.
160 const SkAlpha kZeroAlpha;
161
162 // This is the information that we buffer whenever we're asked to blit
163 // a row with this blitter.
164 struct BufferedRun {
165 const SkAlpha* fAlphas;
166 const int16_t* fRuns;
167 int fX, fY;
168 } fBufferedRuns[kR11_EACBlockSz];
169
170 // The next row (0-3) that we need to blit. This value should never exce ed
171 // the number of rows that we have (kR11_EACBlockSz)
172 int fNextRun;
173
174 // The width and height of the image that we're blitting
175 const int fWidth;
176 const int fHeight;
177
178 // The R11 EAC buffer that we're blitting into. It is assumed that the b uffer
179 // is large enough to store a compressed image of size fWidth*fHeight.
180 uint64_t* const fBuffer;
181
182 // Various utility functions
183 int blocksWide() const { return fWidth / kR11_EACBlockSz; }
184 int blocksTall() const { return fHeight / kR11_EACBlockSz; }
185 int totalBlocks() const { return (fWidth * fHeight) / kPixelsPerBlock; }
186
187 // Returns the block index for the block containing pixel (x, y). Block
188 // indices start at zero and proceed in raster order.
189 int getBlockOffset(int x, int y) const {
190 SkASSERT(x < fWidth);
191 SkASSERT(y < fHeight);
192 const int blockCol = x / kR11_EACBlockSz;
193 const int blockRow = y / kR11_EACBlockSz;
194 return blockRow * this->blocksWide() + blockCol;
195 }
196
197 // Returns a pointer to the block containing pixel (x, y)
198 uint64_t *getBlock(int x, int y) const {
199 return fBuffer + this->getBlockOffset(x, y);
200 }
201
202 // The following function writes the buffered runs to compressed blocks.
203 // If fNextRun < 4, then we fill the runs that we haven't buffered with
204 // the constant zero buffer.
205 void flushRuns();
206 };
45 } 207 }
46 208
47 #endif 209 #endif
OLDNEW
« no previous file with comments | « no previous file | src/utils/SkTextureCompressor.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698