diff --git a/include/core/SkSurface.h b/include/core/SkSurface.h index 3b7df4257f..f126465b3b 100644 --- a/include/core/SkSurface.h +++ b/include/core/SkSurface.h @@ -153,6 +153,7 @@ public: protected: SkSurface(int width, int height); + SkSurface(const SkImageInfo&); // called by subclass if their contents have changed void dirtyGenerationID() { diff --git a/src/image/SkSurface.cpp b/src/image/SkSurface.cpp index 2dde36b96d..cb029c8aea 100644 --- a/src/image/SkSurface.cpp +++ b/src/image/SkSurface.cpp @@ -16,6 +16,11 @@ SkSurface_Base::SkSurface_Base(int width, int height) : INHERITED(width, height) fCachedImage = NULL; } +SkSurface_Base::SkSurface_Base(const SkImageInfo& info) : INHERITED(info) { + fCachedCanvas = NULL; + fCachedImage = NULL; +} + SkSurface_Base::~SkSurface_Base() { // in case the canvas outsurvives us, we null the callback if (fCachedCanvas) { @@ -73,8 +78,17 @@ static SkSurface_Base* asSB(SkSurface* surface) { /////////////////////////////////////////////////////////////////////////////// SkSurface::SkSurface(int width, int height) : fWidth(width), fHeight(height) { - SkASSERT(width >= 0); - SkASSERT(height >= 0); + SkASSERT(fWidth >= 0); + SkASSERT(fHeight >= 0); + fGenerationID = 0; +} + +SkSurface::SkSurface(const SkImageInfo& info) + : fWidth(info.fWidth) + , fHeight(info.fHeight) +{ + SkASSERT(fWidth >= 0); + SkASSERT(fHeight >= 0); fGenerationID = 0; } diff --git a/src/image/SkSurface_Base.h b/src/image/SkSurface_Base.h index cbae5bc5c4..34f32ee1ce 100644 --- a/src/image/SkSurface_Base.h +++ b/src/image/SkSurface_Base.h @@ -14,6 +14,7 @@ class SkSurface_Base : public SkSurface { public: SkSurface_Base(int width, int height); + explicit SkSurface_Base(const SkImageInfo&); virtual ~SkSurface_Base(); /** diff --git a/src/image/SkSurface_Raster.cpp b/src/image/SkSurface_Raster.cpp index 48afe4fc20..1b218eb446 100644 --- a/src/image/SkSurface_Raster.cpp +++ b/src/image/SkSurface_Raster.cpp @@ -18,7 +18,7 @@ public: static bool Valid(const SkImageInfo&, size_t rb = kIgnoreRowBytesValue); SkSurface_Raster(const SkImageInfo&, void*, size_t rb); - SkSurface_Raster(const SkImageInfo&, SkPixelRef*, size_t rb); + SkSurface_Raster(SkPixelRef*); virtual SkCanvas* onNewCanvas() SK_OVERRIDE; virtual SkSurface* onNewSurface(const SkImageInfo&) SK_OVERRIDE; @@ -39,25 +39,21 @@ private: bool SkSurface_Raster::Valid(const SkImageInfo& info, size_t rowBytes) { static const size_t kMaxTotalSize = SK_MaxS32; - SkBitmap::Config config = SkImageInfoToBitmapConfig(info); - int shift = 0; - switch (config) { - case SkBitmap::kA8_Config: + switch (info.fColorType) { + case kAlpha_8_SkColorType: shift = 0; break; - case SkBitmap::kRGB_565_Config: + case kRGB_565_SkColorType: shift = 1; break; - case SkBitmap::kARGB_8888_Config: + case kPMColor_SkColorType: shift = 2; break; default: return false; } - // TODO: examine colorspace - if (kIgnoreRowBytesValue == rowBytes) { return true; } @@ -72,7 +68,7 @@ bool SkSurface_Raster::Valid(const SkImageInfo& info, size_t rowBytes) { return false; } - uint64_t size = (uint64_t)info.fHeight * rowBytes; + uint64_t size = sk_64_mul(info.fHeight, rowBytes); if (size > kMaxTotalSize) { return false; } @@ -81,21 +77,23 @@ bool SkSurface_Raster::Valid(const SkImageInfo& info, size_t rowBytes) { } SkSurface_Raster::SkSurface_Raster(const SkImageInfo& info, void* pixels, size_t rb) - : INHERITED(info.fWidth, info.fHeight) { - SkBitmap::Config config = SkImageInfoToBitmapConfig(info); - fBitmap.setConfig(config, info.fWidth, info.fHeight, rb, info.fAlphaType); + : INHERITED(info) +{ + fBitmap.setConfig(info, rb); fBitmap.setPixels(pixels); fWeOwnThePixels = false; // We are "Direct" } -SkSurface_Raster::SkSurface_Raster(const SkImageInfo& info, SkPixelRef* pr, size_t rb) - : INHERITED(info.fWidth, info.fHeight) { - SkBitmap::Config config = SkImageInfoToBitmapConfig(info); - fBitmap.setConfig(config, info.fWidth, info.fHeight, rb, info.fAlphaType); +SkSurface_Raster::SkSurface_Raster(SkPixelRef* pr) + : INHERITED(pr->info().fWidth, pr->info().fHeight) +{ + const SkImageInfo& info = pr->info(); + + fBitmap.setConfig(info, info.minRowBytes()); fBitmap.setPixelRef(pr); fWeOwnThePixels = true; - if (!SkAlphaTypeIsOpaque(info.fAlphaType)) { + if (!info.isOpaque()) { fBitmap.eraseColor(SK_ColorTRANSPARENT); } } @@ -159,5 +157,5 @@ SkSurface* SkSurface::NewRaster(const SkImageInfo& info) { if (NULL == pr.get()) { return NULL; } - return SkNEW_ARGS(SkSurface_Raster, (info, pr, info.minRowBytes())); + return SkNEW_ARGS(SkSurface_Raster, (pr)); }