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 13SkComposeImageFilter::~SkComposeImageFilter() { 14} 15 16void 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 25bool SkComposeImageFilter::onFilterImageDeprecated(Proxy* proxy, 26 const SkBitmap& src, 27 const Context& ctx, 28 SkBitmap* result, 29 SkIPoint* offset) const { 30 SkBitmap tmp; 31 SkIPoint innerOffset = SkIPoint::Make(0, 0); 32 SkIPoint outerOffset = SkIPoint::Make(0, 0); 33 if (!this->filterInputDeprecated(1, proxy, src, ctx, &tmp, &innerOffset)) 34 return false; 35 36 SkMatrix outerMatrix(ctx.ctm()); 37 outerMatrix.postTranslate(SkIntToScalar(-innerOffset.x()), SkIntToScalar(-innerOffset.y())); 38 SkIRect clipBounds = ctx.clipBounds(); 39 clipBounds.offset(-innerOffset.x(), -innerOffset.y()); 40 Context outerContext(outerMatrix, clipBounds, ctx.cache()); 41 if (!this->filterInputDeprecated(0, proxy, tmp, outerContext, result, &outerOffset)) { 42 return false; 43 } 44 45 *offset = innerOffset + outerOffset; 46 return true; 47} 48 49bool SkComposeImageFilter::onFilterBounds(const SkIRect& src, 50 const SkMatrix& ctm, 51 SkIRect* dst, 52 MapDirection direction) const { 53 SkImageFilter* outer = getInput(0); 54 SkImageFilter* inner = getInput(1); 55 56 SkIRect tmp; 57 return inner->filterBounds(src, ctm, &tmp, direction) && 58 outer->filterBounds(tmp, ctm, dst, direction); 59} 60 61SkFlattenable* SkComposeImageFilter::CreateProc(SkReadBuffer& buffer) { 62 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 2); 63 return SkComposeImageFilter::Create(common.getInput(0), common.getInput(1)); 64} 65 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 82