blob: e2a27a8312c07634a9d01b36fb4d5f5cee8c33b0 [file] [log] [blame]
commit-bot@chromium.org1c4c9ef2013-08-07 00:07:51 +00001/*
2 * Copyright 2013 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
commit-bot@chromium.org1c4c9ef2013-08-07 00:07:51 +00008#include "SkComposeImageFilter.h"
robertphillips40736ab2016-03-08 12:05:37 -08009
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +000010#include "SkReadBuffer.h"
robertphillips40736ab2016-03-08 12:05:37 -080011#include "SkSpecialImage.h"
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +000012#include "SkWriteBuffer.h"
commit-bot@chromium.org1c4c9ef2013-08-07 00:07:51 +000013
commit-bot@chromium.org1c4c9ef2013-08-07 00:07:51 +000014
senorblancoe5e79842016-03-21 14:51:59 -070015SkRect SkComposeImageFilter::computeFastBounds(const SkRect& src) const {
robertphillips491fb172016-03-30 12:32:58 -070016 SkImageFilter* outer = this->getInput(0);
17 SkImageFilter* inner = this->getInput(1);
ajuma5788faa2015-02-13 09:05:47 -080018
senorblancoe5e79842016-03-21 14:51:59 -070019 return outer->computeFastBounds(inner->computeFastBounds(src));
ajuma5788faa2015-02-13 09:05:47 -080020}
21
robertphillips2302de92016-03-24 07:26:32 -070022sk_sp<SkSpecialImage> SkComposeImageFilter::onFilterImage(SkSpecialImage* source,
23 const Context& ctx,
24 SkIPoint* offset) const {
jbroman17a65202016-03-21 08:38:58 -070025 // The bounds passed to the inner filter must be filtered by the outer
26 // filter, so that the inner filter produces the pixels that the outer
27 // filter requires as input. This matters if the outer filter moves pixels.
28 SkIRect innerClipBounds;
robertphillips491fb172016-03-30 12:32:58 -070029 innerClipBounds = this->getInput(0)->filterBounds(ctx.clipBounds(), ctx.ctm());
jbroman17a65202016-03-21 08:38:58 -070030 Context innerContext(ctx.ctm(), innerClipBounds, ctx.cache());
ajuma5788faa2015-02-13 09:05:47 -080031 SkIPoint innerOffset = SkIPoint::Make(0, 0);
robertphillips2302de92016-03-24 07:26:32 -070032 sk_sp<SkSpecialImage> inner(this->filterInput(1, source, innerContext, &innerOffset));
robertphillips40736ab2016-03-08 12:05:37 -080033 if (!inner) {
34 return nullptr;
35 }
ajuma5788faa2015-02-13 09:05:47 -080036
37 SkMatrix outerMatrix(ctx.ctm());
38 outerMatrix.postTranslate(SkIntToScalar(-innerOffset.x()), SkIntToScalar(-innerOffset.y()));
senorblancodb64af32015-12-09 10:11:43 -080039 SkIRect clipBounds = ctx.clipBounds();
40 clipBounds.offset(-innerOffset.x(), -innerOffset.y());
reed4e23cda2016-01-11 10:56:59 -080041 Context outerContext(outerMatrix, clipBounds, ctx.cache());
robertphillips40736ab2016-03-08 12:05:37 -080042
43 SkIPoint outerOffset = SkIPoint::Make(0, 0);
robertphillips2302de92016-03-24 07:26:32 -070044 sk_sp<SkSpecialImage> outer(this->filterInput(0, inner.get(), outerContext, &outerOffset));
robertphillips40736ab2016-03-08 12:05:37 -080045 if (!outer) {
46 return nullptr;
ajuma5788faa2015-02-13 09:05:47 -080047 }
48
49 *offset = innerOffset + outerOffset;
robertphillips2302de92016-03-24 07:26:32 -070050 return outer;
commit-bot@chromium.org1c4c9ef2013-08-07 00:07:51 +000051}
52
senorblancoe5e79842016-03-21 14:51:59 -070053SkIRect SkComposeImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm,
54 MapDirection direction) const {
robertphillips40736ab2016-03-08 12:05:37 -080055 SkImageFilter* outer = this->getInput(0);
56 SkImageFilter* inner = this->getInput(1);
commit-bot@chromium.org1c4c9ef2013-08-07 00:07:51 +000057
senorblancoe5e79842016-03-21 14:51:59 -070058 return outer->filterBounds(inner->filterBounds(src, ctm, direction), ctm, direction);
commit-bot@chromium.org1c4c9ef2013-08-07 00:07:51 +000059}
60
reed9fa60da2014-08-21 07:59:51 -070061SkFlattenable* SkComposeImageFilter::CreateProc(SkReadBuffer& buffer) {
62 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 2);
robertphillips2238c9d2016-03-30 13:34:16 -070063 return SkComposeImageFilter::Make(common.getInput(0), common.getInput(1)).release();
reed9fa60da2014-08-21 07:59:51 -070064}
robertphillipsf3f5bad2014-12-19 13:49:15 -080065
66#ifndef SK_IGNORE_TO_STRING
67void SkComposeImageFilter::toString(SkString* str) const {
68 SkImageFilter* outer = getInput(0);
69 SkImageFilter* inner = getInput(1);
70
71 str->appendf("SkComposeImageFilter: (");
72
73 str->appendf("outer: ");
74 outer->toString(str);
75
76 str->appendf("inner: ");
77 inner->toString(str);
78
79 str->appendf(")");
80}
81#endif