1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
28a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/*
3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project
48a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.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.
78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */
88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
9ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkDraw_DEFINED
118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkDraw_DEFINED
128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkCanvas.h"
148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkMask.h"
158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPaint.h"
168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
17a9e1824e009015ef2a60491916780e96c220afb8tomhudson@google.comclass SkBitmap;
187d7ca79c3e6e6be7b7849b0d9a7fe26effb89c38reed@google.comclass SkClipStack;
191f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.comclass SkBaseDevice;
20a9e1824e009015ef2a60491916780e96c220afb8tomhudson@google.comclass SkMatrix;
218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkPath;
228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkRegion;
23045e62d715f5ee9b03deb5af3c750f8318096179reed@google.comclass SkRasterClip;
248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstruct SkDrawProcs;
25a9e1824e009015ef2a60491916780e96c220afb8tomhudson@google.comstruct SkRect;
26a8e33a92e27ca1523601226cad83c79a7e00c93bscroggo@google.comclass SkRRect;
278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkDraw {
298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
30f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com    SkDraw();
318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDraw(const SkDraw& src);
328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void    drawPaint(const SkPaint&) const;
348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void    drawPoints(SkCanvas::PointMode, size_t count, const SkPoint[],
35f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com                       const SkPaint&, bool forceUseDevice = false) const;
368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void    drawRect(const SkRect&, const SkPaint&) const;
37a8e33a92e27ca1523601226cad83c79a7e00c93bscroggo@google.com    void    drawRRect(const SkRRect&, const SkPaint&) const;
387ff8d81290c3d9d461f2e304f4fd7846275f956dreed@google.com    /**
397ff8d81290c3d9d461f2e304f4fd7846275f956dreed@google.com     *  To save on mallocs, we allow a flag that tells us that srcPath is
407ff8d81290c3d9d461f2e304f4fd7846275f956dreed@google.com     *  mutable, so that we don't have to make copies of it as we transform it.
417ff8d81290c3d9d461f2e304f4fd7846275f956dreed@google.com     *
427ff8d81290c3d9d461f2e304f4fd7846275f956dreed@google.com     *  If prePathMatrix is not null, it should logically be applied before any
437ff8d81290c3d9d461f2e304f4fd7846275f956dreed@google.com     *  stroking or other effects. If there are no effects on the paint that
447ff8d81290c3d9d461f2e304f4fd7846275f956dreed@google.com     *  affect the geometry/rasterization, then the pre matrix can just be
457ff8d81290c3d9d461f2e304f4fd7846275f956dreed@google.com     *  pre-concated with the current matrix.
467ff8d81290c3d9d461f2e304f4fd7846275f956dreed@google.com     */
47126f7f5244502c0cbf1e5fec1d2ad7a0f2eb6c34reed@google.com    void    drawPath(const SkPath& path, const SkPaint& paint,
48126f7f5244502c0cbf1e5fec1d2ad7a0f2eb6c34reed@google.com                     const SkMatrix* prePathMatrix, bool pathIsMutable) const {
49126f7f5244502c0cbf1e5fec1d2ad7a0f2eb6c34reed@google.com        this->drawPath(path, paint, prePathMatrix, pathIsMutable, false);
50126f7f5244502c0cbf1e5fec1d2ad7a0f2eb6c34reed@google.com    }
51126f7f5244502c0cbf1e5fec1d2ad7a0f2eb6c34reed@google.com
52126f7f5244502c0cbf1e5fec1d2ad7a0f2eb6c34reed@google.com    void drawPath(const SkPath& path, const SkPaint& paint) const {
53126f7f5244502c0cbf1e5fec1d2ad7a0f2eb6c34reed@google.com        this->drawPath(path, paint, NULL, false, false);
54126f7f5244502c0cbf1e5fec1d2ad7a0f2eb6c34reed@google.com    }
55126f7f5244502c0cbf1e5fec1d2ad7a0f2eb6c34reed@google.com
568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void    drawBitmap(const SkBitmap&, const SkMatrix&, const SkPaint&) const;
578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void    drawSprite(const SkBitmap&, int x, int y, const SkPaint&) const;
588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void    drawText(const char text[], size_t byteLength, SkScalar x,
598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     SkScalar y, const SkPaint& paint) const;
608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void    drawPosText(const char text[], size_t byteLength,
618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                        const SkScalar pos[], SkScalar constY,
628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                        int scalarsPerPosition, const SkPaint& paint) const;
638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void    drawTextOnPath(const char text[], size_t byteLength,
648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                        const SkPath&, const SkMatrix*, const SkPaint&) const;
658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void    drawVertices(SkCanvas::VertexMode mode, int count,
668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                         const SkPoint vertices[], const SkPoint textures[],
678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                         const SkColor colors[], SkXfermode* xmode,
688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                         const uint16_t indices[], int ptCount,
698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                         const SkPaint& paint) const;
707d7ca79c3e6e6be7b7849b0d9a7fe26effb89c38reed@google.com
71126f7f5244502c0cbf1e5fec1d2ad7a0f2eb6c34reed@google.com    /**
72126f7f5244502c0cbf1e5fec1d2ad7a0f2eb6c34reed@google.com     *  Overwrite the target with the path's coverage (i.e. its mask).
73126f7f5244502c0cbf1e5fec1d2ad7a0f2eb6c34reed@google.com     *  Will overwrite the entire device, so it need not be zero'd first.
74126f7f5244502c0cbf1e5fec1d2ad7a0f2eb6c34reed@google.com     *
75126f7f5244502c0cbf1e5fec1d2ad7a0f2eb6c34reed@google.com     *  Only device A8 is supported right now.
76126f7f5244502c0cbf1e5fec1d2ad7a0f2eb6c34reed@google.com     */
77126f7f5244502c0cbf1e5fec1d2ad7a0f2eb6c34reed@google.com    void drawPathCoverage(const SkPath& src, const SkPaint& paint) const {
78126f7f5244502c0cbf1e5fec1d2ad7a0f2eb6c34reed@google.com        this->drawPath(src, paint, NULL, false, true);
798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Helper function that creates a mask from a path and an optional maskfilter.
828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        Note however, that the resulting mask will not have been actually filtered,
838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        that must be done afterwards (by calling filterMask). The maskfilter is provided
848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        solely to assist in computing the mask's bounds (if the mode requests that).
858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    static bool DrawToMask(const SkPath& devPath, const SkIRect* clipBounds,
8730711b764be6bbb58caa30a0ac5d1474c894efe7reed@google.com                           const SkMaskFilter*, const SkMatrix* filterMatrix,
882ac4ef5e6e0c9c95c9200408ba25a95ca758eac2junov@chromium.org                           SkMask* mask, SkMask::CreateMode mode,
892ac4ef5e6e0c9c95c9200408ba25a95ca758eac2junov@chromium.org                           SkPaint::Style style);
908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
9162ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com    enum RectType {
9262ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com        kHair_RectType,
9362ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com        kFill_RectType,
9462ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com        kStroke_RectType,
9562ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com        kPath_RectType
9662ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com    };
9762ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com
9862ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com    /**
9962ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com     *  Based on the paint's style, strokeWidth, and the matrix, classify how
10062ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com     *  to draw the rect. If no special-case is available, returns
10162ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com     *  kPath_RectType.
10262ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com     *
10362ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com     *  Iff RectType == kStroke_RectType, then strokeSize is set to the device
10462ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com     *  width and height of the stroke.
10562ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com     */
10662ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com    static RectType ComputeRectType(const SkPaint&, const SkMatrix&,
10762ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com                                    SkPoint* strokeSize);
10862ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com
1098128d8c119382279918b90ad8d80ccb3aaebb8a0commit-bot@chromium.org    static bool ShouldDrawTextAsPaths(const SkPaint&, const SkMatrix&);
1108128d8c119382279918b90ad8d80ccb3aaebb8a0commit-bot@chromium.org    void        drawText_asPaths(const char text[], size_t byteLength,
1118128d8c119382279918b90ad8d80ccb3aaebb8a0commit-bot@chromium.org                                 SkScalar x, SkScalar y, const SkPaint&) const;
1128128d8c119382279918b90ad8d80ccb3aaebb8a0commit-bot@chromium.org    void        drawPosText_asPaths(const char text[], size_t byteLength,
1138128d8c119382279918b90ad8d80ccb3aaebb8a0commit-bot@chromium.org                                    const SkScalar pos[], SkScalar constY,
1148128d8c119382279918b90ad8d80ccb3aaebb8a0commit-bot@chromium.org                                    int scalarsPerPosition, const SkPaint&) const;
1155e00989a283111cef05bed8102e45c16651e43e4commit-bot@chromium.org
1165e00989a283111cef05bed8102e45c16651e43e4commit-bot@chromium.orgprivate:
1175e00989a283111cef05bed8102e45c16651e43e4commit-bot@chromium.org    void    drawDevMask(const SkMask& mask, const SkPaint&) const;
1185e00989a283111cef05bed8102e45c16651e43e4commit-bot@chromium.org    void    drawBitmapAsMask(const SkBitmap&, const SkPaint&) const;
119126f7f5244502c0cbf1e5fec1d2ad7a0f2eb6c34reed@google.com
120126f7f5244502c0cbf1e5fec1d2ad7a0f2eb6c34reed@google.com    void    drawPath(const SkPath&, const SkPaint&, const SkMatrix* preMatrix,
121126f7f5244502c0cbf1e5fec1d2ad7a0f2eb6c34reed@google.com                     bool pathIsMutable, bool drawCoverage) const;
1228f6ef4010f6835c5ce9ede180e50a6a58512a81eskia.committer@gmail.com
1234bbdeac58cc928dc66296bde3bd06e78070d96b7reed@google.com    /**
1244bbdeac58cc928dc66296bde3bd06e78070d96b7reed@google.com     *  Return the current clip bounds, in local coordinates, with slop to account
1254bbdeac58cc928dc66296bde3bd06e78070d96b7reed@google.com     *  for antialiasing or hairlines (i.e. device-bounds outset by 1, and then
1264bbdeac58cc928dc66296bde3bd06e78070d96b7reed@google.com     *  run through the inverse of the matrix).
1274bbdeac58cc928dc66296bde3bd06e78070d96b7reed@google.com     *
1284bbdeac58cc928dc66296bde3bd06e78070d96b7reed@google.com     *  If the matrix cannot be inverted, or the current clip is empty, return
1294bbdeac58cc928dc66296bde3bd06e78070d96b7reed@google.com     *  false and ignore bounds parameter.
1304bbdeac58cc928dc66296bde3bd06e78070d96b7reed@google.com     */
1314bbdeac58cc928dc66296bde3bd06e78070d96b7reed@google.com    bool SK_WARN_UNUSED_RESULT
1324bbdeac58cc928dc66296bde3bd06e78070d96b7reed@google.com    computeConservativeLocalClipBounds(SkRect* bounds) const;
1334024f32d99b63a599c544a49f526e53c25135159skia.committer@gmail.com
1348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
1358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    const SkBitmap* fBitmap;        // required
1368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    const SkMatrix* fMatrix;        // required
137045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com    const SkRegion* fClip;          // DEPRECATED
138045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com    const SkRasterClip* fRC;        // required
139f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com
1407d7ca79c3e6e6be7b7849b0d9a7fe26effb89c38reed@google.com    const SkClipStack* fClipStack;  // optional
1411f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com    SkBaseDevice*   fDevice;        // optional
1428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDrawProcs*    fProcs;         // optional
1438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_DEBUG
145f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com    void validate() const;
146f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com#else
147f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com    void validate() const {}
1488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
1498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
1508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
152