Derek Sollenberger | 1db141f | 2014-12-16 08:37:20 -0500 | [diff] [blame] | 1 | /* |
| 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 | |
Derek Sollenberger | 1db141f | 2014-12-16 08:37:20 -0500 | [diff] [blame] | 20 | #include <SkCanvas.h> |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 21 | #include <cutils/compiler.h> |
Derek Sollenberger | 1db141f | 2014-12-16 08:37:20 -0500 | [diff] [blame] | 22 | |
sergeyv | dccca44 | 2016-03-21 15:38:21 -0700 | [diff] [blame] | 23 | #include "hwui/Canvas.h" |
Derek Sollenberger | 1db141f | 2014-12-16 08:37:20 -0500 | [diff] [blame] | 24 | |
| 25 | namespace android { |
| 26 | namespace uirenderer { |
| 27 | |
| 28 | /** |
| 29 | * This class serves as a proxy between Skia's SkCanvas and Android Framework's |
Tom Hudson | b1476ae | 2015-03-05 10:30:18 -0500 | [diff] [blame] | 30 | * 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 Sollenberger | 1db141f | 2014-12-16 08:37:20 -0500 | [diff] [blame] | 32 | * |
| 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 Hudson | b1476ae | 2015-03-05 10:30:18 -0500 | [diff] [blame] | 36 | * |
| 37 | * If filterHwuiCalls is true, the proxy silently ignores away draw calls that |
| 38 | * aren't supported by HWUI. |
Derek Sollenberger | 1db141f | 2014-12-16 08:37:20 -0500 | [diff] [blame] | 39 | */ |
| 40 | class ANDROID_API SkiaCanvasProxy : public SkCanvas { |
| 41 | public: |
Chih-Hung Hsieh | faecb78 | 2016-07-21 11:23:06 -0700 | [diff] [blame] | 42 | explicit SkiaCanvasProxy(Canvas* canvas, bool filterHwuiCalls = false); |
Derek Sollenberger | 1db141f | 2014-12-16 08:37:20 -0500 | [diff] [blame] | 43 | virtual ~SkiaCanvasProxy() {} |
| 44 | |
| 45 | protected: |
Matt Sarett | 79fc3b1 | 2016-03-24 11:02:44 -0400 | [diff] [blame] | 46 | virtual sk_sp<SkSurface> onNewSurface(const SkImageInfo&, const SkSurfaceProps&) override; |
Derek Sollenberger | 1db141f | 2014-12-16 08:37:20 -0500 | [diff] [blame] | 47 | |
| 48 | virtual void willSave() override; |
Leon Scroggins III | 5518e7c | 2016-01-04 09:37:42 -0500 | [diff] [blame] | 49 | virtual SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override; |
Derek Sollenberger | 1db141f | 2014-12-16 08:37:20 -0500 | [diff] [blame] | 50 | virtual void willRestore() override; |
| 51 | |
| 52 | virtual void didConcat(const SkMatrix&) override; |
| 53 | virtual void didSetMatrix(const SkMatrix&) override; |
| 54 | |
| 55 | virtual void onDrawPaint(const SkPaint& paint) override; |
| 56 | virtual void onDrawPoints(PointMode, size_t count, const SkPoint pts[], |
| 57 | const SkPaint&) override; |
| 58 | virtual void onDrawOval(const SkRect&, const SkPaint&) override; |
| 59 | virtual void onDrawRect(const SkRect&, const SkPaint&) override; |
| 60 | virtual void onDrawRRect(const SkRRect&, const SkPaint&) override; |
| 61 | virtual void onDrawPath(const SkPath& path, const SkPaint&) override; |
Yuqian Li | 9969111 | 2017-02-03 15:01:41 -0500 | [diff] [blame] | 62 | virtual void onDrawArc(const SkRect&, SkScalar startAngle, SkScalar sweepAngle, bool useCenter, |
| 63 | const SkPaint&) override; |
Derek Sollenberger | 1db141f | 2014-12-16 08:37:20 -0500 | [diff] [blame] | 64 | virtual void onDrawBitmap(const SkBitmap&, SkScalar left, SkScalar top, |
| 65 | const SkPaint*) override; |
| 66 | virtual void onDrawBitmapRect(const SkBitmap&, const SkRect* src, const SkRect& dst, |
Leon Scroggins III | f35b989 | 2015-07-31 10:38:40 -0400 | [diff] [blame] | 67 | const SkPaint* paint, SrcRectConstraint) override; |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 68 | virtual void onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst, |
| 69 | const SkPaint*) override; |
Stan Iliev | 770e0b5 | 2017-01-05 16:53:14 -0500 | [diff] [blame] | 70 | virtual void onDrawImage(const SkImage*, SkScalar dx, SkScalar dy, const SkPaint*); |
| 71 | virtual void onDrawImageRect(const SkImage*, const SkRect*, const SkRect&, const SkPaint*, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 72 | SrcRectConstraint); |
Stan Iliev | 770e0b5 | 2017-01-05 16:53:14 -0500 | [diff] [blame] | 73 | virtual void onDrawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 74 | const SkPaint*); |
Stan Iliev | 770e0b5 | 2017-01-05 16:53:14 -0500 | [diff] [blame] | 75 | virtual void onDrawImageLattice(const SkImage*, const Lattice& lattice, const SkRect& dst, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 76 | const SkPaint*); |
Mike Reed | 871cd2d | 2017-03-17 10:15:52 -0400 | [diff] [blame] | 77 | virtual void onDrawVerticesObject(const SkVertices*, SkBlendMode, const SkPaint&) override; |
Derek Sollenberger | 1db141f | 2014-12-16 08:37:20 -0500 | [diff] [blame] | 78 | |
| 79 | virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override; |
| 80 | |
| 81 | virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, |
| 82 | const SkPaint&) override; |
| 83 | virtual void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[], |
| 84 | const SkPaint&) override; |
| 85 | virtual void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], |
| 86 | SkScalar constY, const SkPaint&) override; |
| 87 | virtual void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path, |
| 88 | const SkMatrix* matrix, const SkPaint&) override; |
Yuqian Li | afc22149 | 2016-07-18 13:07:42 -0400 | [diff] [blame] | 89 | virtual void onDrawTextRSXform(const void* text, size_t byteLength, const SkRSXform[], |
| 90 | const SkRect* cullRect, const SkPaint& paint); |
Derek Sollenberger | 1db141f | 2014-12-16 08:37:20 -0500 | [diff] [blame] | 91 | virtual void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, |
| 92 | const SkPaint& paint) override; |
| 93 | |
| 94 | virtual void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], |
Mike Reed | c2f31df | 2016-10-28 17:21:45 -0400 | [diff] [blame] | 95 | const SkPoint texCoords[4], SkBlendMode, |
Derek Sollenberger | 1db141f | 2014-12-16 08:37:20 -0500 | [diff] [blame] | 96 | const SkPaint& paint) override; |
| 97 | |
Mike Reed | 6e49c9f | 2016-12-02 15:36:59 -0500 | [diff] [blame] | 98 | virtual void onClipRect(const SkRect&, SkClipOp, ClipEdgeStyle) override; |
| 99 | virtual void onClipRRect(const SkRRect&, SkClipOp, ClipEdgeStyle) override; |
| 100 | virtual void onClipPath(const SkPath&, SkClipOp, ClipEdgeStyle) override; |
Derek Sollenberger | 1db141f | 2014-12-16 08:37:20 -0500 | [diff] [blame] | 101 | |
| 102 | private: |
| 103 | Canvas* mCanvas; |
Tom Hudson | b1476ae | 2015-03-05 10:30:18 -0500 | [diff] [blame] | 104 | bool mFilterHwuiCalls; |
Derek Sollenberger | 1db141f | 2014-12-16 08:37:20 -0500 | [diff] [blame] | 105 | |
| 106 | typedef SkCanvas INHERITED; |
| 107 | }; |
| 108 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 109 | }; // namespace uirenderer |
| 110 | }; // namespace android |
Derek Sollenberger | 1db141f | 2014-12-16 08:37:20 -0500 | [diff] [blame] | 111 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 112 | #endif // SkiaCanvasProxy_DEFINED |