blob: d11a779b36001745fee9154a391c8213cb7e128b [file] [log] [blame]
Derek Sollenberger1db141f2014-12-16 08:37:20 -05001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef SkiaCanvasProxy_DEFINED
18#define SkiaCanvasProxy_DEFINED
19
20#include <cutils/compiler.h>
21#include <SkCanvas.h>
22
sergeyvdccca442016-03-21 15:38:21 -070023#include "hwui/Canvas.h"
Derek Sollenberger1db141f2014-12-16 08:37:20 -050024
25namespace android {
26namespace uirenderer {
27
28/**
29 * This class serves as a proxy between Skia's SkCanvas and Android Framework's
Tom Hudsonb1476ae2015-03-05 10:30:18 -050030 * Canvas. The class does not maintain any draw-related state and will pass
31 * through most requests directly to the Canvas provided in the constructor.
Derek Sollenberger1db141f2014-12-16 08:37:20 -050032 *
33 * Upon construction it is expected that the provided Canvas has already been
34 * prepared for recording and will continue to be in the recording state while
35 * this proxy class is being used.
Tom Hudsonb1476ae2015-03-05 10:30:18 -050036 *
37 * If filterHwuiCalls is true, the proxy silently ignores away draw calls that
38 * aren't supported by HWUI.
Derek Sollenberger1db141f2014-12-16 08:37:20 -050039 */
40class ANDROID_API SkiaCanvasProxy : public SkCanvas {
41public:
Chih-Hung Hsiehfaecb782016-07-21 11:23:06 -070042 explicit SkiaCanvasProxy(Canvas* canvas, bool filterHwuiCalls = false);
Derek Sollenberger1db141f2014-12-16 08:37:20 -050043 virtual ~SkiaCanvasProxy() {}
44
45protected:
46
Matt Sarett79fc3b12016-03-24 11:02:44 -040047 virtual sk_sp<SkSurface> onNewSurface(const SkImageInfo&, const SkSurfaceProps&) override;
Derek Sollenberger1db141f2014-12-16 08:37:20 -050048
49 virtual void willSave() override;
Leon Scroggins III5518e7c2016-01-04 09:37:42 -050050 virtual SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override;
Derek Sollenberger1db141f2014-12-16 08:37:20 -050051 virtual void willRestore() override;
52
53 virtual void didConcat(const SkMatrix&) override;
54 virtual void didSetMatrix(const SkMatrix&) override;
55
56 virtual void onDrawPaint(const SkPaint& paint) override;
57 virtual void onDrawPoints(PointMode, size_t count, const SkPoint pts[],
58 const SkPaint&) override;
59 virtual void onDrawOval(const SkRect&, const SkPaint&) override;
60 virtual void onDrawRect(const SkRect&, const SkPaint&) override;
61 virtual void onDrawRRect(const SkRRect&, const SkPaint&) override;
62 virtual void onDrawPath(const SkPath& path, const SkPaint&) override;
Yuqian Li99691112017-02-03 15:01:41 -050063 virtual void onDrawArc(const SkRect&, SkScalar startAngle, SkScalar sweepAngle, bool useCenter,
64 const SkPaint&) override;
Derek Sollenberger1db141f2014-12-16 08:37:20 -050065 virtual void onDrawBitmap(const SkBitmap&, SkScalar left, SkScalar top,
66 const SkPaint*) override;
67 virtual void onDrawBitmapRect(const SkBitmap&, const SkRect* src, const SkRect& dst,
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -040068 const SkPaint* paint, SrcRectConstraint) override;
Derek Sollenberger1db141f2014-12-16 08:37:20 -050069 virtual void onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
70 const SkRect& dst, const SkPaint*) override;
Stan Iliev770e0b52017-01-05 16:53:14 -050071 virtual void onDrawImage(const SkImage*, SkScalar dx, SkScalar dy, const SkPaint*);
72 virtual void onDrawImageRect(const SkImage*, const SkRect*, const SkRect&, const SkPaint*,
73 SrcRectConstraint);
74 virtual void onDrawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst,
75 const SkPaint*);
76 virtual void onDrawImageLattice(const SkImage*, const Lattice& lattice, const SkRect& dst,
77 const SkPaint*);
Mike Reed871cd2d2017-03-17 10:15:52 -040078 virtual void onDrawVerticesObject(const SkVertices*, SkBlendMode, const SkPaint&) override;
Derek Sollenberger1db141f2014-12-16 08:37:20 -050079
80 virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
81
82 virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
83 const SkPaint&) override;
84 virtual void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
85 const SkPaint&) override;
86 virtual void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
87 SkScalar constY, const SkPaint&) override;
88 virtual void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
89 const SkMatrix* matrix, const SkPaint&) override;
Yuqian Liafc221492016-07-18 13:07:42 -040090 virtual void onDrawTextRSXform(const void* text, size_t byteLength, const SkRSXform[],
91 const SkRect* cullRect, const SkPaint& paint);
Derek Sollenberger1db141f2014-12-16 08:37:20 -050092 virtual void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
93 const SkPaint& paint) override;
94
95 virtual void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
Mike Reedc2f31df2016-10-28 17:21:45 -040096 const SkPoint texCoords[4], SkBlendMode,
Derek Sollenberger1db141f2014-12-16 08:37:20 -050097 const SkPaint& paint) override;
98
Mike Reed6e49c9f2016-12-02 15:36:59 -050099 virtual void onClipRect(const SkRect&, SkClipOp, ClipEdgeStyle) override;
100 virtual void onClipRRect(const SkRRect&, SkClipOp, ClipEdgeStyle) override;
101 virtual void onClipPath(const SkPath&, SkClipOp, ClipEdgeStyle) override;
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500102
103private:
104 Canvas* mCanvas;
Tom Hudsonb1476ae2015-03-05 10:30:18 -0500105 bool mFilterHwuiCalls;
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500106
107 typedef SkCanvas INHERITED;
108};
109
110}; // namespace uirenderer
111}; // namespace android
112
113#endif // SkiaCanvasProxy_DEFINED