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

Unified Diff: include/core/SkImageInfo.h

Issue 1887103003: spriteblitter for memcpy case (for all configs) (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: use normal left shift operator Created 4 years, 8 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 | « include/core/SkBitmap.h ('k') | include/core/SkPixmap.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/core/SkImageInfo.h
diff --git a/include/core/SkImageInfo.h b/include/core/SkImageInfo.h
index c55edd36c2252bc38fa2ad581875e839aa8a0ef5..4b308c05d88ca736d69451f3b970c1bd71b30b12 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());
« no previous file with comments | « include/core/SkBitmap.h ('k') | include/core/SkPixmap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698