blob: 60fad87237b91818a7517abea5abd4076432aac2 [file] [log] [blame]
robertphillips@google.com81e87392014-01-07 16:08:04 +00001/*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkNoSaveLayerCanvas_DEFINED
9#define SkNoSaveLayerCanvas_DEFINED
10
11#include "SkCanvas.h"
12#include "SkRRect.h"
13
14// The NoSaveLayerCanvas is used to play back SkPictures when the saveLayer
15// functionality isn't required (e.g., during analysis of the draw calls).
16// It also simplifies the clipping calls to only use rectangles.
17class SkNoSaveLayerCanvas : public SkCanvas {
18public:
19 SkNoSaveLayerCanvas(SkBaseDevice* device) : INHERITED(device) {}
20
commit-bot@chromium.org069a55a2014-03-12 15:08:22 +000021 // turn saveLayer() into save() for speed, should not affect correctness.
22 virtual int saveLayer(const SkRect* bounds,
23 const SkPaint* paint,
24 SaveFlags flags) SK_OVERRIDE {
25
26 // Like SkPictureRecord, we don't want to create layers, but we do need
27 // to respect the save and (possibly) its rect-clip.
28 int count = this->INHERITED::save(flags);
29 if (NULL != bounds) {
30 this->INHERITED::clipRectBounds(bounds, flags, NULL);
31 }
32 return count;
robertphillips@google.com81e87392014-01-07 16:08:04 +000033 }
34
commit-bot@chromium.org069a55a2014-03-12 15:08:22 +000035protected:
robertphillips@google.com81e87392014-01-07 16:08:04 +000036 // disable aa for speed
robertphillips@google.com8f90a892014-02-28 18:19:39 +000037 virtual void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle) SK_OVERRIDE {
38 this->INHERITED::onClipRect(rect, op, kHard_ClipEdgeStyle);
robertphillips@google.com81e87392014-01-07 16:08:04 +000039 }
40
41 // for speed, just respect the bounds, and disable AA. May give us a few
42 // false positives and negatives.
robertphillips@google.com8f90a892014-02-28 18:19:39 +000043 virtual void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle) SK_OVERRIDE {
44 this->updateClipConservativelyUsingBounds(path.getBounds(), op,
45 path.isInverseFillType());
robertphillips@google.com81e87392014-01-07 16:08:04 +000046 }
robertphillips@google.com8f90a892014-02-28 18:19:39 +000047 virtual void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle) SK_OVERRIDE {
48 this->updateClipConservativelyUsingBounds(rrect.getBounds(), op, false);
robertphillips@google.com81e87392014-01-07 16:08:04 +000049 }
50
51private:
52 typedef SkCanvas INHERITED;
53};
54
55#endif // SkNoSaveLayerCanvas_DEFINED