NoSaveLayerCanvas now its own file

https://codereview.chromium.org/120553003/



git-svn-id: http://skia.googlecode.com/svn/trunk@12938 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
robertphillips@google.com 2014-01-07 16:08:04 +00:00
parent 9109e188c7
commit 81e8739a10
3 changed files with 64 additions and 41 deletions

View File

@ -47,6 +47,7 @@
'../include/utils/SkMatrix44.h',
'../include/utils/SkMeshUtils.h',
'../include/utils/SkNinePatch.h',
'../include/utils/SkNoSaveLayerCanvas.h',
'../include/utils/SkNWayCanvas.h',
'../include/utils/SkNullCanvas.h',
'../include/utils/SkParse.h',

View File

@ -0,0 +1,60 @@
/*
* Copyright 2014 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkNoSaveLayerCanvas_DEFINED
#define SkNoSaveLayerCanvas_DEFINED
#include "SkCanvas.h"
#include "SkRRect.h"
// The NoSaveLayerCanvas is used to play back SkPictures when the saveLayer
// functionality isn't required (e.g., during analysis of the draw calls).
// It also simplifies the clipping calls to only use rectangles.
class SkNoSaveLayerCanvas : public SkCanvas {
public:
SkNoSaveLayerCanvas(SkBaseDevice* device) : INHERITED(device) {}
// turn saveLayer() into save() for speed, should not affect correctness.
virtual int saveLayer(const SkRect* bounds,
const SkPaint* paint,
SaveFlags flags) SK_OVERRIDE {
// Like SkPictureRecord, we don't want to create layers, but we do need
// to respect the save and (possibly) its rect-clip.
int count = this->INHERITED::save(flags);
if (NULL != bounds) {
this->INHERITED::clipRectBounds(bounds, flags, NULL);
}
return count;
}
// disable aa for speed
virtual bool clipRect(const SkRect& rect,
SkRegion::Op op,
bool doAA) SK_OVERRIDE {
return this->INHERITED::clipRect(rect, op, false);
}
// for speed, just respect the bounds, and disable AA. May give us a few
// false positives and negatives.
virtual bool clipPath(const SkPath& path,
SkRegion::Op op,
bool doAA) SK_OVERRIDE {
return this->updateClipConservativelyUsingBounds(path.getBounds(), op,
path.isInverseFillType());
}
virtual bool clipRRect(const SkRRect& rrect,
SkRegion::Op op,
bool doAA) SK_OVERRIDE {
return this->updateClipConservativelyUsingBounds(rrect.getBounds(), op, false);
}
private:
typedef SkCanvas INHERITED;
};
#endif // SkNoSaveLayerCanvas_DEFINED

View File

@ -8,6 +8,7 @@
#include "SkBitmapDevice.h"
#include "SkCanvas.h"
#include "SkData.h"
#include "SkNoSaveLayerCanvas.h"
#include "SkPictureUtils.h"
#include "SkPixelRef.h"
#include "SkRRect.h"
@ -64,7 +65,7 @@ public:
}
virtual GrRenderTarget* accessRenderTarget() SK_OVERRIDE { return NULL; }
virtual bool filterTextFlags(const SkPaint& paint, TextFlags*) SK_OVERRIDE {
return true;
return false;
}
// TODO: allow this call to return failure, or move to SkBitmapDevice only.
virtual const SkBitmap& onAccessBitmap() SK_OVERRIDE {
@ -199,45 +200,6 @@ private:
typedef SkBaseDevice INHERITED;
};
class NoSaveLayerCanvas : public SkCanvas {
public:
NoSaveLayerCanvas(SkBaseDevice* device) : INHERITED(device) {}
// turn saveLayer() into save() for speed, should not affect correctness.
virtual int saveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags flags) SK_OVERRIDE {
// Like SkPictureRecord, we don't want to create layers, but we do need
// to respect the save and (possibly) its rect-clip.
int count = this->INHERITED::save(flags);
if (bounds) {
this->INHERITED::clipRectBounds(bounds, flags, NULL);
}
return count;
}
// disable aa for speed
virtual bool clipRect(const SkRect& rect, SkRegion::Op op,
bool doAA) SK_OVERRIDE {
return this->INHERITED::clipRect(rect, op, false);
}
// for speed, just respect the bounds, and disable AA. May give us a few
// false positives and negatives.
virtual bool clipPath(const SkPath& path, SkRegion::Op op,
bool doAA) SK_OVERRIDE {
return this->updateClipConservativelyUsingBounds(path.getBounds(), op, path.isInverseFillType());
}
virtual bool clipRRect(const SkRRect& rrect, SkRegion::Op op,
bool doAA) SK_OVERRIDE {
return this->updateClipConservativelyUsingBounds(rrect.getBounds(), op, false);
}
private:
typedef SkCanvas INHERITED;
};
SkData* SkPictureUtils::GatherPixelRefs(SkPicture* pict, const SkRect& area) {
if (NULL == pict) {
return NULL;
@ -254,7 +216,7 @@ SkData* SkPictureUtils::GatherPixelRefs(SkPicture* pict, const SkRect& area) {
PixelRefSet prset(&array);
GatherPixelRefDevice device(pict->width(), pict->height(), &prset);
NoSaveLayerCanvas canvas(&device);
SkNoSaveLayerCanvas canvas(&device);
canvas.clipRect(area, SkRegion::kIntersect_Op, false);
canvas.drawPicture(*pict);