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 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 When the balancing call to restore() is made, the previous matrix, clip, | 351 When the balancing call to restore() is made, the previous matrix, clip, |
352 and drawFilter are restored. | 352 and drawFilter are restored. |
353 @param flags The flags govern what portion of the Matrix/Clip/drawFilter | 353 @param flags The flags govern what portion of the Matrix/Clip/drawFilter |
354 state the save (and matching restore) effect. For example, | 354 state the save (and matching restore) effect. For example, |
355 if only kMatrix is specified, then only the matrix state | 355 if only kMatrix is specified, then only the matrix state |
356 will be pushed and popped. Likewise for the clip if kClip | 356 will be pushed and popped. Likewise for the clip if kClip |
357 is specified. However, the drawFilter is always affected | 357 is specified. However, the drawFilter is always affected |
358 by calls to save/restore. | 358 by calls to save/restore. |
359 @return The value to pass to restoreToCount() to balance this save() | 359 @return The value to pass to restoreToCount() to balance this save() |
360 */ | 360 */ |
361 int save(SaveFlags flags = kMatrixClip_SaveFlag); | 361 virtual int save(SaveFlags flags = kMatrixClip_SaveFlag); |
362 | 362 |
363 /** This behaves the same as save(), but in addition it allocates an | 363 /** This behaves the same as save(), but in addition it allocates an |
364 offscreen bitmap. All drawing calls are directed there, and only when | 364 offscreen bitmap. All drawing calls are directed there, and only when |
365 the balancing call to restore() is made is that offscreen transfered to | 365 the balancing call to restore() is made is that offscreen transfered to |
366 the canvas (or the previous layer). | 366 the canvas (or the previous layer). |
367 @param bounds (may be null) This rect, if non-null, is used as a hint to | 367 @param bounds (may be null) This rect, if non-null, is used as a hint to |
368 limit the size of the offscreen, and thus drawing may be | 368 limit the size of the offscreen, and thus drawing may be |
369 clipped to it, though that clipping is not guaranteed to | 369 clipped to it, though that clipping is not guaranteed to |
370 happen. If exact clipping is desired, use clipRect(). | 370 happen. If exact clipping is desired, use clipRect(). |
371 @param paint (may be null) This is copied, and is applied to the | 371 @param paint (may be null) This is copied, and is applied to the |
372 offscreen when restore() is called | 372 offscreen when restore() is called |
373 @param flags LayerFlags | 373 @param flags LayerFlags |
374 @return The value to pass to restoreToCount() to balance this save() | 374 @return The value to pass to restoreToCount() to balance this save() |
375 */ | 375 */ |
376 int saveLayer(const SkRect* bounds, const SkPaint* paint, | 376 virtual int saveLayer(const SkRect* bounds, const SkPaint* paint, |
377 SaveFlags flags = kARGB_ClipLayer_SaveFlag); | 377 SaveFlags flags = kARGB_ClipLayer_SaveFlag); |
378 | 378 |
379 /** This behaves the same as save(), but in addition it allocates an | 379 /** This behaves the same as save(), but in addition it allocates an |
380 offscreen bitmap. All drawing calls are directed there, and only when | 380 offscreen bitmap. All drawing calls are directed there, and only when |
381 the balancing call to restore() is made is that offscreen transfered to | 381 the balancing call to restore() is made is that offscreen transfered to |
382 the canvas (or the previous layer). | 382 the canvas (or the previous layer). |
383 @param bounds (may be null) This rect, if non-null, is used as a hint to | 383 @param bounds (may be null) This rect, if non-null, is used as a hint to |
384 limit the size of the offscreen, and thus drawing may be | 384 limit the size of the offscreen, and thus drawing may be |
385 clipped to it, though that clipping is not guaranteed to | 385 clipped to it, though that clipping is not guaranteed to |
386 happen. If exact clipping is desired, use clipRect(). | 386 happen. If exact clipping is desired, use clipRect(). |
387 @param alpha This is applied to the offscreen when restore() is called. | 387 @param alpha This is applied to the offscreen when restore() is called. |
388 @param flags LayerFlags | 388 @param flags LayerFlags |
389 @return The value to pass to restoreToCount() to balance this save() | 389 @return The value to pass to restoreToCount() to balance this save() |
390 */ | 390 */ |
391 int saveLayerAlpha(const SkRect* bounds, U8CPU alpha, | 391 int saveLayerAlpha(const SkRect* bounds, U8CPU alpha, |
392 SaveFlags flags = kARGB_ClipLayer_SaveFlag); | 392 SaveFlags flags = kARGB_ClipLayer_SaveFlag); |
393 | 393 |
394 /** This call balances a previous call to save(), and is used to remove all | 394 /** This call balances a previous call to save(), and is used to remove all |
395 modifications to the matrix/clip/drawFilter state since the last save | 395 modifications to the matrix/clip/drawFilter state since the last save |
396 call. | 396 call. |
397 It is an error to call restore() more times than save() was called. | 397 It is an error to call restore() more times than save() was called. |
398 */ | 398 */ |
399 void restore(); | 399 virtual void restore(); |
400 | 400 |
401 /** Returns the number of matrix/clip states on the SkCanvas' private stack. | 401 /** Returns the number of matrix/clip states on the SkCanvas' private stack. |
402 This will equal # save() calls - # restore() calls + 1. The save count o
n | 402 This will equal # save() calls - # restore() calls + 1. The save count o
n |
403 a new canvas is 1. | 403 a new canvas is 1. |
404 */ | 404 */ |
405 int getSaveCount() const; | 405 int getSaveCount() const; |
406 | 406 |
407 /** Efficient way to pop any calls to save() that happened after the save | 407 /** Efficient way to pop any calls to save() that happened after the save |
408 count reached saveCount. It is an error for saveCount to be greater than | 408 count reached saveCount. It is an error for saveCount to be greater than |
409 getSaveCount(). To pop all the way back to the initial matrix/clip conte
xt | 409 getSaveCount(). To pop all the way back to the initial matrix/clip conte
xt |
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1171 // don't call | 1171 // don't call |
1172 void internal_private_getTotalClipAsPath(SkPath*) const; | 1172 void internal_private_getTotalClipAsPath(SkPath*) const; |
1173 | 1173 |
1174 protected: | 1174 protected: |
1175 // default impl defers to getDevice()->newSurface(info) | 1175 // default impl defers to getDevice()->newSurface(info) |
1176 virtual SkSurface* onNewSurface(const SkImageInfo&); | 1176 virtual SkSurface* onNewSurface(const SkImageInfo&); |
1177 | 1177 |
1178 // default impl defers to its device | 1178 // default impl defers to its device |
1179 virtual const void* onPeekPixels(SkImageInfo*, size_t* rowBytes); | 1179 virtual const void* onPeekPixels(SkImageInfo*, size_t* rowBytes); |
1180 | 1180 |
1181 // Subclass save/restore notifiers. These are called *before* updating the c
anvas state. | |
1182 // Overriders should call the corresponding INHERITED method up the inherita
nce chain. | |
1183 // For onSaveLayer(), returning false suppresses full layer allocation (and
forces | |
1184 // the base impl to only perform a state save + bounds clip). | |
1185 virtual void onSave(SaveFlags); | |
1186 virtual bool onSaveLayer(const SkRect*, const SkPaint*, SaveFlags); | |
1187 virtual void onRestore(); | |
1188 | |
1189 virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&); | 1181 virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&); |
1190 | 1182 |
1191 enum ClipEdgeStyle { | 1183 enum ClipEdgeStyle { |
1192 kHard_ClipEdgeStyle, | 1184 kHard_ClipEdgeStyle, |
1193 kSoft_ClipEdgeStyle | 1185 kSoft_ClipEdgeStyle |
1194 }; | 1186 }; |
1195 | 1187 |
1196 virtual void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle e
dgeStyle); | 1188 virtual void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle e
dgeStyle); |
1197 virtual void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyl
e edgeStyle); | 1189 virtual void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyl
e edgeStyle); |
1198 virtual void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle e
dgeStyle); | 1190 virtual void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle e
dgeStyle); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1278 // internal methods are not virtual, so they can safely be called by other | 1270 // internal methods are not virtual, so they can safely be called by other |
1279 // canvas apis, without confusing subclasses (like SkPictureRecording) | 1271 // canvas apis, without confusing subclasses (like SkPictureRecording) |
1280 void internalDrawBitmap(const SkBitmap&, const SkMatrix& m, const SkPaint* p
aint); | 1272 void internalDrawBitmap(const SkBitmap&, const SkMatrix& m, const SkPaint* p
aint); |
1281 void internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, | 1273 void internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, |
1282 const SkRect& dst, const SkPaint* paint, | 1274 const SkRect& dst, const SkPaint* paint, |
1283 DrawBitmapRectFlags flags); | 1275 DrawBitmapRectFlags flags); |
1284 void internalDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, | 1276 void internalDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, |
1285 const SkRect& dst, const SkPaint* paint); | 1277 const SkRect& dst, const SkPaint* paint); |
1286 void internalDrawPaint(const SkPaint& paint); | 1278 void internalDrawPaint(const SkPaint& paint); |
1287 int internalSaveLayer(const SkRect* bounds, const SkPaint* paint, | 1279 int internalSaveLayer(const SkRect* bounds, const SkPaint* paint, |
1288 SaveFlags, bool justForImageFilter, bool skipLayer); | 1280 SaveFlags, bool justForImageFilter); |
1289 void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*); | 1281 void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*); |
1290 | 1282 |
1291 // shared by save() and saveLayer() | 1283 // shared by save() and saveLayer() |
1292 int internalSave(SaveFlags flags); | 1284 int internalSave(SaveFlags flags); |
1293 void internalRestore(); | 1285 void internalRestore(); |
1294 static void DrawRect(const SkDraw& draw, const SkPaint& paint, | 1286 static void DrawRect(const SkDraw& draw, const SkPaint& paint, |
1295 const SkRect& r, SkScalar textSize); | 1287 const SkRect& r, SkScalar textSize); |
1296 static void DrawTextDecorations(const SkDraw& draw, const SkPaint& paint, | 1288 static void DrawTextDecorations(const SkDraw& draw, const SkPaint& paint, |
1297 const char text[], size_t byteLength, | 1289 const char text[], size_t byteLength, |
1298 SkScalar x, SkScalar y); | 1290 SkScalar x, SkScalar y); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1431 bool asROBitmap(SkBitmap*) const; | 1423 bool asROBitmap(SkBitmap*) const; |
1432 | 1424 |
1433 private: | 1425 private: |
1434 SkBitmap fBitmap; // used if peekPixels() fails | 1426 SkBitmap fBitmap; // used if peekPixels() fails |
1435 const void* fAddr; // NULL on failure | 1427 const void* fAddr; // NULL on failure |
1436 SkImageInfo fInfo; | 1428 SkImageInfo fInfo; |
1437 size_t fRowBytes; | 1429 size_t fRowBytes; |
1438 }; | 1430 }; |
1439 | 1431 |
1440 #endif | 1432 #endif |
OLD | NEW |