1
2/*
3 * Copyright 2006 The Android Open Source Project
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9
10#include "SkMaskFilter.h"
11#include "SkBlitter.h"
12#include "SkBounder.h"
13#include "SkBuffer.h"
14#include "SkDraw.h"
15#include "SkRasterClip.h"
16
17bool SkMaskFilter::filterMask(SkMask*, const SkMask&, const SkMatrix&,
18                              SkIPoint*) {
19    return false;
20}
21
22bool SkMaskFilter::filterPath(const SkPath& devPath, const SkMatrix& matrix,
23                              const SkRasterClip& clip, SkBounder* bounder,
24                              SkBlitter* blitter) {
25    SkMask  srcM, dstM;
26
27    if (!SkDraw::DrawToMask(devPath, &clip.getBounds(), this, &matrix, &srcM,
28                            SkMask::kComputeBoundsAndRenderImage_CreateMode)) {
29        return false;
30    }
31    SkAutoMaskFreeImage autoSrc(srcM.fImage);
32
33    if (!this->filterMask(&dstM, srcM, matrix, NULL)) {
34        return false;
35    }
36    SkAutoMaskFreeImage autoDst(dstM.fImage);
37
38    // if we get here, we need to (possibly) resolve the clip and blitter
39    SkAAClipBlitterWrapper wrapper(clip, blitter);
40    blitter = wrapper.getBlitter();
41
42    SkRegion::Cliperator clipper(wrapper.getRgn(), dstM.fBounds);
43
44    if (!clipper.done() && (bounder == NULL || bounder->doIRect(dstM.fBounds))) {
45        const SkIRect& cr = clipper.rect();
46        do {
47            blitter->blitMask(dstM, cr);
48            clipper.next();
49        } while (!clipper.done());
50    }
51
52    return true;
53}
54
55SkMaskFilter::BlurType SkMaskFilter::asABlur(BlurInfo*) const {
56    return kNone_BlurType;
57}
58
59void SkMaskFilter::computeFastBounds(const SkRect& src, SkRect* dst) {
60    SkMask  srcM, dstM;
61
62    srcM.fImage = NULL;
63    src.roundOut(&srcM.fBounds);
64    srcM.fRowBytes = 0;
65    srcM.fFormat = SkMask::kA8_Format;
66
67    SkIPoint margin;    // ignored
68    if (this->filterMask(&dstM, srcM, SkMatrix::I(), &margin)) {
69        dst->set(dstM.fBounds);
70    } else {
71        dst->set(srcM.fBounds);
72    }
73}
74
75
76