blob: 30bf7063a6274d4e443cb2e8d50ed964a859e5f7 [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>
Nader Jawad197743f2021-04-19 19:45:13 -070024#include <effects/StretchEffect.h>
John Recke4267ea2014-06-03 15:53:15 -070025
26#include "utils/Macros.h"
27
John Reckc12882392015-08-12 13:39:11 -070028// 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
John Reck1bcacfd2017-11-03 10:12:19 -070030#define DIRTY_MIN (-0x7ffffff - 1)
Nick Desaulniers19ae5f92019-10-10 13:11:23 -070031#define DIRTY_MAX (0x8000000)
John Reckc12882392015-08-12 13:39:11 -070032
John Recke4267ea2014-06-03 15:53:15 -070033namespace android {
34namespace uirenderer {
35
36struct DirtyStack;
37class RenderNode;
John Recka447d292014-06-11 18:39:44 -070038class Matrix4;
John Recke4267ea2014-06-03 15:53:15 -070039
Chris Craik69e5adf2014-08-14 13:34:01 -070040class DamageAccumulator {
John Recke4267ea2014-06-03 15:53:15 -070041 PREVENT_COPY_AND_ASSIGN(DamageAccumulator);
John Reck1bcacfd2017-11-03 10:12:19 -070042
John Recke4267ea2014-06-03 15:53:15 -070043public:
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()
John Recka447d292014-06-11 18:39:44 -070049 // will be affected by the transform when popTransform() is called.
Chris Craik69e5adf2014-08-14 13:34:01 -070050 void pushTransform(const RenderNode* transform);
51 void pushTransform(const Matrix4* transform);
John Recka447d292014-06-11 18:39:44 -070052
John Recke4267ea2014-06-03 15:53:15 -070053 // Pops a transform node from the stack, propagating the dirty rect
John Recka447d292014-06-11 18:39:44 -070054 // up to the parent node. Returns the IDamageTransform that was just applied
Chris Craik69e5adf2014-08-14 13:34:01 -070055 void popTransform();
John Recka447d292014-06-11 18:39:44 -070056
Chris Craik69e5adf2014-08-14 13:34:01 -070057 void dirty(float left, float top, float right, float bottom);
John Recke4267ea2014-06-03 15:53:15 -070058
John Reck25fbb3f2014-06-12 13:46:45 -070059 // Returns the current dirty area, *NOT* transformed by pushed transforms
Chris Craikc71bfca2014-08-21 10:18:58 -070060 void peekAtDirty(SkRect* dest) const;
Chris Craik69e5adf2014-08-14 13:34:01 -070061
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -050062 void computeCurrentTransform(Matrix4* outMatrix) const;
John Reck25fbb3f2014-06-12 13:46:45 -070063
John Reck1b152e72023-10-24 20:43:22 -040064 SkRect computeClipAndTransform(const SkRect& bounds, Matrix4* outMatrix) const;
65
John Recke4267ea2014-06-03 15:53:15 -070066 void finish(SkRect* totalDirty);
67
Nader Jawad197743f2021-04-19 19:45:13 -070068 struct StretchResult {
69 /**
70 * Stretch parameters configured on the stretch container
71 */
72 const StretchEffect* stretchEffect;
73
74 /**
Nader Jawadaf29d232023-04-17 19:53:58 -070075 * Bounds of the stretching container
Nader Jawad197743f2021-04-19 19:45:13 -070076 */
Nader Jawadaf29d232023-04-17 19:53:58 -070077 const SkRect parentBounds;
Nader Jawad197743f2021-04-19 19:45:13 -070078
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;
John Reck5d53a752021-02-08 19:22:59 -050091
John Recke4267ea2014-06-03 15:53:15 -070092private:
John Recka447d292014-06-11 18:39:44 -070093 void pushCommon();
94 void applyMatrix4Transform(DirtyStack* frame);
95 void applyRenderNodeTransform(DirtyStack* frame);
96
John Recke4267ea2014-06-03 15:53:15 -070097 LinearAllocator mAllocator;
98 DirtyStack* mHead;
99};
100
John Recke4267ea2014-06-03 15:53:15 -0700101} /* namespace uirenderer */
102} /* namespace android */
103
104#endif /* DAMAGEACCUMULATOR_H */