Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | #pragma once |
| 18 | |
| 19 | #include "Layer.h" |
| 20 | #include "RenderNode.h" |
| 21 | |
| 22 | #include <SkCanvas.h> |
| 23 | #include <SkDrawable.h> |
| 24 | #include <SkMatrix.h> |
| 25 | |
| 26 | #include <utils/RefBase.h> |
| 27 | #include <utils/FatVector.h> |
| 28 | #include <utils/Functor.h> |
| 29 | |
| 30 | namespace android { |
| 31 | |
| 32 | class Functor; |
| 33 | |
| 34 | namespace uirenderer { |
| 35 | |
| 36 | |
| 37 | class RenderProperties; |
| 38 | class OffscreenBuffer; |
| 39 | class GlFunctorLifecycleListener; |
| 40 | class SkiaDisplayList; |
| 41 | |
| 42 | /** |
| 43 | * This drawable wraps a RenderNode and enables it to be recorded into a list |
| 44 | * of Skia drawing commands. |
| 45 | */ |
| 46 | class RenderNodeDrawable : public SkDrawable { |
| 47 | public: |
| 48 | explicit RenderNodeDrawable(RenderNode* node, SkCanvas* canvas) |
| 49 | : mRenderNode(node) |
| 50 | , mRecordedTransform(canvas->getTotalMatrix()) {} |
| 51 | |
| 52 | /** |
| 53 | * The renderNode (and its properties) that is to be drawn |
| 54 | */ |
| 55 | RenderNode* getRenderNode() const { return mRenderNode.get(); } |
| 56 | |
| 57 | /** |
| 58 | * Returns the transform on the canvas at time of recording and is used for |
| 59 | * computing total transform without rerunning DL contents. |
| 60 | */ |
| 61 | const SkMatrix& getRecordedMatrix() const { return mRecordedTransform; } |
| 62 | |
| 63 | protected: |
| 64 | virtual SkRect onGetBounds() override { |
| 65 | // We don't want to enable a record time quick reject because the properties |
| 66 | // of the RenderNode may be updated on subsequent frames. |
| 67 | return SkRect::MakeLargest(); |
| 68 | } |
| 69 | virtual void onDraw(SkCanvas* canvas) override { /* TODO */ } |
| 70 | |
| 71 | private: |
| 72 | sp<RenderNode> mRenderNode; |
| 73 | const SkMatrix mRecordedTransform; |
| 74 | }; |
| 75 | |
| 76 | /** |
| 77 | * This drawable wraps a OpenGL functor enabling it to be recorded into a list |
| 78 | * of Skia drawing commands. |
| 79 | */ |
| 80 | class GLFunctorDrawable : public SkDrawable { |
| 81 | public: |
| 82 | GLFunctorDrawable(Functor* functor, GlFunctorLifecycleListener* listener, SkCanvas* canvas) |
| 83 | : mFunctor(functor) |
| 84 | , mListener(listener) { |
| 85 | canvas->getClipBounds(&mBounds); |
| 86 | } |
| 87 | virtual ~GLFunctorDrawable() {} |
| 88 | |
| 89 | void syncFunctor() const { (*mFunctor)(DrawGlInfo::kModeSync, nullptr); } |
| 90 | |
| 91 | protected: |
| 92 | virtual SkRect onGetBounds() override { return mBounds; } |
| 93 | virtual void onDraw(SkCanvas* canvas) override { /* TODO */ } |
| 94 | |
| 95 | private: |
| 96 | Functor* mFunctor; |
| 97 | sp<GlFunctorLifecycleListener> mListener; |
| 98 | SkRect mBounds; |
| 99 | }; |
| 100 | |
| 101 | }; // namespace uirenderer |
| 102 | }; // namespace android |