blob: a1ceeaa0afb4af7c126ac2b51e43e0ceb1f34605 [file] [log] [blame]
Derek Sollenberger0df62092016-09-27 16:04:42 -04001/*
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
30namespace android {
31
32class Functor;
33
34namespace uirenderer {
35
36
37class RenderProperties;
38class OffscreenBuffer;
39class GlFunctorLifecycleListener;
40class SkiaDisplayList;
41
42/**
43 * This drawable wraps a RenderNode and enables it to be recorded into a list
44 * of Skia drawing commands.
45 */
46class RenderNodeDrawable : public SkDrawable {
47public:
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
63protected:
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
71private:
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 */
80class GLFunctorDrawable : public SkDrawable {
81public:
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