blob: 0de965094e64c613a1e19cd2fcd2fba640b8ac05 [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
23#include "Canvas.h"
24
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:
Tom Hudsonb1476ae2015-03-05 10:30:18 -050042 SkiaCanvasProxy(Canvas* canvas, bool filterHwuiCalls = false);
Derek Sollenberger1db141f2014-12-16 08:37:20 -050043 virtual ~SkiaCanvasProxy() {}
44
45protected:
46
47 virtual SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) override;
48
49 virtual void willSave() override;
50 virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) override;
51 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;
63 virtual void onDrawBitmap(const SkBitmap&, SkScalar left, SkScalar top,
64 const SkPaint*) override;
65 virtual void onDrawBitmapRect(const SkBitmap&, const SkRect* src, const SkRect& dst,
66 const SkPaint* paint, DrawBitmapRectFlags flags) override;
67 virtual void onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
68 const SkRect& dst, const SkPaint*) override;
69 virtual void onDrawSprite(const SkBitmap&, int left, int top,
70 const SkPaint*) override;
71 virtual void onDrawVertices(VertexMode, int vertexCount, const SkPoint vertices[],
72 const SkPoint texs[], const SkColor colors[], SkXfermode*,
73 const uint16_t indices[], int indexCount,
74 const SkPaint&) override;
75
76 virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
77
78 virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
79 const SkPaint&) override;
80 virtual void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
81 const SkPaint&) override;
82 virtual void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
83 SkScalar constY, const SkPaint&) override;
84 virtual void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
85 const SkMatrix* matrix, const SkPaint&) override;
86 virtual void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
87 const SkPaint& paint) override;
88
89 virtual void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
90 const SkPoint texCoords[4], SkXfermode* xmode,
91 const SkPaint& paint) override;
92
93 virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) override;
94 virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) override;
95 virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) override;
96 virtual void onClipRegion(const SkRegion&, SkRegion::Op) override;
97
98private:
99 Canvas* mCanvas;
Tom Hudsonb1476ae2015-03-05 10:30:18 -0500100 bool mFilterHwuiCalls;
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500101
102 typedef SkCanvas INHERITED;
103};
104
105}; // namespace uirenderer
106}; // namespace android
107
108#endif // SkiaCanvasProxy_DEFINED