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 |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 When the balancing call to restore() is made, the previous matrix, clip, | 371 When the balancing call to restore() is made, the previous matrix, clip, |
372 and drawFilter are restored. | 372 and drawFilter are restored. |
373 @param flags The flags govern what portion of the Matrix/Clip/drawFilter | 373 @param flags The flags govern what portion of the Matrix/Clip/drawFilter |
374 state the save (and matching restore) effect. For example, | 374 state the save (and matching restore) effect. For example, |
375 if only kMatrix is specified, then only the matrix state | 375 if only kMatrix is specified, then only the matrix state |
376 will be pushed and popped. Likewise for the clip if kClip | 376 will be pushed and popped. Likewise for the clip if kClip |
377 is specified. However, the drawFilter is always affected | 377 is specified. However, the drawFilter is always affected |
378 by calls to save/restore. | 378 by calls to save/restore. |
379 @return The value to pass to restoreToCount() to balance this save() | 379 @return The value to pass to restoreToCount() to balance this save() |
380 */ | 380 */ |
381 virtual int save(SaveFlags flags = kMatrixClip_SaveFlag); | 381 int save(SaveFlags flags = kMatrixClip_SaveFlag); |
382 | 382 |
383 /** This behaves the same as save(), but in addition it allocates an | 383 /** This behaves the same as save(), but in addition it allocates an |
384 offscreen bitmap. All drawing calls are directed there, and only when | 384 offscreen bitmap. All drawing calls are directed there, and only when |
385 the balancing call to restore() is made is that offscreen transfered to | 385 the balancing call to restore() is made is that offscreen transfered to |
386 the canvas (or the previous layer). | 386 the canvas (or the previous layer). |
387 @param bounds (may be null) This rect, if non-null, is used as a hint to | 387 @param bounds (may be null) This rect, if non-null, is used as a hint to |
388 limit the size of the offscreen, and thus drawing may be | 388 limit the size of the offscreen, and thus drawing may be |
389 clipped to it, though that clipping is not guaranteed to | 389 clipped to it, though that clipping is not guaranteed to |
390 happen. If exact clipping is desired, use clipRect(). | 390 happen. If exact clipping is desired, use clipRect(). |
391 @param paint (may be null) This is copied, and is applied to the | 391 @param paint (may be null) This is copied, and is applied to the |
392 offscreen when restore() is called | 392 offscreen when restore() is called |
393 @param flags LayerFlags | 393 @param flags LayerFlags |
394 @return The value to pass to restoreToCount() to balance this save() | 394 @return The value to pass to restoreToCount() to balance this save() |
395 */ | 395 */ |
396 virtual int saveLayer(const SkRect* bounds, const SkPaint* paint, | 396 int saveLayer(const SkRect* bounds, const SkPaint* paint, |
397 SaveFlags flags = kARGB_ClipLayer_SaveFlag); | 397 SaveFlags flags = kARGB_ClipLayer_SaveFlag); |
398 | 398 |
399 /** This behaves the same as save(), but in addition it allocates an | 399 /** This behaves the same as save(), but in addition it allocates an |
400 offscreen bitmap. All drawing calls are directed there, and only when | 400 offscreen bitmap. All drawing calls are directed there, and only when |
401 the balancing call to restore() is made is that offscreen transfered to | 401 the balancing call to restore() is made is that offscreen transfered to |
402 the canvas (or the previous layer). | 402 the canvas (or the previous layer). |
403 @param bounds (may be null) This rect, if non-null, is used as a hint to | 403 @param bounds (may be null) This rect, if non-null, is used as a hint to |
404 limit the size of the offscreen, and thus drawing may be | 404 limit the size of the offscreen, and thus drawing may be |
405 clipped to it, though that clipping is not guaranteed to | 405 clipped to it, though that clipping is not guaranteed to |
406 happen. If exact clipping is desired, use clipRect(). | 406 happen. If exact clipping is desired, use clipRect(). |
407 @param alpha This is applied to the offscreen when restore() is called. | 407 @param alpha This is applied to the offscreen when restore() is called. |
408 @param flags LayerFlags | 408 @param flags LayerFlags |
409 @return The value to pass to restoreToCount() to balance this save() | 409 @return The value to pass to restoreToCount() to balance this save() |
410 */ | 410 */ |
411 int saveLayerAlpha(const SkRect* bounds, U8CPU alpha, | 411 int saveLayerAlpha(const SkRect* bounds, U8CPU alpha, |
412 SaveFlags flags = kARGB_ClipLayer_SaveFlag); | 412 SaveFlags flags = kARGB_ClipLayer_SaveFlag); |
413 | 413 |
414 /** This call balances a previous call to save(), and is used to remove all | 414 /** This call balances a previous call to save(), and is used to remove all |
415 modifications to the matrix/clip/drawFilter state since the last save | 415 modifications to the matrix/clip/drawFilter state since the last save |
416 call. | 416 call. |
417 It is an error to call restore() more times than save() was called. | 417 It is an error to call restore() more times than save() was called. |
418 */ | 418 */ |
419 virtual void restore(); | 419 void restore(); |
420 | 420 |
421 /** Returns the number of matrix/clip states on the SkCanvas' private stack. | 421 /** Returns the number of matrix/clip states on the SkCanvas' private stack. |
422 This will equal # save() calls - # restore() calls + 1. The save count o
n | 422 This will equal # save() calls - # restore() calls + 1. The save count o
n |
423 a new canvas is 1. | 423 a new canvas is 1. |
424 */ | 424 */ |
425 int getSaveCount() const; | 425 int getSaveCount() const; |
426 | 426 |
427 /** Efficient way to pop any calls to save() that happened after the save | 427 /** Efficient way to pop any calls to save() that happened after the save |
428 count reached saveCount. It is an error for saveCount to be greater than | 428 count reached saveCount. It is an error for saveCount to be greater than |
429 getSaveCount(). To pop all the way back to the initial matrix/clip conte
xt | 429 getSaveCount(). To pop all the way back to the initial matrix/clip conte
xt |
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1194 GrRenderTarget* internal_private_accessTopLayerRenderTarget(); | 1194 GrRenderTarget* internal_private_accessTopLayerRenderTarget(); |
1195 | 1195 |
1196 protected: | 1196 protected: |
1197 // default impl defers to getDevice()->newSurface(info) | 1197 // default impl defers to getDevice()->newSurface(info) |
1198 virtual SkSurface* onNewSurface(const SkImageInfo&); | 1198 virtual SkSurface* onNewSurface(const SkImageInfo&); |
1199 | 1199 |
1200 // default impl defers to its device | 1200 // default impl defers to its device |
1201 virtual const void* onPeekPixels(SkImageInfo*, size_t* rowBytes); | 1201 virtual const void* onPeekPixels(SkImageInfo*, size_t* rowBytes); |
1202 virtual void* onAccessTopLayerPixels(SkImageInfo*, size_t* rowBytes); | 1202 virtual void* onAccessTopLayerPixels(SkImageInfo*, size_t* rowBytes); |
1203 | 1203 |
| 1204 // Subclass save/restore notifiers. |
| 1205 // Overriders should call the corresponding INHERITED method up the inherita
nce chain. |
| 1206 // willSaveLayer()'s return value may suppress full layer allocation. |
| 1207 enum SaveLayerStrategy { |
| 1208 kFullLayer_SaveLayerStrategy, |
| 1209 kNoLayer_SaveLayerStrategy |
| 1210 }; |
| 1211 virtual void willSave(SaveFlags); |
| 1212 virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveF
lags); |
| 1213 virtual void willRestore(); |
| 1214 |
1204 virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&); | 1215 virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&); |
1205 | 1216 |
1206 enum ClipEdgeStyle { | 1217 enum ClipEdgeStyle { |
1207 kHard_ClipEdgeStyle, | 1218 kHard_ClipEdgeStyle, |
1208 kSoft_ClipEdgeStyle | 1219 kSoft_ClipEdgeStyle |
1209 }; | 1220 }; |
1210 | 1221 |
1211 virtual void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle e
dgeStyle); | 1222 virtual void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle e
dgeStyle); |
1212 virtual void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyl
e edgeStyle); | 1223 virtual void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyl
e edgeStyle); |
1213 virtual void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle e
dgeStyle); | 1224 virtual void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle e
dgeStyle); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1294 // internal methods are not virtual, so they can safely be called by other | 1305 // internal methods are not virtual, so they can safely be called by other |
1295 // canvas apis, without confusing subclasses (like SkPictureRecording) | 1306 // canvas apis, without confusing subclasses (like SkPictureRecording) |
1296 void internalDrawBitmap(const SkBitmap&, const SkMatrix& m, const SkPaint* p
aint); | 1307 void internalDrawBitmap(const SkBitmap&, const SkMatrix& m, const SkPaint* p
aint); |
1297 void internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, | 1308 void internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, |
1298 const SkRect& dst, const SkPaint* paint, | 1309 const SkRect& dst, const SkPaint* paint, |
1299 DrawBitmapRectFlags flags); | 1310 DrawBitmapRectFlags flags); |
1300 void internalDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, | 1311 void internalDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, |
1301 const SkRect& dst, const SkPaint* paint); | 1312 const SkRect& dst, const SkPaint* paint); |
1302 void internalDrawPaint(const SkPaint& paint); | 1313 void internalDrawPaint(const SkPaint& paint); |
1303 int internalSaveLayer(const SkRect* bounds, const SkPaint* paint, | 1314 int internalSaveLayer(const SkRect* bounds, const SkPaint* paint, |
1304 SaveFlags, bool justForImageFilter); | 1315 SaveFlags, bool justForImageFilter, SaveLayerStrategy
strategy); |
1305 void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*); | 1316 void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*); |
1306 | 1317 |
1307 // shared by save() and saveLayer() | 1318 // shared by save() and saveLayer() |
1308 int internalSave(SaveFlags flags); | 1319 int internalSave(SaveFlags flags); |
1309 void internalRestore(); | 1320 void internalRestore(); |
1310 static void DrawRect(const SkDraw& draw, const SkPaint& paint, | 1321 static void DrawRect(const SkDraw& draw, const SkPaint& paint, |
1311 const SkRect& r, SkScalar textSize); | 1322 const SkRect& r, SkScalar textSize); |
1312 static void DrawTextDecorations(const SkDraw& draw, const SkPaint& paint, | 1323 static void DrawTextDecorations(const SkDraw& draw, const SkPaint& paint, |
1313 const char text[], size_t byteLength, | 1324 const char text[], size_t byteLength, |
1314 SkScalar x, SkScalar y); | 1325 SkScalar x, SkScalar y); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1447 bool asROBitmap(SkBitmap*) const; | 1458 bool asROBitmap(SkBitmap*) const; |
1448 | 1459 |
1449 private: | 1460 private: |
1450 SkBitmap fBitmap; // used if peekPixels() fails | 1461 SkBitmap fBitmap; // used if peekPixels() fails |
1451 const void* fAddr; // NULL on failure | 1462 const void* fAddr; // NULL on failure |
1452 SkImageInfo fInfo; | 1463 SkImageInfo fInfo; |
1453 size_t fRowBytes; | 1464 size_t fRowBytes; |
1454 }; | 1465 }; |
1455 | 1466 |
1456 #endif | 1467 #endif |
OLD | NEW |