forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use SkPaintFilterCanvas for paint filtering
SkDrawFilter is deprecated - convert its only Chromium client to SkPaintFilterCanvas. BUG=skia:3587 R=reed@google.com,robertphillips@google.com,enne@chromium.org CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel Review URL: https://codereview.chromium.org/1176393003 Cr-Commit-Position: refs/heads/master@{#334166}
- Loading branch information
Showing
7 changed files
with
103 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2015 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "skia/ext/opacity_filter_canvas.h" | ||
#include "third_party/skia/include/core/SkPaint.h" | ||
#include "third_party/skia/include/core/SkTLazy.h" | ||
|
||
namespace skia { | ||
|
||
OpacityFilterCanvas::OpacityFilterCanvas(SkCanvas* canvas, | ||
float opacity, | ||
bool disable_image_filtering) | ||
: INHERITED(canvas->imageInfo().width(), canvas->imageInfo().height()), | ||
alpha_(SkScalarRoundToInt(opacity * 255)), | ||
disable_image_filtering_(disable_image_filtering) { | ||
this->addCanvas(canvas); | ||
} | ||
|
||
void OpacityFilterCanvas::onFilterPaint(SkPaint* paint, Type) const { | ||
if (alpha_ < 255) | ||
paint->setAlpha(alpha_); | ||
|
||
if (disable_image_filtering_) | ||
paint->setFilterQuality(kNone_SkFilterQuality); | ||
} | ||
|
||
void OpacityFilterCanvas::onDrawPicture(const SkPicture* picture, | ||
const SkMatrix* matrix, | ||
const SkPaint* paint) { | ||
SkTLazy<SkPaint> filteredPaint; | ||
if (paint) { | ||
this->onFilterPaint(filteredPaint.set(*paint), kPicture_Type); | ||
} | ||
|
||
// Unfurl pictures in order to filter nested paints. | ||
this->SkCanvas::onDrawPicture(picture, matrix, filteredPaint.getMaybeNull()); | ||
} | ||
|
||
} // namespace skia |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2015 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef SKIA_EXT_OPACITY_FILTER_CANVAS_H | ||
#define SKIA_EXT_OPACITY_FILTER_CANVAS_H | ||
|
||
#include "third_party/skia/include/utils/SkPaintFilterCanvas.h" | ||
|
||
namespace skia { | ||
|
||
// This filter canvas allows setting an opacity on every draw call to a canvas, | ||
// and to disable image filtering. Note that the opacity setting is only | ||
// correct in very limited conditions: when there is only zero or one opaque, | ||
// nonlayer draw for every pixel in the surface. | ||
class SK_API OpacityFilterCanvas : public SkPaintFilterCanvas { | ||
public: | ||
OpacityFilterCanvas(SkCanvas* canvas, | ||
float opacity, | ||
bool disable_image_filtering); | ||
|
||
protected: | ||
void onFilterPaint(SkPaint* paint, Type type) const override; | ||
|
||
void onDrawPicture(const SkPicture* picture, | ||
const SkMatrix* matrix, | ||
const SkPaint* paint) override; | ||
|
||
private: | ||
typedef SkPaintFilterCanvas INHERITED; | ||
|
||
int alpha_; | ||
bool disable_image_filtering_; | ||
}; | ||
|
||
} // namespace skia | ||
|
||
#endif // SKIA_EXT_OPACITY_FILTER_CANVAS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters