181e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.com/*
281e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.com * Copyright 2014 Google Inc.
381e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.com *
481e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.com * Use of this source code is governed by a BSD-style license that can be
581e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.com * found in the LICENSE file.
681e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.com */
781e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.com
881e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.com#ifndef SkNoSaveLayerCanvas_DEFINED
981e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.com#define SkNoSaveLayerCanvas_DEFINED
1081e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.com
1181e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.com#include "SkCanvas.h"
1281e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.com#include "SkRRect.h"
1381e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.com
1481e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.com// The NoSaveLayerCanvas is used to play back SkPictures when the saveLayer
1581e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.com// functionality isn't required (e.g., during analysis of the draw calls).
1681e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.com// It also simplifies the clipping calls to only use rectangles.
170f03f43e44d94b3aaf679edc8a6a41de4012fdf5robertphillips@google.comclass SK_API SkNoSaveLayerCanvas : public SkCanvas {
1881e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.compublic:
1981e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.com    SkNoSaveLayerCanvas(SkBaseDevice* device) : INHERITED(device) {}
2081e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.com
21e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.orgprotected:
22e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    virtual SaveLayerStrategy willSaveLayer(const SkRect* bounds, const SkPaint* paint,
23e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org                                            SaveFlags flags) SK_OVERRIDE {
24e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org        this->INHERITED::willSaveLayer(bounds, paint, flags);
25e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org        return kNoLayer_SaveLayerStrategy;
2681e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.com    }
2781e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.com
2881e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.com    // disable aa for speed
298f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle) SK_OVERRIDE {
308f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com        this->INHERITED::onClipRect(rect, op, kHard_ClipEdgeStyle);
3181e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.com    }
3281e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.com
3381e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.com    // for speed, just respect the bounds, and disable AA. May give us a few
3481e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.com    // false positives and negatives.
358f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle) SK_OVERRIDE {
368f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com        this->updateClipConservativelyUsingBounds(path.getBounds(), op,
378f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com                                                  path.isInverseFillType());
3881e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.com    }
398f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle) SK_OVERRIDE {
408f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com        this->updateClipConservativelyUsingBounds(rrect.getBounds(), op, false);
4181e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.com    }
4281e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.com
4381e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.comprivate:
4481e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.com    typedef SkCanvas INHERITED;
4581e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.com};
4681e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.com
4781e8739a101ecb0a978850bd45842bc6e6bc05a6robertphillips@google.com#endif // SkNoSaveLayerCanvas_DEFINED
48