1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/*
3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project
4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com *
5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be
6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file.
7ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com */
8ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRasterizer.h"
118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDraw.h"
128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkMaskFilter.h"
138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPath.h"
148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkRasterizer::rasterize(const SkPath& fillPath, const SkMatrix& matrix,
168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                             const SkIRect* clipBounds, SkMaskFilter* filter,
17fdba4041c350b72791a1844ff0bc0af28cbb4199reed@google.com                             SkMask* mask, SkMask::CreateMode mode) const {
188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkIRect storage;
19fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
20fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com    if (clipBounds && filter && SkMask::kJustRenderImage_CreateMode != mode) {
218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkIPoint    margin;
228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkMask      srcM, dstM;
23fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        srcM.fFormat = SkMask::kA8_Format;
258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        srcM.fBounds.set(0, 0, 1, 1);
26feb8cc870df055099c6fcdfebdd6c1486bd91b27reed@google.com        if (!filter->filterMask(&dstM, srcM, matrix, &margin)) {
278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            return false;
28feb8cc870df055099c6fcdfebdd6c1486bd91b27reed@google.com        }
2911fa2247b747eb75e2f158dc7571d458ed6c0115reed        storage = clipBounds->makeOutset(margin.fX, margin.fY);
308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        clipBounds = &storage;
318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
32fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    return this->onRasterize(fillPath, matrix, clipBounds, mask, mode);
348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/*  Our default implementation of the virtual method just scan converts
378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/
388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkRasterizer::onRasterize(const SkPath& fillPath, const SkMatrix& matrix,
398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                             const SkIRect* clipBounds,
40fdba4041c350b72791a1844ff0bc0af28cbb4199reed@google.com                             SkMask* mask, SkMask::CreateMode mode) const {
418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkPath  devPath;
42fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    fillPath.transform(matrix, &devPath);
4496fcdcc219d2a0d3579719b84b28bede76efba64halcanary    return SkDraw::DrawToMask(devPath, clipBounds, nullptr, nullptr, mask, mode,
452ac4ef5e6e0c9c95c9200408ba25a95ca758eac2junov@chromium.org                              SkPaint::kFill_Style);
468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
47