aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2016-04-15 06:59:38 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-04-15 06:59:39 -0700
commit8c3fd4f1b49a77634b73f787c6c49d34039a16f0 (patch)
tree7634a1926ff900026077d9cec0b6d0c96a1bd6e2 /include/core
parent3faf74b8364491ca806f523fbb1d8a97be592663 (diff)
spriteblitter for memcpy case (for all configs)
Diffstat (limited to 'include/core')
-rw-r--r--include/core/SkBitmap.h2
-rw-r--r--include/core/SkImageInfo.h36
-rw-r--r--include/core/SkPixmap.h5
3 files changed, 30 insertions, 13 deletions
diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h
index a81e03eefa..27a00f977e 100644
--- a/include/core/SkBitmap.h
+++ b/include/core/SkBitmap.h
@@ -105,7 +105,7 @@ public:
* Return the shift amount per pixel (i.e. 0 for 1-byte per pixel, 1 for 2-bytes per pixel
* colortypes, 2 for 4-bytes per pixel colortypes). Return 0 for kUnknown_SkColorType.
*/
- int shiftPerPixel() const { return this->bytesPerPixel() >> 1; }
+ int shiftPerPixel() const { return this->fInfo.shiftPerPixel(); }
///////////////////////////////////////////////////////////////////////////
diff --git a/include/core/SkImageInfo.h b/include/core/SkImageInfo.h
index c55edd36c2..4b308c05d8 100644
--- a/include/core/SkImageInfo.h
+++ b/include/core/SkImageInfo.h
@@ -105,6 +105,25 @@ static int SkColorTypeBytesPerPixel(SkColorType ct) {
return gSize[ct];
}
+static int SkColorTypeShiftPerPixel(SkColorType ct) {
+ static const uint8_t gShift[] = {
+ 0, // Unknown
+ 0, // Alpha_8
+ 1, // RGB_565
+ 1, // ARGB_4444
+ 2, // RGBA_8888
+ 2, // BGRA_8888
+ 0, // kIndex_8
+ 0, // kGray_8
+ 3, // kRGBA_F16
+ };
+ static_assert(SK_ARRAY_COUNT(gShift) == (size_t)(kLastEnum_SkColorType + 1),
+ "size_mismatch_with_SkColorType_enum");
+
+ SkASSERT((size_t)ct < SK_ARRAY_COUNT(gShift));
+ return gShift[ct];
+}
+
static inline size_t SkColorTypeMinRowBytes(SkColorType ct, int width) {
return width * SkColorTypeBytesPerPixel(ct);
}
@@ -114,15 +133,10 @@ static inline bool SkColorTypeIsValid(unsigned value) {
}
static inline size_t SkColorTypeComputeOffset(SkColorType ct, int x, int y, size_t rowBytes) {
- int shift = 0;
- switch (SkColorTypeBytesPerPixel(ct)) {
- case 8: shift = 3; break;
- case 4: shift = 2; break;
- case 2: shift = 1; break;
- case 1: shift = 0; break;
- default: return 0;
+ if (kUnknown_SkColorType == ct) {
+ return 0;
}
- return y * rowBytes + (x << shift);
+ return y * rowBytes + (x << SkColorTypeShiftPerPixel(ct));
}
///////////////////////////////////////////////////////////////////////////////
@@ -252,9 +266,9 @@ public:
return SkImageInfo::Make(fWidth, fHeight, newColorType, fAlphaType, fProfileType);
}
- int bytesPerPixel() const {
- return SkColorTypeBytesPerPixel(fColorType);
- }
+ int bytesPerPixel() const { return SkColorTypeBytesPerPixel(fColorType); }
+
+ int shiftPerPixel() const { return SkColorTypeShiftPerPixel(fColorType); }
uint64_t minRowBytes64() const {
return sk_64_mul(fWidth, this->bytesPerPixel());
diff --git a/include/core/SkPixmap.h b/include/core/SkPixmap.h
index 5f90273a97..c3c27bec78 100644
--- a/include/core/SkPixmap.h
+++ b/include/core/SkPixmap.h
@@ -80,7 +80,7 @@ public:
* Return the shift amount per pixel (i.e. 0 for 1-byte per pixel, 1 for 2-bytes per pixel
* colortypes, 2 for 4-bytes per pixel colortypes). Return 0 for kUnknown_SkColorType.
*/
- int shiftPerPixel() const { return fInfo.bytesPerPixel() >> 1; }
+ int shiftPerPixel() const { return fInfo.shiftPerPixel(); }
uint64_t getSize64() const { return sk_64_mul(fInfo.height(), fRowBytes); }
uint64_t getSafeSize64() const { return fInfo.getSafeSize64(fRowBytes); }
@@ -141,6 +141,9 @@ public:
// Writable versions
void* writable_addr() const { return const_cast<void*>(fPixels); }
+ void* writable_addr(int x, int y) const {
+ return const_cast<void*>(this->addr(x, y));
+ }
uint8_t* writable_addr8(int x, int y) const {
return const_cast<uint8_t*>(this->addr8(x, y));
}