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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/utils/SkTextureCompressor.cpp » ('j') | src/utils/SkTextureCompressor.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/utils/SkTextureCompressor.h
diff --git a/src/utils/SkTextureCompressor.h b/src/utils/SkTextureCompressor.h
index ec6153ace9d945c38544633335dde8f9f3f85ce0..1242ed90771a51f5a12ca2a095327e798d177837 100644
--- a/src/utils/SkTextureCompressor.h
+++ b/src/utils/SkTextureCompressor.h
@@ -9,6 +9,7 @@
#define SkTextureCompressor_DEFINED
#include "SkImageInfo.h"
+#include "SkBlitter.h"
class SkBitmap;
class SkData;
@@ -42,6 +43,112 @@ namespace SkTextureCompressor {
// allows SIMD optimized compression functions to be implemented.
typedef bool (*CompressionProc)(uint8_t* dst, const uint8_t* src,
int width, int height, int rowBytes);
+
robertphillips 2014/07/21 14:28:06 // This class ... ?
krajcevski 2014/07/21 17:35:27 Done.
+ class R11_EACBlitter : public SkBlitter {
+ public:
+ R11_EACBlitter(int width, int height, void *latcBuffer);
+ virtual ~R11_EACBlitter() { this->flushRuns(); }
+
robertphillips 2014/07/21 14:28:06 /// -> // ?
krajcevski 2014/07/21 17:35:27 Done.
+ /// Blit a horizontal run of one or more pixels.
+ 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
+ SkFAIL("Not implemented!");
+ }
+
+ /// Blit a horizontal run of antialiased pixels; runs[] is a *sparse*
+ /// zero-terminated run-length encoding of spans of constant alpha values.
+ virtual void blitAntiH(int x, int y,
+ const SkAlpha* antialias,
+ const int16_t* runs) SK_OVERRIDE;
+
+ /// Blit a vertical run of pixels with a constant alpha value.
+ 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.
+ SkFAIL("Not implemented!");
+ }
+
+ /// Blit a solid rectangle one or more pixels wide.
+ 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.
+ SkFAIL("Not implemented!");
+ }
+
+ /** Blit a rectangle with one alpha-blended column on the left,
+ width (zero or more) opaque pixels, and one alpha-blended column
+ on the right.
+ The result will always be at least two pixels wide. */
+ virtual void blitAntiRect(int x, int y, int width, int height,
+ SkAlpha leftAlpha, SkAlpha rightAlpha) SK_OVERRIDE {
robertphillips 2014/07/21 14:28:06 ?
krajcevski 2014/07/21 17:35:27 Done.
+ SkFAIL("Not implemented!");
+ }
+ /// Blit a pattern of pixels defined by a rectangle-clipped mask;
+ /// typically used for text.
+ 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.
+ SkFAIL("Not implemented!");
+ }
+
+ /** If the blitter just sets a single value for each pixel, return the
+ bitmap it draws into, and assign value. If not, return NULL and ignore
+ the value parameter.
+ */
+ virtual const SkBitmap* justAnOpaqueColor(uint32_t* value) SK_OVERRIDE {
+ return NULL;
+ }
+
+ /**
+ * Compressed texture blitters only really work correctly if they get
+ * four blocks at a time. That being said, this blitter tries it's best
+ * to preserve semantics if blitAntiH doesn't get called in too many
+ * weird ways...
+ */
+ virtual int requestRowsPreserved() const { return kR11_EACBlockSz; }
+
+ protected:
+ virtual void onNotifyFinished() { this->flushRuns(); }
+
+ private:
+ static const int kR11_EACBlockSz = 4;
+ static const int kPixelsPerBlock = kR11_EACBlockSz * kR11_EACBlockSz;
+
+ // Various utility functions
+ int blocksWide() const { return fWidth / kR11_EACBlockSz; }
+ int blocksTall() const { return fHeight / kR11_EACBlockSz; }
+ int totalBlocks() const { return (fWidth * fHeight) / kPixelsPerBlock; }
+
+ // Returns the block index for the block containing pixel (x, y). Block
+ // indices start at zero and proceed in raster order.
+ int getBlockOffset(int x, int y) const {
+ SkASSERT(x < fWidth);
+ SkASSERT(y < fHeight);
+ const int blockCol = x / kR11_EACBlockSz;
+ const int blockRow = y / kR11_EACBlockSz;
+ return blockRow * this->blocksWide() + blockCol;
+ }
+
+ // Returns a pointer to the block containing pixel (x, y)
+ uint64_t *getBlock(int x, int y) const {
+ return fBuffer + getBlockOffset(x, y);
+ }
+
robertphillips 2014/07/21 14:28:06 order is supposed to be member variables then meth
krajcevski 2014/07/21 17:35:27 Done.
+ const int16_t kLongestRun;
+ const SkAlpha kZeroAlpha;
+ struct BufferedRun {
+ const SkAlpha* fAlphas;
+ const int16_t* fRuns;
+ int fX, fY;
+ } fBufferedRuns[kR11_EACBlockSz];
+ int fNextRun;
+
+ // The following function writes the buffered runs to compressed blocks.
+ // If fNextRun < 4, then we fill the runs that we haven't buffered with
+ // the constant zero buffer.
+ void flushRuns();
+
+ // The width and height of the image that we're blitting
+ const int fWidth;
+ const int fHeight;
+
+ // The R11 EAC buffer that we're blitting into. It is assumed that the buffer
+ // is large enough to store a compressed image of size fWidth*fHeight.
+ uint64_t*const fBuffer;
+ };
}
#endif
« no previous file with comments | « no previous file | src/utils/SkTextureCompressor.cpp » ('j') | src/utils/SkTextureCompressor.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698