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

Unified Diff: src/core/SkCanvas.cpp

Issue 183533004: add SkCanvas::NewRaster factory -- a very common use-case in chrome (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 10 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/SkCanvas.h ('k') | tests/CanvasTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkCanvas.cpp
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 5ba6e8f6dc399c7c71fa8c858425ba826ddb6378..1c423e0840021ab1c1a100c4b8d9e7b3ca4396ab 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -2305,3 +2305,43 @@ int SkCanvas::LayerIter::y() const { return fImpl->getY(); }
///////////////////////////////////////////////////////////////////////////////
SkCanvas::ClipVisitor::~ClipVisitor() { }
+
+///////////////////////////////////////////////////////////////////////////////
+
+static bool supported_for_raster_canvas(const SkImageInfo& info) {
+ switch (info.alphaType()) {
+ case kPremul_SkAlphaType:
+ case kOpaque_SkAlphaType:
+ break;
+ default:
+ return false;
+ }
+
+ switch (info.colorType()) {
+ case kAlpha_8_SkColorType:
+ case kRGB_565_SkColorType:
+ case kPMColor_SkColorType:
+ break;
+ default:
+ return false;
+ }
+
+ return true;
+}
+
+SkCanvas* SkCanvas::NewRaster(const SkImageInfo& info) {
+ if (!supported_for_raster_canvas(info)) {
+ return NULL;
+ }
+
+ SkBitmap bitmap;
+ if (!bitmap.allocPixels(info)) {
+ return NULL;
+ }
+
+ // should this functionality be moved into allocPixels()?
+ if (!bitmap.info().isOpaque()) {
+ bitmap.eraseColor(0);
+ }
+ return SkNEW_ARGS(SkCanvas, (bitmap));
+}
« no previous file with comments | « include/core/SkCanvas.h ('k') | tests/CanvasTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698