• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
8 #include "SkBitmap.h"
9 #include "SkComposeImageFilter.h"
10 #include "SkReadBuffer.h"
11 #include "SkWriteBuffer.h"
12 
~SkComposeImageFilter()13 SkComposeImageFilter::~SkComposeImageFilter() {
14 }
15 
computeFastBounds(const SkRect & src,SkRect * dst) const16 void SkComposeImageFilter::computeFastBounds(const SkRect& src, SkRect* dst) const {
17     SkImageFilter* outer = getInput(0);
18     SkImageFilter* inner = getInput(1);
19 
20     SkRect tmp;
21     inner->computeFastBounds(src, &tmp);
22     outer->computeFastBounds(tmp, dst);
23 }
24 
onFilterImage(Proxy * proxy,const SkBitmap & src,const Context & ctx,SkBitmap * result,SkIPoint * offset) const25 bool SkComposeImageFilter::onFilterImage(Proxy* proxy,
26                                          const SkBitmap& src,
27                                          const Context& ctx,
28                                          SkBitmap* result,
29                                          SkIPoint* offset) const {
30     SkImageFilter* outer = getInput(0);
31     SkImageFilter* inner = getInput(1);
32 
33     SkBitmap tmp;
34     SkIPoint innerOffset = SkIPoint::Make(0, 0);
35     SkIPoint outerOffset = SkIPoint::Make(0, 0);
36     if (!inner->filterImage(proxy, src, ctx, &tmp, &innerOffset))
37         return false;
38 
39     SkMatrix outerMatrix(ctx.ctm());
40     outerMatrix.postTranslate(SkIntToScalar(-innerOffset.x()), SkIntToScalar(-innerOffset.y()));
41     Context outerContext(outerMatrix, ctx.clipBounds(), ctx.cache());
42     if (!outer->filterImage(proxy, tmp, outerContext, result, &outerOffset)) {
43         return false;
44     }
45 
46     *offset = innerOffset + outerOffset;
47     return true;
48 }
49 
onFilterBounds(const SkIRect & src,const SkMatrix & ctm,SkIRect * dst) const50 bool SkComposeImageFilter::onFilterBounds(const SkIRect& src,
51                                           const SkMatrix& ctm,
52                                           SkIRect* dst) const {
53     SkImageFilter* outer = getInput(0);
54     SkImageFilter* inner = getInput(1);
55 
56     SkIRect tmp;
57     return inner->filterBounds(src, ctm, &tmp) && outer->filterBounds(tmp, ctm, dst);
58 }
59 
CreateProc(SkReadBuffer & buffer)60 SkFlattenable* SkComposeImageFilter::CreateProc(SkReadBuffer& buffer) {
61     SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 2);
62     return SkComposeImageFilter::Create(common.getInput(0), common.getInput(1));
63 }
64 
65 #ifndef SK_IGNORE_TO_STRING
toString(SkString * str) const66 void SkComposeImageFilter::toString(SkString* str) const {
67     SkImageFilter* outer = getInput(0);
68     SkImageFilter* inner = getInput(1);
69 
70     str->appendf("SkComposeImageFilter: (");
71 
72     str->appendf("outer: ");
73     outer->toString(str);
74 
75     str->appendf("inner: ");
76     inner->toString(str);
77 
78     str->appendf(")");
79 }
80 #endif
81