Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: include/core/SkCanvas.h

Issue 1533953002: change signature for virtual related to saveLayer, passing SaveLayerRec (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | include/private/SkRecords.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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,
1224 }; 1245 };
1225 1246
1226 virtual void willSave() {} 1247 virtual void willSave() {}
1248 #ifdef SK_SUPPORT_LEGACY_SAVELAYERPARAMS
1227 virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveF lags) { 1249 virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveF lags) {
1228 return kFullLayer_SaveLayerStrategy; 1250 return kFullLayer_SaveLayerStrategy;
1229 } 1251 }
1252 virtual SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&);
1253 #else
1254 virtual SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) {
f(malita) 2015/12/17 22:23:28 While reviewing the Chromium side of this CL, it o
reed1 2015/12/17 22:29:39 That is documented on the strategy enum, but I wil
1255 return kFullLayer_SaveLayerStrategy;
1256 }
1257 #endif
1230 virtual void willRestore() {} 1258 virtual void willRestore() {}
1231 virtual void didRestore() {} 1259 virtual void didRestore() {}
1232 virtual void didConcat(const SkMatrix&) {} 1260 virtual void didConcat(const SkMatrix&) {}
1233 virtual void didSetMatrix(const SkMatrix&) {} 1261 virtual void didSetMatrix(const SkMatrix&) {}
1234 1262
1235 virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&); 1263 virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&);
1236 1264
1237 virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, 1265 virtual void onDrawText(const void* text, size_t byteLength, SkScalar x,
1238 SkScalar y, const SkPaint& paint); 1266 SkScalar y, const SkPaint& paint);
1239 1267
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 // Returns the canvas to be used by DrawIter. Default implementation 1325 // Returns the canvas to be used by DrawIter. Default implementation
1298 // returns this. Subclasses that encapsulate an indirect canvas may 1326 // returns this. Subclasses that encapsulate an indirect canvas may
1299 // need to overload this method. The impl must keep track of this, as it 1327 // need to overload this method. The impl must keep track of this, as it
1300 // is not released or deleted by the caller. 1328 // is not released or deleted by the caller.
1301 virtual SkCanvas* canvasForDrawIter(); 1329 virtual SkCanvas* canvasForDrawIter();
1302 1330
1303 // Clip rectangle bounds. Called internally by saveLayer. 1331 // Clip rectangle bounds. Called internally by saveLayer.
1304 // returns false if the entire rectangle is entirely clipped out 1332 // returns false if the entire rectangle is entirely clipped out
1305 // If non-NULL, The imageFilter parameter will be used to expand the clip 1333 // 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. 1334 // and offscreen bounds for any margin required by the filter DAG.
1307 bool clipRectBounds(const SkRect* bounds, SaveFlags flags, 1335 bool clipRectBounds(const SkRect* bounds, SaveLayerFlags, SkIRect* intersect ion,
1308 SkIRect* intersection,
1309 const SkImageFilter* imageFilter = NULL); 1336 const SkImageFilter* imageFilter = NULL);
1310 1337
1311 private: 1338 private:
1312 enum PrivateSaveFlags { 1339 enum PrivateSaveLayerFlags {
1313 // These must not overlap the public flags. 1340 kDontClipToLayer_PrivateSaveLayerFlag = 1 << 31,
1314 kPreserveLCDText_PrivateSaveFlag = 1 << 5,
1315 }; 1341 };
1316 1342
1343 static bool BoundsAffectsClip(SaveLayerFlags);
1344 static uint32_t SaveFlagsToSaveLayerFlags(SaveFlags);
1345
1317 enum ShaderOverrideOpacity { 1346 enum ShaderOverrideOpacity {
1318 kNone_ShaderOverrideOpacity, //!< there is no overriding shader ( bitmap or image) 1347 kNone_ShaderOverrideOpacity, //!< there is no overriding shader ( bitmap or image)
1319 kOpaque_ShaderOverrideOpacity, //!< the overriding shader is opaque 1348 kOpaque_ShaderOverrideOpacity, //!< the overriding shader is opaque
1320 kNotOpaque_ShaderOverrideOpacity, //!< the overriding shader may not b e opaque 1349 kNotOpaque_ShaderOverrideOpacity, //!< the overriding shader may not b e opaque
1321 }; 1350 };
1322 1351
1323 // notify our surface (if we have one) that we are about to draw, so it 1352 // 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 1353 // can perform copy-on-write or invalidate any cached images
1325 void predrawNotify(bool willOverwritesEntireSurface = false); 1354 void predrawNotify(bool willOverwritesEntireSurface = false);
1326 void predrawNotify(const SkRect* rect, const SkPaint* paint, ShaderOverrideO pacity); 1355 void predrawNotify(const SkRect* rect, const SkPaint* paint, ShaderOverrideO pacity);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1366 1395
1367 friend class SkDrawIter; // needs setupDrawForLayerDevice() 1396 friend class SkDrawIter; // needs setupDrawForLayerDevice()
1368 friend class AutoDrawLooper; 1397 friend class AutoDrawLooper;
1369 friend class SkLua; // needs top layer size and offset 1398 friend class SkLua; // needs top layer size and offset
1370 friend class SkDebugCanvas; // needs experimental fAllowSimplifyClip 1399 friend class SkDebugCanvas; // needs experimental fAllowSimplifyClip
1371 friend class SkSurface_Raster; // needs getDevice() 1400 friend class SkSurface_Raster; // needs getDevice()
1372 friend class SkRecorder; // InitFlags 1401 friend class SkRecorder; // InitFlags
1373 friend class SkNoSaveLayerCanvas; // InitFlags 1402 friend class SkNoSaveLayerCanvas; // InitFlags
1374 friend class SkPictureImageFilter; // SkCanvas(SkBaseDevice*, SkSurfaceProp s*, InitFlags) 1403 friend class SkPictureImageFilter; // SkCanvas(SkBaseDevice*, SkSurfaceProp s*, InitFlags)
1375 friend class SkPictureRecord; // predrawNotify (why does it need it? <reed >) 1404 friend class SkPictureRecord; // predrawNotify (why does it need it? <reed >)
1405 friend class SkPicturePlayback; // SaveFlagsToSaveLayerFlags
1376 1406
1377 enum InitFlags { 1407 enum InitFlags {
1378 kDefault_InitFlags = 0, 1408 kDefault_InitFlags = 0,
1379 kConservativeRasterClip_InitFlag = 1 << 0, 1409 kConservativeRasterClip_InitFlag = 1 << 0,
1380 }; 1410 };
1381 SkCanvas(const SkIRect& bounds, InitFlags); 1411 SkCanvas(const SkIRect& bounds, InitFlags);
1382 SkCanvas(SkBaseDevice* device, InitFlags); 1412 SkCanvas(SkBaseDevice* device, InitFlags);
1383 1413
1384 void resetForNextPicture(const SkIRect& bounds); 1414 void resetForNextPicture(const SkIRect& bounds);
1385 1415
(...skipping 11 matching lines...) Expand all
1397 * Gets the size/origin of the top level layer in global canvas coordinates. We don't want this 1427 * 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. 1428 * to be public because it exposes decisions about layer sizes that are inte rnal to the canvas.
1399 */ 1429 */
1400 SkISize getTopLayerSize() const; 1430 SkISize getTopLayerSize() const;
1401 SkIPoint getTopLayerOrigin() const; 1431 SkIPoint getTopLayerOrigin() const;
1402 1432
1403 void internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, 1433 void internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
1404 const SkRect& dst, const SkPaint* paint, 1434 const SkRect& dst, const SkPaint* paint,
1405 SrcRectConstraint); 1435 SrcRectConstraint);
1406 void internalDrawPaint(const SkPaint& paint); 1436 void internalDrawPaint(const SkPaint& paint);
1407 void internalSaveLayer(const SkRect* bounds, const SkPaint*, SaveFlags, Save LayerStrategy); 1437 void internalSaveLayer(const SaveLayerRec&, SaveLayerStrategy);
1408 void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*, bool is BitmapDevice); 1438 void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*, bool is BitmapDevice);
1409 1439
1410 // shared by save() and saveLayer() 1440 // shared by save() and saveLayer()
1411 void internalSave(); 1441 void internalSave();
1412 void internalRestore(); 1442 void internalRestore();
1413 static void DrawRect(const SkDraw& draw, const SkPaint& paint, 1443 static void DrawRect(const SkDraw& draw, const SkPaint& paint,
1414 const SkRect& r, SkScalar textSize); 1444 const SkRect& r, SkScalar textSize);
1415 static void DrawTextDecorations(const SkDraw& draw, const SkPaint& paint, 1445 static void DrawTextDecorations(const SkDraw& draw, const SkPaint& paint,
1416 const char text[], size_t byteLength, 1446 const char text[], size_t byteLength,
1417 SkScalar x, SkScalar y); 1447 SkScalar x, SkScalar y);
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1563 1593
1564 class SkCanvasClipVisitor { 1594 class SkCanvasClipVisitor {
1565 public: 1595 public:
1566 virtual ~SkCanvasClipVisitor(); 1596 virtual ~SkCanvasClipVisitor();
1567 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0; 1597 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0;
1568 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0; 1598 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0;
1569 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0; 1599 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0;
1570 }; 1600 };
1571 1601
1572 #endif 1602 #endif
OLDNEW
« no previous file with comments | « no previous file | include/private/SkRecords.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698