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 "SkRasterizer.h" 11 #include "SkDraw.h" 12 #include "SkMaskFilter.h" 13 #include "SkPath.h" 14 15 SK_DEFINE_INST_COUNT(SkRasterizer) 16 17 bool SkRasterizer::rasterize(const SkPath& fillPath, const SkMatrix& matrix, 18 const SkIRect* clipBounds, SkMaskFilter* filter, 19 SkMask* mask, SkMask::CreateMode mode) const { 20 SkIRect storage; 21 22 if (clipBounds && filter && SkMask::kJustRenderImage_CreateMode != mode) { 23 SkIPoint margin; 24 SkMask srcM, dstM; 25 26 srcM.fFormat = SkMask::kA8_Format; 27 srcM.fBounds.set(0, 0, 1, 1); 28 srcM.fImage = NULL; 29 if (!filter->filterMask(&dstM, srcM, matrix, &margin)) { 30 return false; 31 } 32 storage = *clipBounds; 33 storage.inset(-margin.fX, -margin.fY); 34 clipBounds = &storage; 35 } 36 37 return this->onRasterize(fillPath, matrix, clipBounds, mask, mode); 38 } 39 40 /* Our default implementation of the virtual method just scan converts 41 */ 42 bool SkRasterizer::onRasterize(const SkPath& fillPath, const SkMatrix& matrix, 43 const SkIRect* clipBounds, 44 SkMask* mask, SkMask::CreateMode mode) const { 45 SkPath devPath; 46 47 fillPath.transform(matrix, &devPath); 48 return SkDraw::DrawToMask(devPath, clipBounds, NULL, NULL, mask, mode, 49 SkPaint::kFill_Style); 50 } 51