blob: fc9b41b220a5564b161a64d2eaf6062c43e824d6 [file] [log] [blame]
John Recke4267ea2014-06-03 15:53:15 -07001/*
2 * Copyright (C) 2014 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#ifndef DAMAGEACCUMULATOR_H
17#define DAMAGEACCUMULATOR_H
18
John Recka447d292014-06-11 18:39:44 -070019#include <cutils/compiler.h>
John Recke4267ea2014-06-03 15:53:15 -070020#include <utils/LinearAllocator.h>
21
22#include <SkMatrix.h>
23#include <SkRect.h>
24
25#include "utils/Macros.h"
26
27namespace android {
28namespace uirenderer {
29
30struct DirtyStack;
31class RenderNode;
John Recka447d292014-06-11 18:39:44 -070032class Matrix4;
John Recke4267ea2014-06-03 15:53:15 -070033
John Recka447d292014-06-11 18:39:44 -070034class IDamageAccumulator {
35public:
36 virtual void pushTransform(const RenderNode* transform) = 0;
37 virtual void pushTransform(const Matrix4* transform) = 0;
John Reck25fbb3f2014-06-12 13:46:45 -070038 virtual void pushNullTransform() = 0;
John Recka447d292014-06-11 18:39:44 -070039 virtual void popTransform() = 0;
40 virtual void dirty(float left, float top, float right, float bottom) = 0;
John Reck25fbb3f2014-06-12 13:46:45 -070041 virtual void peekAtDirty(SkRect* dest) = 0;
John Recka447d292014-06-11 18:39:44 -070042protected:
43 virtual ~IDamageAccumulator() {}
44};
45
46class DamageAccumulator : public IDamageAccumulator {
John Recke4267ea2014-06-03 15:53:15 -070047 PREVENT_COPY_AND_ASSIGN(DamageAccumulator);
48public:
49 DamageAccumulator();
50 // mAllocator will clean everything up for us, no need for a dtor
51
52 // Push a transform node onto the stack. This should be called prior
53 // to any dirty() calls. Subsequent calls to dirty()
John Recka447d292014-06-11 18:39:44 -070054 // will be affected by the transform when popTransform() is called.
55 virtual void pushTransform(const RenderNode* transform);
56 virtual void pushTransform(const Matrix4* transform);
John Reck25fbb3f2014-06-12 13:46:45 -070057 // This is used in combination with peekAtDirty to inspect the damage
58 // area of a subtree
59 virtual void pushNullTransform();
John Recka447d292014-06-11 18:39:44 -070060
John Recke4267ea2014-06-03 15:53:15 -070061 // Pops a transform node from the stack, propagating the dirty rect
John Recka447d292014-06-11 18:39:44 -070062 // up to the parent node. Returns the IDamageTransform that was just applied
63 virtual void popTransform();
64
65 virtual void dirty(float left, float top, float right, float bottom);
John Recke4267ea2014-06-03 15:53:15 -070066
John Reck25fbb3f2014-06-12 13:46:45 -070067 // Returns the current dirty area, *NOT* transformed by pushed transforms
68 virtual void peekAtDirty(SkRect* dest);
69
John Recke4267ea2014-06-03 15:53:15 -070070 void finish(SkRect* totalDirty);
71
72private:
John Recka447d292014-06-11 18:39:44 -070073 void pushCommon();
74 void applyMatrix4Transform(DirtyStack* frame);
75 void applyRenderNodeTransform(DirtyStack* frame);
76
John Recke4267ea2014-06-03 15:53:15 -070077 LinearAllocator mAllocator;
78 DirtyStack* mHead;
79};
80
John Recka447d292014-06-11 18:39:44 -070081class NullDamageAccumulator : public IDamageAccumulator {
82 PREVENT_COPY_AND_ASSIGN(NullDamageAccumulator);
83public:
84 virtual void pushTransform(const RenderNode* transform) { }
85 virtual void pushTransform(const Matrix4* transform) { }
John Reck25fbb3f2014-06-12 13:46:45 -070086 virtual void pushNullTransform() { }
John Recka447d292014-06-11 18:39:44 -070087 virtual void popTransform() { }
88 virtual void dirty(float left, float top, float right, float bottom) { }
John Reck25fbb3f2014-06-12 13:46:45 -070089 virtual void peekAtDirty(SkRect* dest) { dest->setEmpty(); }
John Recka447d292014-06-11 18:39:44 -070090
91 ANDROID_API static NullDamageAccumulator* instance();
92
93private:
94 NullDamageAccumulator() {}
95 ~NullDamageAccumulator() {}
96
97 static NullDamageAccumulator sInstance;
98};
99
John Recke4267ea2014-06-03 15:53:15 -0700100} /* namespace uirenderer */
101} /* namespace android */
102
103#endif /* DAMAGEACCUMULATOR_H */