• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <effects/StretchEffect.h>
25 
26 #include "utils/Macros.h"
27 
28 // Smaller than INT_MIN/INT_MAX because we offset these values
29 // and thus don't want to be adding offsets to INT_MAX, that's bad
30 #define DIRTY_MIN (-0x7ffffff - 1)
31 #define DIRTY_MAX (0x8000000)
32 
33 namespace android {
34 namespace uirenderer {
35 
36 struct DirtyStack;
37 class RenderNode;
38 class Matrix4;
39 
40 class DamageAccumulator {
41     PREVENT_COPY_AND_ASSIGN(DamageAccumulator);
42 
43 public:
44     DamageAccumulator();
45     // mAllocator will clean everything up for us, no need for a dtor
46 
47     // Push a transform node onto the stack. This should be called prior
48     // to any dirty() calls. Subsequent calls to dirty()
49     // will be affected by the transform when popTransform() is called.
50     void pushTransform(const RenderNode* transform);
51     void pushTransform(const Matrix4* transform);
52 
53     // Pops a transform node from the stack, propagating the dirty rect
54     // up to the parent node. Returns the IDamageTransform that was just applied
55     void popTransform();
56 
57     void dirty(float left, float top, float right, float bottom);
58 
59     // Returns the current dirty area, *NOT* transformed by pushed transforms
60     void peekAtDirty(SkRect* dest) const;
61 
62     void computeCurrentTransform(Matrix4* outMatrix) const;
63 
64     SkRect computeClipAndTransform(const SkRect& bounds, Matrix4* outMatrix) const;
65 
66     void finish(SkRect* totalDirty);
67 
68     struct StretchResult {
69         /**
70          * Stretch parameters configured on the stretch container
71          */
72         const StretchEffect* stretchEffect;
73 
74         /**
75          * Bounds of the stretching container
76          */
77         const SkRect parentBounds;
78 
79         /**
80          * Width of the stretch container
81          */
82         const float width;
83 
84         /**
85          * Height of the stretch container
86          */
87         const float height;
88     };
89 
90     [[nodiscard]] StretchResult findNearestStretchEffect() const;
91 
92 private:
93     void pushCommon();
94     void applyMatrix4Transform(DirtyStack* frame);
95     void applyRenderNodeTransform(DirtyStack* frame);
96 
97     LinearAllocator mAllocator;
98     DirtyStack* mHead;
99 };
100 
101 } /* namespace uirenderer */
102 } /* namespace android */
103 
104 #endif /* DAMAGEACCUMULATOR_H */
105