diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-02-27 20:32:51 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-02-27 20:32:51 +0000 |
commit | 3107b6a85eee7914b37382f7145ab658e8c27667 (patch) | |
tree | 5aa215f98c7ff70d3d95e829a4bfc1fcb20e93c6 /include | |
parent | 4fcc3ca4112754f99a7d94b07e8ebbb0cb8c09ea (diff) |
add SkCanvas::NewRaster factory -- a very common use-case in chrome
BUG=skia:
R=scroggo@google.com
Author: reed@google.com
Review URL: https://codereview.chromium.org/183533004
git-svn-id: http://skia.googlecode.com/svn/trunk@13617 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include')
-rw-r--r-- | include/core/SkCanvas.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h index 8cc8bc9eb7..b73a1e48ca 100644 --- a/include/core/SkCanvas.h +++ b/include/core/SkCanvas.h @@ -49,6 +49,35 @@ public: SK_DECLARE_INST_COUNT(SkCanvas) /** + * Attempt to allocate an offscreen raster canvas, matching the ImageInfo. + * On success, return a new canvas that will draw into that offscreen. + * + * The caller can access the pixels after drawing into this canvas by + * calling readPixels() or peekPixels(). + * + * If the requested ImageInfo is opaque (either the colortype is + * intrinsically opaque like RGB_565, or the info's alphatype is kOpaque) + * then the pixel memory may be uninitialized. Otherwise, the pixel memory + * will be initialized to 0, which is interpreted as transparent. + * + * On failure, return NULL. This can fail for several reasons: + * 1. the memory allocation failed (e.g. request is too large) + * 2. invalid ImageInfo (e.g. negative dimensions) + * 3. unsupported ImageInfo for a canvas + * - kUnknown_SkColorType, kIndex_8_SkColorType + * - kIgnore_SkAlphaType + * - this list is not complete, so others may also be unsupported + * + * Note: it is valid to request a supported ImageInfo, but with zero + * dimensions. + */ + static SkCanvas* NewRaster(const SkImageInfo&); + + static SkCanvas* NewRasterN32(int width, int height) { + return NewRaster(SkImageInfo::MakeN32Premul(width, height)); + } + + /** * Creates an empty canvas with no backing device/pixels, and zero * dimensions. */ |