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 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 SK_ATTR_EXTERNALLY_DEPRECATED("SaveFlags use is deprecated") | 391 SK_ATTR_EXTERNALLY_DEPRECATED("SaveFlags use is deprecated") |
392 int saveLayerAlpha(const SkRect* bounds, U8CPU alpha, SaveFlags flags); | 392 int saveLayerAlpha(const SkRect* bounds, U8CPU alpha, SaveFlags flags); |
393 | 393 |
394 enum { | |
395 kIsOpaque_SaveLayerFlag = 1 << 0, | |
396 kPreserveLCDText_SaveLayerFlag = 1 << 1, | |
397 }; | |
398 typedef uint32_t SaveLayerFlags; | |
399 | |
400 struct SaveLayerRec { | |
401 SaveLayerRec() : fBounds(nullptr), fPaint(nullptr), fSaveLayerFlags(0) { } | |
402 SaveLayerRec(const SkRect* bounds, const SkPaint* paint, SaveLayerFlags saveLayerFlags = 0) | |
403 : fBounds(bounds) | |
404 , fPaint(paint) | |
405 , fSaveLayerFlags(saveLayerFlags) | |
406 {} | |
407 | |
408 const SkRect* fBounds; // optional | |
409 const SkPaint* fPaint; // optional | |
410 SaveLayerFlags fSaveLayerFlags; | |
411 }; | |
412 | |
413 int saveLayer(const SaveLayerRec&); | |
414 | |
394 /** This call balances a previous call to save(), and is used to remove all | 415 /** 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 | 416 modifications to the matrix/clip/drawFilter state since the last save |
396 call. | 417 call. |
397 It is an error to call restore() more times than save() was called. | 418 It is an error to call restore() more times than save() was called. |
398 */ | 419 */ |
399 void restore(); | 420 void restore(); |
400 | 421 |
401 /** Returns the number of matrix/clip states on the SkCanvas' private stack. | 422 /** 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 | 423 This will equal # save() calls - # restore() calls + 1. The save count o n |
403 a new canvas is 1. | 424 a new canvas is 1. |
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1213 | 1234 |
1214 // default impl defers to its device | 1235 // default impl defers to its device |
1215 virtual bool onPeekPixels(SkPixmap*); | 1236 virtual bool onPeekPixels(SkPixmap*); |
1216 virtual bool onAccessTopLayerPixels(SkPixmap*); | 1237 virtual bool onAccessTopLayerPixels(SkPixmap*); |
1217 | 1238 |
1218 // Subclass save/restore notifiers. | 1239 // Subclass save/restore notifiers. |
1219 // Overriders should call the corresponding INHERITED method up the inherita nce chain. | 1240 // Overriders should call the corresponding INHERITED method up the inherita nce chain. |
1220 // willSaveLayer()'s return value may suppress full layer allocation. | 1241 // willSaveLayer()'s return value may suppress full layer allocation. |
1221 enum SaveLayerStrategy { | 1242 enum SaveLayerStrategy { |
1222 kFullLayer_SaveLayerStrategy, | 1243 kFullLayer_SaveLayerStrategy, |
1223 kNoLayer_SaveLayerStrategy | 1244 kNoLayer_SaveLayerStrategy, |
1245 kCallLegacyMethod_SaveLayerStrategy, // TEMPORARY until we can remove legacy willSaveLayer | |
f(malita)
2015/12/17 20:48:59
no longer used?
reed1
2015/12/17 20:53:00
good catch, done.
| |
1224 }; | 1246 }; |
1225 | 1247 |
1226 virtual void willSave() {} | 1248 virtual void willSave() {} |
1249 #ifdef SK_SUPPORT_LEGACY_SAVELAYERPARAMS | |
1227 virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveF lags) { | 1250 virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveF lags) { |
1228 return kFullLayer_SaveLayerStrategy; | 1251 return kFullLayer_SaveLayerStrategy; |
1229 } | 1252 } |
1253 virtual SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&); | |
1254 #else | |
1255 virtual SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) { | |
1256 return kFullLayer_SaveLayerStrategy; | |
1257 } | |
1258 #endif | |
1230 virtual void willRestore() {} | 1259 virtual void willRestore() {} |
1231 virtual void didRestore() {} | 1260 virtual void didRestore() {} |
1232 virtual void didConcat(const SkMatrix&) {} | 1261 virtual void didConcat(const SkMatrix&) {} |
1233 virtual void didSetMatrix(const SkMatrix&) {} | 1262 virtual void didSetMatrix(const SkMatrix&) {} |
1234 | 1263 |
1235 virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&); | 1264 virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&); |
1236 | 1265 |
1237 virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, | 1266 virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, |
1238 SkScalar y, const SkPaint& paint); | 1267 SkScalar y, const SkPaint& paint); |
1239 | 1268 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1297 // Returns the canvas to be used by DrawIter. Default implementation | 1326 // Returns the canvas to be used by DrawIter. Default implementation |
1298 // returns this. Subclasses that encapsulate an indirect canvas may | 1327 // returns this. Subclasses that encapsulate an indirect canvas may |
1299 // need to overload this method. The impl must keep track of this, as it | 1328 // need to overload this method. The impl must keep track of this, as it |
1300 // is not released or deleted by the caller. | 1329 // is not released or deleted by the caller. |
1301 virtual SkCanvas* canvasForDrawIter(); | 1330 virtual SkCanvas* canvasForDrawIter(); |
1302 | 1331 |
1303 // Clip rectangle bounds. Called internally by saveLayer. | 1332 // Clip rectangle bounds. Called internally by saveLayer. |
1304 // returns false if the entire rectangle is entirely clipped out | 1333 // returns false if the entire rectangle is entirely clipped out |
1305 // If non-NULL, The imageFilter parameter will be used to expand the clip | 1334 // If non-NULL, The imageFilter parameter will be used to expand the clip |
1306 // and offscreen bounds for any margin required by the filter DAG. | 1335 // and offscreen bounds for any margin required by the filter DAG. |
1307 bool clipRectBounds(const SkRect* bounds, SaveFlags flags, | 1336 bool clipRectBounds(const SkRect* bounds, SaveLayerFlags, SkIRect* intersect ion, |
1308 SkIRect* intersection, | |
1309 const SkImageFilter* imageFilter = NULL); | 1337 const SkImageFilter* imageFilter = NULL); |
1310 | 1338 |
1311 private: | 1339 private: |
1312 enum PrivateSaveFlags { | 1340 enum PrivateSaveLayerFlags { |
1313 // These must not overlap the public flags. | 1341 kDontClipToLayer_PrivateSaveLayerFlag = 1 << 31, |
1314 kPreserveLCDText_PrivateSaveFlag = 1 << 5, | |
1315 }; | 1342 }; |
1316 | 1343 |
1344 static bool BoundsAffectsClip(SaveLayerFlags); | |
f(malita)
2015/12/17 20:48:59
If this is only used in SkCanvas.cpp, can we keep
reed1
2015/12/17 20:53:00
Needs access to private flag :(
| |
1345 static uint32_t SaveFlagsToSaveLayerFlags(SaveFlags); | |
1346 | |
1317 enum ShaderOverrideOpacity { | 1347 enum ShaderOverrideOpacity { |
1318 kNone_ShaderOverrideOpacity, //!< there is no overriding shader ( bitmap or image) | 1348 kNone_ShaderOverrideOpacity, //!< there is no overriding shader ( bitmap or image) |
1319 kOpaque_ShaderOverrideOpacity, //!< the overriding shader is opaque | 1349 kOpaque_ShaderOverrideOpacity, //!< the overriding shader is opaque |
1320 kNotOpaque_ShaderOverrideOpacity, //!< the overriding shader may not b e opaque | 1350 kNotOpaque_ShaderOverrideOpacity, //!< the overriding shader may not b e opaque |
1321 }; | 1351 }; |
1322 | 1352 |
1323 // notify our surface (if we have one) that we are about to draw, so it | 1353 // notify our surface (if we have one) that we are about to draw, so it |
1324 // can perform copy-on-write or invalidate any cached images | 1354 // can perform copy-on-write or invalidate any cached images |
1325 void predrawNotify(bool willOverwritesEntireSurface = false); | 1355 void predrawNotify(bool willOverwritesEntireSurface = false); |
1326 void predrawNotify(const SkRect* rect, const SkPaint* paint, ShaderOverrideO pacity); | 1356 void predrawNotify(const SkRect* rect, const SkPaint* paint, ShaderOverrideO pacity); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1366 | 1396 |
1367 friend class SkDrawIter; // needs setupDrawForLayerDevice() | 1397 friend class SkDrawIter; // needs setupDrawForLayerDevice() |
1368 friend class AutoDrawLooper; | 1398 friend class AutoDrawLooper; |
1369 friend class SkLua; // needs top layer size and offset | 1399 friend class SkLua; // needs top layer size and offset |
1370 friend class SkDebugCanvas; // needs experimental fAllowSimplifyClip | 1400 friend class SkDebugCanvas; // needs experimental fAllowSimplifyClip |
1371 friend class SkSurface_Raster; // needs getDevice() | 1401 friend class SkSurface_Raster; // needs getDevice() |
1372 friend class SkRecorder; // InitFlags | 1402 friend class SkRecorder; // InitFlags |
1373 friend class SkNoSaveLayerCanvas; // InitFlags | 1403 friend class SkNoSaveLayerCanvas; // InitFlags |
1374 friend class SkPictureImageFilter; // SkCanvas(SkBaseDevice*, SkSurfaceProp s*, InitFlags) | 1404 friend class SkPictureImageFilter; // SkCanvas(SkBaseDevice*, SkSurfaceProp s*, InitFlags) |
1375 friend class SkPictureRecord; // predrawNotify (why does it need it? <reed >) | 1405 friend class SkPictureRecord; // predrawNotify (why does it need it? <reed >) |
1406 friend class SkPicturePlayback; // SaveFlagsToSaveLayerFlags | |
1376 | 1407 |
1377 enum InitFlags { | 1408 enum InitFlags { |
1378 kDefault_InitFlags = 0, | 1409 kDefault_InitFlags = 0, |
1379 kConservativeRasterClip_InitFlag = 1 << 0, | 1410 kConservativeRasterClip_InitFlag = 1 << 0, |
1380 }; | 1411 }; |
1381 SkCanvas(const SkIRect& bounds, InitFlags); | 1412 SkCanvas(const SkIRect& bounds, InitFlags); |
1382 SkCanvas(SkBaseDevice* device, InitFlags); | 1413 SkCanvas(SkBaseDevice* device, InitFlags); |
1383 | 1414 |
1384 void resetForNextPicture(const SkIRect& bounds); | 1415 void resetForNextPicture(const SkIRect& bounds); |
1385 | 1416 |
(...skipping 11 matching lines...) Expand all Loading... | |
1397 * Gets the size/origin of the top level layer in global canvas coordinates. We don't want this | 1428 * Gets the size/origin of the top level layer in global canvas coordinates. We don't want this |
1398 * to be public because it exposes decisions about layer sizes that are inte rnal to the canvas. | 1429 * to be public because it exposes decisions about layer sizes that are inte rnal to the canvas. |
1399 */ | 1430 */ |
1400 SkISize getTopLayerSize() const; | 1431 SkISize getTopLayerSize() const; |
1401 SkIPoint getTopLayerOrigin() const; | 1432 SkIPoint getTopLayerOrigin() const; |
1402 | 1433 |
1403 void internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, | 1434 void internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, |
1404 const SkRect& dst, const SkPaint* paint, | 1435 const SkRect& dst, const SkPaint* paint, |
1405 SrcRectConstraint); | 1436 SrcRectConstraint); |
1406 void internalDrawPaint(const SkPaint& paint); | 1437 void internalDrawPaint(const SkPaint& paint); |
1407 void internalSaveLayer(const SkRect* bounds, const SkPaint*, SaveFlags, Save LayerStrategy); | 1438 void internalSaveLayer(const SaveLayerRec&, SaveLayerStrategy); |
1408 void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*, bool is BitmapDevice); | 1439 void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*, bool is BitmapDevice); |
1409 | 1440 |
1410 // shared by save() and saveLayer() | 1441 // shared by save() and saveLayer() |
1411 void internalSave(); | 1442 void internalSave(); |
1412 void internalRestore(); | 1443 void internalRestore(); |
1413 static void DrawRect(const SkDraw& draw, const SkPaint& paint, | 1444 static void DrawRect(const SkDraw& draw, const SkPaint& paint, |
1414 const SkRect& r, SkScalar textSize); | 1445 const SkRect& r, SkScalar textSize); |
1415 static void DrawTextDecorations(const SkDraw& draw, const SkPaint& paint, | 1446 static void DrawTextDecorations(const SkDraw& draw, const SkPaint& paint, |
1416 const char text[], size_t byteLength, | 1447 const char text[], size_t byteLength, |
1417 SkScalar x, SkScalar y); | 1448 SkScalar x, SkScalar y); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1563 | 1594 |
1564 class SkCanvasClipVisitor { | 1595 class SkCanvasClipVisitor { |
1565 public: | 1596 public: |
1566 virtual ~SkCanvasClipVisitor(); | 1597 virtual ~SkCanvasClipVisitor(); |
1567 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0; | 1598 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0; |
1568 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0; | 1599 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0; |
1569 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0; | 1600 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0; |
1570 }; | 1601 }; |
1571 | 1602 |
1572 #endif | 1603 #endif |
OLD | NEW |