1cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger/*
2cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger * Copyright (C) 2014 The Android Open Source Project
3cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger *
4cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger * Licensed under the Apache License, Version 2.0 (the "License");
5cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger * you may not use this file except in compliance with the License.
6cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger * You may obtain a copy of the License at
7cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger *
8cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger *      http://www.apache.org/licenses/LICENSE-2.0
9cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger *
10cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger * Unless required by applicable law or agreed to in writing, software
11cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger * distributed under the License is distributed on an "AS IS" BASIS,
12cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger * See the License for the specific language governing permissions and
14cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger * limitations under the License.
15cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger */
16cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger
17cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger#ifndef ANDROID_GRAPHICS_CANVAS_H
18cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger#define ANDROID_GRAPHICS_CANVAS_H
19cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger
20849911a9c4315fc552faa38516c842b2541b1909John Reck#include <cutils/compiler.h>
216f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger#include <utils/Functor.h>
22849911a9c4315fc552faa38516c842b2541b1909John Reck
23cd1c3eba69d044b551cededad75474038f919890John Reck#include "GlFunctorLifecycleListener.h"
244c5efe9290543b723b76a8bd48518da1ae1dcb26Derek Sollenberger#include "utils/NinePatch.h"
254c5efe9290543b723b76a8bd48518da1ae1dcb26Derek Sollenberger
26849911a9c4315fc552faa38516c842b2541b1909John Reck#include <SkBitmap.h>
27849911a9c4315fc552faa38516c842b2541b1909John Reck#include <SkCanvas.h>
28849911a9c4315fc552faa38516c842b2541b1909John Reck#include <SkMatrix.h>
29cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger
30cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenbergernamespace android {
31cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger
326f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenbergernamespace uirenderer {
336f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger    class CanvasPropertyPaint;
346f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger    class CanvasPropertyPrimitive;
356f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger    class DeferredLayerUpdater;
366f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger    class DisplayList;
376f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger    class RenderNode;
386f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger}
396f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger
40eecff56fed5dd5206acfbc5007b4912081b36d3bFlorin Malitanamespace SaveFlags {
41eecff56fed5dd5206acfbc5007b4912081b36d3bFlorin Malita
42eecff56fed5dd5206acfbc5007b4912081b36d3bFlorin Malita// These must match the corresponding Canvas API constants.
43eecff56fed5dd5206acfbc5007b4912081b36d3bFlorin Malitaenum {
44eecff56fed5dd5206acfbc5007b4912081b36d3bFlorin Malita    Matrix        = 0x01,
45eecff56fed5dd5206acfbc5007b4912081b36d3bFlorin Malita    Clip          = 0x02,
46eecff56fed5dd5206acfbc5007b4912081b36d3bFlorin Malita    HasAlphaLayer = 0x04,
47eecff56fed5dd5206acfbc5007b4912081b36d3bFlorin Malita    ClipToLayer   = 0x10,
48eecff56fed5dd5206acfbc5007b4912081b36d3bFlorin Malita
49eecff56fed5dd5206acfbc5007b4912081b36d3bFlorin Malita    // Helper constant
50eecff56fed5dd5206acfbc5007b4912081b36d3bFlorin Malita    MatrixClip    = Matrix | Clip,
51eecff56fed5dd5206acfbc5007b4912081b36d3bFlorin Malita};
52eecff56fed5dd5206acfbc5007b4912081b36d3bFlorin Malitatypedef uint32_t Flags;
53eecff56fed5dd5206acfbc5007b4912081b36d3bFlorin Malita
54eecff56fed5dd5206acfbc5007b4912081b36d3bFlorin Malita} // namespace SaveFlags
55eecff56fed5dd5206acfbc5007b4912081b36d3bFlorin Malita
56766431aa57c16ece8842287a92b2e7208e3b8ac3Doris Liunamespace uirenderer {
5779abbf22d4f672208327546661e694d837f564a9Derek Sollenbergerclass SkiaCanvasProxy;
58766431aa57c16ece8842287a92b2e7208e3b8ac3Doris Liunamespace VectorDrawable {
59766431aa57c16ece8842287a92b2e7208e3b8ac3Doris Liuclass Tree;
60766431aa57c16ece8842287a92b2e7208e3b8ac3Doris Liu};
61766431aa57c16ece8842287a92b2e7208e3b8ac3Doris Liu};
62766431aa57c16ece8842287a92b2e7208e3b8ac3Doris Liutypedef uirenderer::VectorDrawable::Tree VectorDrawableRoot;
63766431aa57c16ece8842287a92b2e7208e3b8ac3Doris Liu
64dccca44ffda4836b56a21da95a046c9708ffd49csergeyvclass Paint;
65bad99183916ba2bac6659efc8a28273e344ba511sergeyvstruct Typeface;
66dccca44ffda4836b56a21da95a046c9708ffd49csergeyv
67849911a9c4315fc552faa38516c842b2541b1909John Reckclass ANDROID_API Canvas {
68cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenbergerpublic:
69cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual ~Canvas() {};
70cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger
71c1b33d665c8caf5760f68c45c6ca0baa649b832aJohn Reck    static Canvas* create_canvas(const SkBitmap& bitmap);
7218981294a58c411a4a33ebb22caf9c75ba639691Leon Scroggins III
736f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger    static Canvas* create_recording_canvas(int width, int height);
746f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger
7518981294a58c411a4a33ebb22caf9c75ba639691Leon Scroggins III    /**
7618981294a58c411a4a33ebb22caf9c75ba639691Leon Scroggins III     *  Create a new Canvas object which delegates to an SkCanvas.
7718981294a58c411a4a33ebb22caf9c75ba639691Leon Scroggins III     *
7818981294a58c411a4a33ebb22caf9c75ba639691Leon Scroggins III     *  @param skiaCanvas Must not be NULL. All drawing calls will be
7918981294a58c411a4a33ebb22caf9c75ba639691Leon Scroggins III     *      delegated to this object. This function will call ref() on the
8018981294a58c411a4a33ebb22caf9c75ba639691Leon Scroggins III     *      SkCanvas, and the returned Canvas will unref() it upon
8118981294a58c411a4a33ebb22caf9c75ba639691Leon Scroggins III     *      destruction.
8218981294a58c411a4a33ebb22caf9c75ba639691Leon Scroggins III     *  @return new Canvas object. Will not return NULL.
8318981294a58c411a4a33ebb22caf9c75ba639691Leon Scroggins III     */
84cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    static Canvas* create_canvas(SkCanvas* skiaCanvas);
85cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger
861db141f93c4fe79a4669440c3d14f63bc87b2e34Derek Sollenberger    /**
871db141f93c4fe79a4669440c3d14f63bc87b2e34Derek Sollenberger     *  Provides a Skia SkCanvas interface that acts as a proxy to this Canvas.
881db141f93c4fe79a4669440c3d14f63bc87b2e34Derek Sollenberger     *  It is useful for testing and clients (e.g. Picture/Movie) that expect to
891db141f93c4fe79a4669440c3d14f63bc87b2e34Derek Sollenberger     *  draw their contents into an SkCanvas.
901db141f93c4fe79a4669440c3d14f63bc87b2e34Derek Sollenberger     *
9190fb1f6732a610ad5ff6acdb3bd9ae392c8eac82Tom Hudson     *  The SkCanvas returned is *only* valid until another Canvas call is made
9290fb1f6732a610ad5ff6acdb3bd9ae392c8eac82Tom Hudson     *  that would change state (e.g. matrix or clip). Clients of asSkCanvas()
9390fb1f6732a610ad5ff6acdb3bd9ae392c8eac82Tom Hudson     *  are responsible for *not* persisting this pointer.
9490fb1f6732a610ad5ff6acdb3bd9ae392c8eac82Tom Hudson     *
951db141f93c4fe79a4669440c3d14f63bc87b2e34Derek Sollenberger     *  Further, the returned SkCanvas should NOT be unref'd and is valid until
961db141f93c4fe79a4669440c3d14f63bc87b2e34Derek Sollenberger     *  this canvas is destroyed or a new bitmap is set.
971db141f93c4fe79a4669440c3d14f63bc87b2e34Derek Sollenberger     */
98b3d50e007523d1ada0866d384c391c72ac1a3577Derek Sollenberger    virtual SkCanvas* asSkCanvas() = 0;
99cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger
1006f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger
101c1b33d665c8caf5760f68c45c6ca0baa649b832aJohn Reck    virtual void setBitmap(const SkBitmap& bitmap) = 0;
102cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger
103cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual bool isOpaque() = 0;
104cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual int width() = 0;
105cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual int height() = 0;
106cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger
1076f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger// ----------------------------------------------------------------------------
1086f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger// View System operations (not exposed in public Canvas API)
1096f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger// ----------------------------------------------------------------------------
1106f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger
1116f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger    virtual void resetRecording(int width, int height) = 0;
1126f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger    virtual uirenderer::DisplayList* finishRecording() = 0;
1136f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger    virtual void insertReorderBarrier(bool enableReorder) = 0;
1146f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger
1156578a989566e585eee053095dc80e2552e125db2Derek Sollenberger    virtual void setHighContrastText(bool highContrastText) = 0;
1166578a989566e585eee053095dc80e2552e125db2Derek Sollenberger    virtual bool isHighContrastText() = 0;
1176578a989566e585eee053095dc80e2552e125db2Derek Sollenberger
1186f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger    virtual void drawRoundRect(uirenderer::CanvasPropertyPrimitive* left,
1196f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger            uirenderer::CanvasPropertyPrimitive* top, uirenderer::CanvasPropertyPrimitive* right,
1206f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger            uirenderer::CanvasPropertyPrimitive* bottom, uirenderer::CanvasPropertyPrimitive* rx,
1216f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger            uirenderer::CanvasPropertyPrimitive* ry, uirenderer::CanvasPropertyPaint* paint) = 0;
1226f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger    virtual void drawCircle(uirenderer::CanvasPropertyPrimitive* x,
1236f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger            uirenderer::CanvasPropertyPrimitive* y, uirenderer::CanvasPropertyPrimitive* radius,
1246f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger            uirenderer::CanvasPropertyPaint* paint) = 0;
1256f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger
1266f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger    virtual void drawLayer(uirenderer::DeferredLayerUpdater* layerHandle) = 0;
1276f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger    virtual void drawRenderNode(uirenderer::RenderNode* renderNode) = 0;
128cd1c3eba69d044b551cededad75474038f919890John Reck    virtual void callDrawGLFunction(Functor* functor,
129cd1c3eba69d044b551cededad75474038f919890John Reck            uirenderer::GlFunctorLifecycleListener* listener) = 0;
1306f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger
131cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger// ----------------------------------------------------------------------------
132cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger// Canvas state operations
133cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger// ----------------------------------------------------------------------------
134eecff56fed5dd5206acfbc5007b4912081b36d3bFlorin Malita
135cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    // Save (layer)
136cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual int getSaveCount() const = 0;
137eecff56fed5dd5206acfbc5007b4912081b36d3bFlorin Malita    virtual int save(SaveFlags::Flags flags) = 0;
138cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual void restore() = 0;
139cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual void restoreToCount(int saveCount) = 0;
140cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger
141cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual int saveLayer(float left, float top, float right, float bottom,
142eecff56fed5dd5206acfbc5007b4912081b36d3bFlorin Malita                const SkPaint* paint, SaveFlags::Flags flags) = 0;
143cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual int saveLayerAlpha(float left, float top, float right, float bottom,
144eecff56fed5dd5206acfbc5007b4912081b36d3bFlorin Malita            int alpha, SaveFlags::Flags flags) = 0;
145cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger
146cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    // Matrix
147cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual void getMatrix(SkMatrix* outMatrix) const = 0;
148cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual void setMatrix(const SkMatrix& matrix) = 0;
149cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger
150cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual void concat(const SkMatrix& matrix) = 0;
151cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual void rotate(float degrees) = 0;
152cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual void scale(float sx, float sy) = 0;
153cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual void skew(float sx, float sy) = 0;
154cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual void translate(float dx, float dy) = 0;
155cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger
156cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    // clip
157cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual bool getClipBounds(SkRect* outRect) const = 0;
158cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual bool quickRejectRect(float left, float top, float right, float bottom) const = 0;
159cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual bool quickRejectPath(const SkPath& path) const = 0;
160cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger
161c1b33d665c8caf5760f68c45c6ca0baa649b832aJohn Reck    virtual bool clipRect(float left, float top, float right, float bottom,
162c1b33d665c8caf5760f68c45c6ca0baa649b832aJohn Reck            SkRegion::Op op = SkRegion::kIntersect_Op) = 0;
163cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual bool clipPath(const SkPath* path, SkRegion::Op op) = 0;
164cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual bool clipRegion(const SkRegion* region, SkRegion::Op op) = 0;
165cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger
166cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    // filters
167cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual SkDrawFilter* getDrawFilter() = 0;
168cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual void setDrawFilter(SkDrawFilter* drawFilter) = 0;
169cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger
170cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger// ----------------------------------------------------------------------------
171cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger// Canvas draw operations
172cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger// ----------------------------------------------------------------------------
173cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual void drawColor(int color, SkXfermode::Mode mode) = 0;
174cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual void drawPaint(const SkPaint& paint) = 0;
175cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger
176cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    // Geometry
177cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual void drawPoint(float x, float y, const SkPaint& paint) = 0;
178386aa031793bb037ec43b6cdbd8908c343cc86cbChris Craik    virtual void drawPoints(const float* points, int floatCount, const SkPaint& paint) = 0;
179cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual void drawLine(float startX, float startY, float stopX, float stopY,
180cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger                const SkPaint& paint) = 0;
181386aa031793bb037ec43b6cdbd8908c343cc86cbChris Craik    virtual void drawLines(const float* points, int floatCount, const SkPaint& paint) = 0;
182cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual void drawRect(float left, float top, float right, float bottom,
183cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger            const SkPaint& paint) = 0;
18494394b3fb048d5349a77b57950ab7f6b6e92ce34Derek Sollenberger    virtual void drawRegion(const SkRegion& region, const SkPaint& paint) = 0;
185cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual void drawRoundRect(float left, float top, float right, float bottom,
186cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger            float rx, float ry, const SkPaint& paint) = 0;
187cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual void drawCircle(float x, float y, float radius, const SkPaint& paint) = 0;
188cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual void drawOval(float left, float top, float right, float bottom,
189cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger            const SkPaint& paint) = 0;
190cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual void drawArc(float left, float top, float right, float bottom,
191cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger            float startAngle, float sweepAngle, bool useCenter, const SkPaint& paint) = 0;
192cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual void drawPath(const SkPath& path, const SkPaint& paint) = 0;
193cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual void drawVertices(SkCanvas::VertexMode vertexMode, int vertexCount,
194cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger                              const float* verts, const float* tex, const int* colors,
195cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger                              const uint16_t* indices, int indexCount, const SkPaint& paint) = 0;
196cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger
197cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    // Bitmap-based
198cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual void drawBitmap(const SkBitmap& bitmap, float left, float top,
199cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger            const SkPaint* paint) = 0;
200cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual void drawBitmap(const SkBitmap& bitmap, const SkMatrix& matrix,
201cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger            const SkPaint* paint) = 0;
202cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual void drawBitmap(const SkBitmap& bitmap, float srcLeft, float srcTop,
203cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger            float srcRight, float srcBottom, float dstLeft, float dstTop,
204cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger            float dstRight, float dstBottom, const SkPaint* paint) = 0;
205cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual void drawBitmapMesh(const SkBitmap& bitmap, int meshWidth, int meshHeight,
206cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger            const float* vertices, const int* colors, const SkPaint* paint) = 0;
2074c5efe9290543b723b76a8bd48518da1ae1dcb26Derek Sollenberger    virtual void drawNinePatch(const SkBitmap& bitmap, const android::Res_png_9patch& chunk,
2084c5efe9290543b723b76a8bd48518da1ae1dcb26Derek Sollenberger            float dstLeft, float dstTop, float dstRight, float dstBottom,
2094c5efe9290543b723b76a8bd48518da1ae1dcb26Derek Sollenberger            const SkPaint* paint) = 0;
210cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger
2118dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson    /**
212cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger     * Specifies if the positions passed to ::drawText are absolute or relative
213cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger     * to the (x,y) value provided.
214cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger     *
215cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger     * If true the (x,y) values are ignored. Otherwise, those (x,y) values need
216cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger     * to be added to each glyph's position to get its absolute position.
217cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger     */
218cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger    virtual bool drawTextAbsolutePos() const = 0;
219a1717271caac5e8ea3808c331d4141ac01a42134Chris Craik
220766431aa57c16ece8842287a92b2e7208e3b8ac3Doris Liu    /**
221766431aa57c16ece8842287a92b2e7208e3b8ac3Doris Liu     * Draws a VectorDrawable onto the canvas.
222766431aa57c16ece8842287a92b2e7208e3b8ac3Doris Liu     */
223766431aa57c16ece8842287a92b2e7208e3b8ac3Doris Liu    virtual void drawVectorDrawable(VectorDrawableRoot* tree);
224766431aa57c16ece8842287a92b2e7208e3b8ac3Doris Liu
225dccca44ffda4836b56a21da95a046c9708ffd49csergeyv    /**
226dccca44ffda4836b56a21da95a046c9708ffd49csergeyv     * Converts utf16 text to glyphs, calculating position and boundary,
227dccca44ffda4836b56a21da95a046c9708ffd49csergeyv     * and delegating the final draw to virtual drawGlyphs method.
228dccca44ffda4836b56a21da95a046c9708ffd49csergeyv     */
229dccca44ffda4836b56a21da95a046c9708ffd49csergeyv    void drawText(const uint16_t* text, int start, int count, int contextCount,
230bad99183916ba2bac6659efc8a28273e344ba511sergeyv            float x, float y, int bidiFlags, const Paint& origPaint, Typeface* typeface);
231dccca44ffda4836b56a21da95a046c9708ffd49csergeyv
232dccca44ffda4836b56a21da95a046c9708ffd49csergeyv    void drawTextOnPath(const uint16_t* text, int count, int bidiFlags, const SkPath& path,
233bad99183916ba2bac6659efc8a28273e344ba511sergeyv            float hOffset, float vOffset, const Paint& paint, Typeface* typeface);
234dccca44ffda4836b56a21da95a046c9708ffd49csergeyv
235a1717271caac5e8ea3808c331d4141ac01a42134Chris Craikprotected:
236a1717271caac5e8ea3808c331d4141ac01a42134Chris Craik    void drawTextDecorations(float x, float y, float length, const SkPaint& paint);
23779abbf22d4f672208327546661e694d837f564a9Derek Sollenberger
23879abbf22d4f672208327546661e694d837f564a9Derek Sollenberger    /**
23979abbf22d4f672208327546661e694d837f564a9Derek Sollenberger     * drawText: count is of glyphs
24079abbf22d4f672208327546661e694d837f564a9Derek Sollenberger     * totalAdvance: used to define width of text decorations (underlines, strikethroughs).
24179abbf22d4f672208327546661e694d837f564a9Derek Sollenberger     */
24279abbf22d4f672208327546661e694d837f564a9Derek Sollenberger    virtual void drawGlyphs(const uint16_t* glyphs, const float* positions, int count,
24379abbf22d4f672208327546661e694d837f564a9Derek Sollenberger            const SkPaint& paint, float x, float y,
24479abbf22d4f672208327546661e694d837f564a9Derek Sollenberger            float boundsLeft, float boundsTop, float boundsRight, float boundsBottom,
24579abbf22d4f672208327546661e694d837f564a9Derek Sollenberger            float totalAdvance) = 0;
24679abbf22d4f672208327546661e694d837f564a9Derek Sollenberger    /** drawTextOnPath: count is of glyphs */
24779abbf22d4f672208327546661e694d837f564a9Derek Sollenberger    virtual void drawGlyphsOnPath(const uint16_t* glyphs, int count, const SkPath& path,
24879abbf22d4f672208327546661e694d837f564a9Derek Sollenberger            float hOffset, float vOffset, const SkPaint& paint) = 0;
24979abbf22d4f672208327546661e694d837f564a9Derek Sollenberger
25079abbf22d4f672208327546661e694d837f564a9Derek Sollenberger    friend class DrawTextFunctor;
25179abbf22d4f672208327546661e694d837f564a9Derek Sollenberger    friend class DrawTextOnPathFunctor;
25279abbf22d4f672208327546661e694d837f564a9Derek Sollenberger    friend class uirenderer::SkiaCanvasProxy;
253cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger};
254cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger
255cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger}; // namespace android
256cae05e0b4c4726236487bdd7c23b82e93f85fd23Derek Sollenberger#endif // ANDROID_GRAPHICS_CANVAS_H
257