180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/* 380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2006 The Android Open Source Project 480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be 680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file. 780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifndef SkDraw_DEFINED 1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SkDraw_DEFINED 1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkCanvas.h" 1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkMask.h" 1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkPaint.h" 1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 177839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenbergerclass SkBitmap; 1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkBounder; 1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkClipStack; 200a657bbc2c6fc9daf699942e023050536d5ec95fDerek Sollenbergerclass SkBaseDevice; 217839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenbergerclass SkMatrix; 2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkPath; 2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkRegion; 2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkRasterClip; 2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querustruct SkDrawProcs; 267839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenbergerstruct SkRect; 27910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenbergerclass SkRRect; 2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkDraw { 3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querupublic: 3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDraw(); 3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDraw(const SkDraw& src); 3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void drawPaint(const SkPaint&) const; 3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void drawPoints(SkCanvas::PointMode, size_t count, const SkPoint[], 3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkPaint&, bool forceUseDevice = false) const; 3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void drawRect(const SkRect&, const SkPaint&) const; 38910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger void drawRRect(const SkRRect&, const SkPaint&) const; 3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** 4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * To save on mallocs, we allow a flag that tells us that srcPath is 4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * mutable, so that we don't have to make copies of it as we transform it. 4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * If prePathMatrix is not null, it should logically be applied before any 4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * stroking or other effects. If there are no effects on the paint that 4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * affect the geometry/rasterization, then the pre matrix can just be 4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * pre-concated with the current matrix. 4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 48910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger void drawPath(const SkPath& path, const SkPaint& paint, 49910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger const SkMatrix* prePathMatrix, bool pathIsMutable) const { 50910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger this->drawPath(path, paint, prePathMatrix, pathIsMutable, false); 51910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger } 52910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger 53910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger void drawPath(const SkPath& path, const SkPaint& paint) const { 54910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger this->drawPath(path, paint, NULL, false, false); 55910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger } 56910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger 5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void drawBitmap(const SkBitmap&, const SkMatrix&, const SkPaint&) const; 5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void drawSprite(const SkBitmap&, int x, int y, const SkPaint&) const; 5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void drawText(const char text[], size_t byteLength, SkScalar x, 6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkScalar y, const SkPaint& paint) const; 6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void drawPosText(const char text[], size_t byteLength, 6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkScalar pos[], SkScalar constY, 6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int scalarsPerPosition, const SkPaint& paint) const; 6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void drawTextOnPath(const char text[], size_t byteLength, 6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkPath&, const SkMatrix*, const SkPaint&) const; 6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void drawVertices(SkCanvas::VertexMode mode, int count, 6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkPoint vertices[], const SkPoint textures[], 6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkColor colors[], SkXfermode* xmode, 6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const uint16_t indices[], int ptCount, 7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkPaint& paint) const; 7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 72910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger /** 73910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger * Overwrite the target with the path's coverage (i.e. its mask). 74910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger * Will overwrite the entire device, so it need not be zero'd first. 75910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger * 76910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger * Only device A8 is supported right now. 77910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger */ 78910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger void drawPathCoverage(const SkPath& src, const SkPaint& paint) const { 79910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger this->drawPath(src, paint, NULL, false, true); 8080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 8180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 8280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Helper function that creates a mask from a path and an optional maskfilter. 8380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru Note however, that the resulting mask will not have been actually filtered, 8480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru that must be done afterwards (by calling filterMask). The maskfilter is provided 8580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru solely to assist in computing the mask's bounds (if the mode requests that). 8680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 8780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru static bool DrawToMask(const SkPath& devPath, const SkIRect* clipBounds, 88363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger const SkMaskFilter*, const SkMatrix* filterMatrix, 8980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkMask* mask, SkMask::CreateMode mode, 9080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkPaint::Style style); 9180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 9280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru enum RectType { 9380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kHair_RectType, 9480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kFill_RectType, 9580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kStroke_RectType, 9680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kPath_RectType 9780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru }; 9880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 9980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** 10080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Based on the paint's style, strokeWidth, and the matrix, classify how 10180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * to draw the rect. If no special-case is available, returns 10280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * kPath_RectType. 10380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 10480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Iff RectType == kStroke_RectType, then strokeSize is set to the device 10580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * width and height of the stroke. 10680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 10780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru static RectType ComputeRectType(const SkPaint&, const SkMatrix&, 10880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkPoint* strokeSize); 10980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 11080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void drawText_asPaths(const char text[], size_t byteLength, 11180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkScalar x, SkScalar y, const SkPaint&) const; 11258190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger void drawPosText_asPaths(const char text[], size_t byteLength, 11358190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger const SkScalar pos[], SkScalar constY, 11458190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger int scalarsPerPosition, const SkPaint&) const; 11558190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger 1160a657bbc2c6fc9daf699942e023050536d5ec95fDerek Sollenbergerprivate: 1170a657bbc2c6fc9daf699942e023050536d5ec95fDerek Sollenberger void drawDevMask(const SkMask& mask, const SkPaint&) const; 1180a657bbc2c6fc9daf699942e023050536d5ec95fDerek Sollenberger void drawBitmapAsMask(const SkBitmap&, const SkPaint&) const; 119910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger 120910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger void drawPath(const SkPath&, const SkPaint&, const SkMatrix* preMatrix, 121910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger bool pathIsMutable, bool drawCoverage) const; 1220a657bbc2c6fc9daf699942e023050536d5ec95fDerek Sollenberger 123d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger /** 124d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger * Return the current clip bounds, in local coordinates, with slop to account 125d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger * for antialiasing or hairlines (i.e. device-bounds outset by 1, and then 126d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger * run through the inverse of the matrix). 127d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger * 128d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger * If the matrix cannot be inverted, or the current clip is empty, return 129d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger * false and ignore bounds parameter. 130d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger */ 131d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger bool SK_WARN_UNUSED_RESULT 132d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger computeConservativeLocalClipBounds(SkRect* bounds) const; 133d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger 13458190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger static bool ShouldDrawTextAsPaths(const SkPaint&, const SkMatrix&); 13558190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger 13680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querupublic: 13780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkBitmap* fBitmap; // required 13880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkMatrix* fMatrix; // required 13980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkRegion* fClip; // DEPRECATED 14080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkRasterClip* fRC; // required 14180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 14280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkClipStack* fClipStack; // optional 1430a657bbc2c6fc9daf699942e023050536d5ec95fDerek Sollenberger SkBaseDevice* fDevice; // optional 14480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkBounder* fBounder; // optional 14580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDrawProcs* fProcs; // optional 14680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 14780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifdef SK_DEBUG 14880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void validate() const; 14980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#else 15080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void validate() const {} 15180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 15280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}; 15380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 15480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 155