DamageAccumulator.h revision a447d29c65fb811cd184775a3476101a1cede929
1/*
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
19#include <cutils/compiler.h>
20#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;
32class Matrix4;
33
34class IDamageAccumulator {
35public:
36    virtual void pushTransform(const RenderNode* transform) = 0;
37    virtual void pushTransform(const Matrix4* transform) = 0;
38    virtual void popTransform() = 0;
39    virtual void dirty(float left, float top, float right, float bottom) = 0;
40protected:
41    virtual ~IDamageAccumulator() {}
42};
43
44class DamageAccumulator : public IDamageAccumulator {
45    PREVENT_COPY_AND_ASSIGN(DamageAccumulator);
46public:
47    DamageAccumulator();
48    // mAllocator will clean everything up for us, no need for a dtor
49
50    // Push a transform node onto the stack. This should be called prior
51    // to any dirty() calls. Subsequent calls to dirty()
52    // will be affected by the transform when popTransform() is called.
53    virtual void pushTransform(const RenderNode* transform);
54    virtual void pushTransform(const Matrix4* transform);
55
56    // Pops a transform node from the stack, propagating the dirty rect
57    // up to the parent node. Returns the IDamageTransform that was just applied
58    virtual void popTransform();
59
60    virtual void dirty(float left, float top, float right, float bottom);
61
62    void finish(SkRect* totalDirty);
63
64private:
65    void pushCommon();
66    void applyMatrix4Transform(DirtyStack* frame);
67    void applyRenderNodeTransform(DirtyStack* frame);
68
69    LinearAllocator mAllocator;
70    DirtyStack* mHead;
71};
72
73class NullDamageAccumulator : public IDamageAccumulator {
74    PREVENT_COPY_AND_ASSIGN(NullDamageAccumulator);
75public:
76    virtual void pushTransform(const RenderNode* transform) { }
77    virtual void pushTransform(const Matrix4* transform) { }
78    virtual void popTransform() { }
79    virtual void dirty(float left, float top, float right, float bottom) { }
80
81    ANDROID_API static NullDamageAccumulator* instance();
82
83private:
84    NullDamageAccumulator() {}
85    ~NullDamageAccumulator() {}
86
87    static NullDamageAccumulator sInstance;
88};
89
90} /* namespace uirenderer */
91} /* namespace android */
92
93#endif /* DAMAGEACCUMULATOR_H */
94