| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkCanvas_DEFINED | 8 #ifndef SkCanvas_DEFINED |
| 9 #define SkCanvas_DEFINED | 9 #define SkCanvas_DEFINED |
| 10 | 10 |
| 11 #include "SkTypes.h" | 11 #include "SkTypes.h" |
| 12 #include "SkBitmap.h" | 12 #include "SkBitmap.h" |
| 13 #include "SkDeque.h" | 13 #include "SkDeque.h" |
| 14 #include "SkClipStack.h" | 14 #include "SkClipStack.h" |
| 15 #include "SkPaint.h" | 15 #include "SkPaint.h" |
| 16 #include "SkRefCnt.h" | 16 #include "SkRefCnt.h" |
| 17 #include "SkPath.h" | 17 #include "SkPath.h" |
| 18 #include "SkRegion.h" | 18 #include "SkRegion.h" |
| 19 #include "SkXfermode.h" | 19 #include "SkXfermode.h" |
| 20 | 20 |
| 21 //#define SK_SUPPORT_LEGACY_READPIXELSCONFIG |
| 22 |
| 21 // if not defined, we always assume ClipToLayer for saveLayer() | 23 // if not defined, we always assume ClipToLayer for saveLayer() |
| 22 //#define SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG | 24 //#define SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
| 23 | 25 |
| 24 | 26 |
| 25 //#define SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG | 27 //#define SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG |
| 26 //#define SK_SUPPORT_LEGACY_GETCLIPTYPE | 28 //#define SK_SUPPORT_LEGACY_GETCLIPTYPE |
| 27 //#define SK_SUPPORT_LEGACY_GETTOTALCLIP | 29 //#define SK_SUPPORT_LEGACY_GETTOTALCLIP |
| 28 //#define SK_SUPPORT_LEGACY_GETTOPDEVICE | 30 //#define SK_SUPPORT_LEGACY_GETTOPDEVICE |
| 29 | 31 |
| 30 class SkBounder; | 32 class SkBounder; |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 */ | 260 */ |
| 259 kBGRA_Premul_Config8888, | 261 kBGRA_Premul_Config8888, |
| 260 kBGRA_Unpremul_Config8888, | 262 kBGRA_Unpremul_Config8888, |
| 261 /** | 263 /** |
| 262 * low byte to high byte: R, G, B, A. | 264 * low byte to high byte: R, G, B, A. |
| 263 */ | 265 */ |
| 264 kRGBA_Premul_Config8888, | 266 kRGBA_Premul_Config8888, |
| 265 kRGBA_Unpremul_Config8888 | 267 kRGBA_Unpremul_Config8888 |
| 266 }; | 268 }; |
| 267 | 269 |
| 270 #ifdef SK_SUPPORT_LEGACY_READPIXELSCONFIG |
| 268 /** | 271 /** |
| 269 * On success (returns true), copy the canvas pixels into the bitmap. | 272 * On success (returns true), copy the canvas pixels into the bitmap. |
| 270 * On failure, the bitmap parameter is left unchanged and false is | 273 * On failure, the bitmap parameter is left unchanged and false is |
| 271 * returned. | 274 * returned. |
| 272 * | 275 * |
| 273 * The canvas' pixels are converted to the bitmap's config. The only | 276 * The canvas' pixels are converted to the bitmap's config. The only |
| 274 * supported config is kARGB_8888_Config, though this is likely to be | 277 * supported config is kARGB_8888_Config, though this is likely to be |
| 275 * relaxed in the future. The meaning of config kARGB_8888_Config is | 278 * relaxed in the future. The meaning of config kARGB_8888_Config is |
| 276 * modified by the enum param config8888. The default value interprets | 279 * modified by the enum param config8888. The default value interprets |
| 277 * kARGB_8888_Config as SkPMColor | 280 * kARGB_8888_Config as SkPMColor |
| (...skipping 16 matching lines...) Expand all Loading... |
| 294 * | 297 * |
| 295 * Example that reads the entire canvas into a bitmap using the native | 298 * Example that reads the entire canvas into a bitmap using the native |
| 296 * SkPMColor: | 299 * SkPMColor: |
| 297 * SkISize size = canvas->getDeviceSize(); | 300 * SkISize size = canvas->getDeviceSize(); |
| 298 * bitmap->setConfig(SkBitmap::kARGB_8888_Config, size.fWidth, | 301 * bitmap->setConfig(SkBitmap::kARGB_8888_Config, size.fWidth, |
| 299 * size.fHeight); | 302 * size.fHeight); |
| 300 * if (canvas->readPixels(bitmap, 0, 0)) { | 303 * if (canvas->readPixels(bitmap, 0, 0)) { |
| 301 * // use the pixels | 304 * // use the pixels |
| 302 * } | 305 * } |
| 303 */ | 306 */ |
| 304 bool readPixels(SkBitmap* bitmap, | 307 bool readPixels(SkBitmap* bitmap, int x, int y, Config8888 config8888); |
| 305 int x, int y, | 308 #endif |
| 306 Config8888 config8888 = kNative_Premul_Config8888); | |
| 307 | |
| 308 /** | |
| 309 * DEPRECATED: This will be removed as soon as webkit is no longer relying | |
| 310 * on it. The bitmap is resized to the intersection of srcRect and the | |
| 311 * canvas bounds. New pixels are always allocated on success. Bitmap is | |
| 312 * unmodified on failure. | |
| 313 */ | |
| 314 bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap); | |
| 315 | 309 |
| 316 #ifdef SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG | 310 #ifdef SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG |
| 317 /** | 311 /** |
| 318 * DEPRECATED | 312 * DEPRECATED |
| 319 * Similar to draw sprite, this method will copy the pixels in bitmap onto | 313 * Similar to draw sprite, this method will copy the pixels in bitmap onto |
| 320 * the canvas, with the top/left corner specified by (x, y). The canvas' | 314 * the canvas, with the top/left corner specified by (x, y). The canvas' |
| 321 * pixel values are completely replaced: there is no blending. | 315 * pixel values are completely replaced: there is no blending. |
| 322 * | 316 * |
| 323 * Currently if bitmap is backed by a texture this is a no-op. This may be | 317 * Currently if bitmap is backed by a texture this is a no-op. This may be |
| 324 * relaxed in the future. | 318 * relaxed in the future. |
| 325 * | 319 * |
| 326 * If the bitmap has config kARGB_8888_Config then the config8888 param | 320 * If the bitmap has config kARGB_8888_Config then the config8888 param |
| 327 * will determines how the pixel valuess are intepreted. If the bitmap is | 321 * will determines how the pixel valuess are intepreted. If the bitmap is |
| 328 * not kARGB_8888_Config then this parameter is ignored. | 322 * not kARGB_8888_Config then this parameter is ignored. |
| 329 * | 323 * |
| 330 * Note: If you are recording drawing commands on this canvas to | 324 * Note: If you are recording drawing commands on this canvas to |
| 331 * SkPicture, writePixels() is ignored! | 325 * SkPicture, writePixels() is ignored! |
| 332 */ | 326 */ |
| 333 void writePixels(const SkBitmap& bitmap, int x, int y, Config8888 config8888
); | 327 void writePixels(const SkBitmap& bitmap, int x, int y, Config8888 config8888
); |
| 334 #endif | 328 #endif |
| 335 | 329 |
| 336 /** | 330 /** |
| 331 * Copy the pixels from the base-layer into the specified buffer (pixels +
rowBytes), |
| 332 * converting them into the requested format (SkImageInfo). The base-layer
pixels are read |
| 333 * starting at the specified (x,y) location in the coordinate system of the
base-layer. |
| 334 * |
| 335 * The specified ImageInfo and (x,y) offset specifies a source rectangle |
| 336 * |
| 337 * srcR(x, y, info.width(), info.height()); |
| 338 * |
| 339 * SrcR is intersected with the bounds of the base-layer. If this intersect
ion is not empty, |
| 340 * then we have two sets of pixels (of equal size), the "src" specified by
base-layer at (x,y) |
| 341 * and the "dst" by info+pixels+rowBytes. Replace the dst pixels with the c
orresponding src |
| 342 * pixels, performing any colortype/alphatype transformations needed (in th
e case where the |
| 343 * src and dst have different colortypes or alphatypes). |
| 344 * |
| 345 * This call can fail, returning false, for several reasons: |
| 346 * - If the requested colortype/alphatype cannot be converted from the base
-layer's types. |
| 347 * - If this canvas is not backed by pixels (e.g. picture or PDF) |
| 348 */ |
| 349 bool readPixels(const SkImageInfo&, void* pixels, size_t rowBytes, int x, in
t y); |
| 350 |
| 351 /** |
| 352 * Helper for calling readPixels(info, ...). This call will check if bitmap
has been allocated. |
| 353 * If not, it will attempt to call allocPixels(). If this fails, it will re
turn false. If not, |
| 354 * it calls through to readPixels(info, ...) and returns its result. |
| 355 */ |
| 356 bool readPixels(SkBitmap* bitmap, int x, int y); |
| 357 |
| 358 /** |
| 359 * Helper for allocating pixels and then calling readPixels(info, ...). The
bitmap is resized |
| 360 * to the intersection of srcRect and the base-layer bounds. On success, pi
xels will be |
| 361 * allocated in bitmap and true returned. On failure, false is returned and
bitmap will be |
| 362 * set to empty. |
| 363 */ |
| 364 bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap); |
| 365 |
| 366 /** |
| 337 * This method affects the pixels in the base-layer, and operates in pixel
coordinates, | 367 * This method affects the pixels in the base-layer, and operates in pixel
coordinates, |
| 338 * ignoring the matrix and clip. | 368 * ignoring the matrix and clip. |
| 339 * | 369 * |
| 340 * The specified ImageInfo and (x,y) offset specifies a rectangle: target. | 370 * The specified ImageInfo and (x,y) offset specifies a rectangle: target. |
| 341 * | 371 * |
| 342 * target.setXYWH(x, y, info.width(), info.height()); | 372 * target.setXYWH(x, y, info.width(), info.height()); |
| 343 * | 373 * |
| 344 * Target is intersected with the bounds of the base-layer. If this interse
ction is not empty, | 374 * Target is intersected with the bounds of the base-layer. If this interse
ction is not empty, |
| 345 * then we have two sets of pixels (of equal size), the "src" specified by
info+pixels+rowBytes | 375 * then we have two sets of pixels (of equal size), the "src" specified by
info+pixels+rowBytes |
| 346 * and the "dst" by the canvas' backend. Replace the dst pixels with the co
rresponding src | 376 * and the "dst" by the canvas' backend. Replace the dst pixels with the co
rresponding src |
| (...skipping 1147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1494 bool asROBitmap(SkBitmap*) const; | 1524 bool asROBitmap(SkBitmap*) const; |
| 1495 | 1525 |
| 1496 private: | 1526 private: |
| 1497 SkBitmap fBitmap; // used if peekPixels() fails | 1527 SkBitmap fBitmap; // used if peekPixels() fails |
| 1498 const void* fAddr; // NULL on failure | 1528 const void* fAddr; // NULL on failure |
| 1499 SkImageInfo fInfo; | 1529 SkImageInfo fInfo; |
| 1500 size_t fRowBytes; | 1530 size_t fRowBytes; |
| 1501 }; | 1531 }; |
| 1502 | 1532 |
| 1503 #endif | 1533 #endif |
| OLD | NEW |