OLD | NEW |
---|---|
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 Loading... | |
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 | |
robertphillips
2014/07/21 14:28:06
// This class ... ?
krajcevski
2014/07/21 17:35:27
Done.
| |
47 class R11_EACBlitter : public SkBlitter { | |
48 public: | |
49 R11_EACBlitter(int width, int height, void *latcBuffer); | |
50 virtual ~R11_EACBlitter() { this->flushRuns(); } | |
51 | |
robertphillips
2014/07/21 14:28:06
/// -> // ?
krajcevski
2014/07/21 17:35:27
Done.
| |
52 /// Blit a horizontal run of one or more pixels. | |
53 virtual void blitH(int x, int y, int width) SK_OVERRIDE { | |
robertphillips
2014/07/21 14:28:06
Is this allowed in the SkBlitter contract or a TOD
krajcevski
2014/07/21 17:35:27
All of the not implemented functions are more of a
| |
54 SkFAIL("Not implemented!"); | |
55 } | |
56 | |
57 /// Blit a horizontal run of antialiased pixels; runs[] is a *sparse* | |
58 /// zero-terminated run-length encoding of spans of constant alpha value s. | |
59 virtual void blitAntiH(int x, int y, | |
60 const SkAlpha* antialias, | |
61 const int16_t* runs) SK_OVERRIDE; | |
62 | |
63 /// Blit a vertical run of pixels with a constant alpha value. | |
64 virtual void blitV(int x, int y, int height, SkAlpha alpha) SK_OVERRIDE { | |
robertphillips
2014/07/21 14:28:06
Again - can we do without this?
krajcevski
2014/07/21 17:35:26
Done.
| |
65 SkFAIL("Not implemented!"); | |
66 } | |
67 | |
68 /// Blit a solid rectangle one or more pixels wide. | |
69 virtual void blitRect(int x, int y, int width, int height) SK_OVERRIDE { | |
robertphillips
2014/07/21 14:28:06
Here too?
krajcevski
2014/07/21 17:35:27
Done.
| |
70 SkFAIL("Not implemented!"); | |
71 } | |
72 | |
73 /** Blit a rectangle with one alpha-blended column on the left, | |
74 width (zero or more) opaque pixels, and one alpha-blended column | |
75 on the right. | |
76 The result will always be at least two pixels wide. */ | |
77 virtual void blitAntiRect(int x, int y, int width, int height, | |
78 SkAlpha leftAlpha, SkAlpha rightAlpha) SK_OVER RIDE { | |
robertphillips
2014/07/21 14:28:06
?
krajcevski
2014/07/21 17:35:27
Done.
| |
79 SkFAIL("Not implemented!"); | |
80 } | |
81 /// Blit a pattern of pixels defined by a rectangle-clipped mask; | |
82 /// typically used for text. | |
83 virtual void blitMask(const SkMask&, const SkIRect& clip) SK_OVERRIDE { | |
robertphillips
2014/07/21 14:28:06
?
krajcevski
2014/07/21 17:35:27
Done.
| |
84 SkFAIL("Not implemented!"); | |
85 } | |
86 | |
87 /** If the blitter just sets a single value for each pixel, return the | |
88 bitmap it draws into, and assign value. If not, return NULL and igno re | |
89 the value parameter. | |
90 */ | |
91 virtual const SkBitmap* justAnOpaqueColor(uint32_t* value) SK_OVERRIDE { | |
92 return NULL; | |
93 } | |
94 | |
95 /** | |
96 * Compressed texture blitters only really work correctly if they get | |
97 * four blocks at a time. That being said, this blitter tries it's best | |
98 * to preserve semantics if blitAntiH doesn't get called in too many | |
99 * weird ways... | |
100 */ | |
101 virtual int requestRowsPreserved() const { return kR11_EACBlockSz; } | |
102 | |
103 protected: | |
104 virtual void onNotifyFinished() { this->flushRuns(); } | |
105 | |
106 private: | |
107 static const int kR11_EACBlockSz = 4; | |
108 static const int kPixelsPerBlock = kR11_EACBlockSz * kR11_EACBlockSz; | |
109 | |
110 // Various utility functions | |
111 int blocksWide() const { return fWidth / kR11_EACBlockSz; } | |
112 int blocksTall() const { return fHeight / kR11_EACBlockSz; } | |
113 int totalBlocks() const { return (fWidth * fHeight) / kPixelsPerBlock; } | |
114 | |
115 // Returns the block index for the block containing pixel (x, y). Block | |
116 // indices start at zero and proceed in raster order. | |
117 int getBlockOffset(int x, int y) const { | |
118 SkASSERT(x < fWidth); | |
119 SkASSERT(y < fHeight); | |
120 const int blockCol = x / kR11_EACBlockSz; | |
121 const int blockRow = y / kR11_EACBlockSz; | |
122 return blockRow * this->blocksWide() + blockCol; | |
123 } | |
124 | |
125 // Returns a pointer to the block containing pixel (x, y) | |
126 uint64_t *getBlock(int x, int y) const { | |
127 return fBuffer + getBlockOffset(x, y); | |
128 } | |
129 | |
robertphillips
2014/07/21 14:28:06
order is supposed to be member variables then meth
krajcevski
2014/07/21 17:35:27
Done.
| |
130 const int16_t kLongestRun; | |
131 const SkAlpha kZeroAlpha; | |
132 struct BufferedRun { | |
133 const SkAlpha* fAlphas; | |
134 const int16_t* fRuns; | |
135 int fX, fY; | |
136 } fBufferedRuns[kR11_EACBlockSz]; | |
137 int fNextRun; | |
138 | |
139 // The following function writes the buffered runs to compressed blocks. | |
140 // If fNextRun < 4, then we fill the runs that we haven't buffered with | |
141 // the constant zero buffer. | |
142 void flushRuns(); | |
143 | |
144 // The width and height of the image that we're blitting | |
145 const int fWidth; | |
146 const int fHeight; | |
147 | |
148 // The R11 EAC buffer that we're blitting into. It is assumed that the b uffer | |
149 // is large enough to store a compressed image of size fWidth*fHeight. | |
150 uint64_t*const fBuffer; | |
151 }; | |
45 } | 152 } |
46 | 153 |
47 #endif | 154 #endif |
OLD | NEW |