Skip to content

Commit

Permalink
Use SkPaintFilterCanvas for paint filtering
Browse files Browse the repository at this point in the history
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
fmalita authored and Commit bot committed Jun 12, 2015
1 parent 5e0ab4d commit 36e307f
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 82 deletions.
39 changes: 21 additions & 18 deletions cc/output/software_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "cc/quads/solid_color_draw_quad.h"
#include "cc/quads/texture_draw_quad.h"
#include "cc/quads/tile_draw_quad.h"
#include "skia/ext/opacity_draw_filter.h"
#include "skia/ext/opacity_filter_canvas.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkImageFilter.h"
Expand Down Expand Up @@ -387,23 +387,26 @@ void SoftwareRenderer::DrawPictureQuad(const DrawingFrame* frame,
SkMatrix::kFill_ScaleToFit);
current_canvas_->concat(content_matrix);

// TODO(aelias): This isn't correct in all cases. We should detect these
// cases and fall back to a persistent bitmap backing
// (http://crbug.com/280374).
skia::RefPtr<SkDrawFilter> opacity_filter = skia::AdoptRef(
new skia::OpacityDrawFilter(quad->shared_quad_state->opacity,
frame->disable_picture_quad_image_filtering ||
quad->nearest_neighbor));
DCHECK(!current_canvas_->getDrawFilter());
current_canvas_->setDrawFilter(opacity_filter.get());

TRACE_EVENT0("cc",
"SoftwareRenderer::DrawPictureQuad");

quad->raster_source->PlaybackToSharedCanvas(
current_canvas_, quad->content_rect, quad->contents_scale);

current_canvas_->setDrawFilter(NULL);
const bool needs_transparency =
SkScalarRoundToInt(quad->shared_quad_state->opacity * 255) < 255;
const bool disable_image_filtering =
frame->disable_picture_quad_image_filtering || quad->nearest_neighbor;

TRACE_EVENT0("cc", "SoftwareRenderer::DrawPictureQuad");

if (needs_transparency || disable_image_filtering) {
// TODO(aelias): This isn't correct in all cases. We should detect these
// cases and fall back to a persistent bitmap backing
// (http://crbug.com/280374).
skia::OpacityFilterCanvas filtered_canvas(current_canvas_,
quad->shared_quad_state->opacity,
disable_image_filtering);
quad->raster_source->PlaybackToSharedCanvas(
&filtered_canvas, quad->content_rect, quad->contents_scale);
} else {
quad->raster_source->PlaybackToSharedCanvas(
current_canvas_, quad->content_rect, quad->contents_scale);
}
}

void SoftwareRenderer::DrawSolidColorQuad(const DrawingFrame* frame,
Expand Down
4 changes: 2 additions & 2 deletions skia/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ component("skia") {
"ext/google_logging.cc",
"ext/image_operations.cc",
"ext/image_operations.h",
"ext/opacity_draw_filter.cc",
"ext/opacity_draw_filter.h",
"ext/opacity_filter_canvas.cc",
"ext/opacity_filter_canvas.h",
"ext/pixel_ref_utils.cc",
"ext/pixel_ref_utils.h",
"ext/platform_canvas.cc",
Expand Down
27 changes: 0 additions & 27 deletions skia/ext/opacity_draw_filter.cc

This file was deleted.

33 changes: 0 additions & 33 deletions skia/ext/opacity_draw_filter.h

This file was deleted.

40 changes: 40 additions & 0 deletions skia/ext/opacity_filter_canvas.cc
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
38 changes: 38 additions & 0 deletions skia/ext/opacity_filter_canvas.h
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
4 changes: 2 additions & 2 deletions skia/skia_chrome.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
'ext/google_logging.cc',
'ext/image_operations.cc',
'ext/image_operations.h',
'ext/opacity_draw_filter.cc',
'ext/opacity_draw_filter.h',
'ext/opacity_filter_canvas.cc',
'ext/opacity_filter_canvas.h',
'ext/pixel_ref_utils.cc',
'ext/pixel_ref_utils.h',
'ext/platform_canvas.cc',
Expand Down

0 comments on commit 36e307f

Please sign in to comment.