blob: 250296ecc89f33053d022731c206dfb0710d4d0a [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
John Reckc1288232015-08-12 13:39:11 -070027// Smaller than INT_MIN/INT_MAX because we offset these values
28// and thus don't want to be adding offsets to INT_MAX, that's bad
29#define DIRTY_MIN (-0x7ffffff-1)
30#define DIRTY_MAX (0x7ffffff)
31
John Recke4267ea2014-06-03 15:53:15 -070032namespace android {
33namespace uirenderer {
34
35struct DirtyStack;
36class RenderNode;
John Recka447d292014-06-11 18:39:44 -070037class Matrix4;
John Recke4267ea2014-06-03 15:53:15 -070038
Chris Craik69e5adf2014-08-14 13:34:01 -070039class DamageAccumulator {
John Recke4267ea2014-06-03 15:53:15 -070040 PREVENT_COPY_AND_ASSIGN(DamageAccumulator);
41public:
42 DamageAccumulator();
43 // mAllocator will clean everything up for us, no need for a dtor
44
45 // Push a transform node onto the stack. This should be called prior
46 // to any dirty() calls. Subsequent calls to dirty()
John Recka447d292014-06-11 18:39:44 -070047 // will be affected by the transform when popTransform() is called.
Chris Craik69e5adf2014-08-14 13:34:01 -070048 void pushTransform(const RenderNode* transform);
49 void pushTransform(const Matrix4* transform);
John Recka447d292014-06-11 18:39:44 -070050
John Recke4267ea2014-06-03 15:53:15 -070051 // Pops a transform node from the stack, propagating the dirty rect
John Recka447d292014-06-11 18:39:44 -070052 // up to the parent node. Returns the IDamageTransform that was just applied
Chris Craik69e5adf2014-08-14 13:34:01 -070053 void popTransform();
John Recka447d292014-06-11 18:39:44 -070054
Chris Craik69e5adf2014-08-14 13:34:01 -070055 void dirty(float left, float top, float right, float bottom);
John Recke4267ea2014-06-03 15:53:15 -070056
John Reck25fbb3f2014-06-12 13:46:45 -070057 // Returns the current dirty area, *NOT* transformed by pushed transforms
Chris Craikc71bfca2014-08-21 10:18:58 -070058 void peekAtDirty(SkRect* dest) const;
Chris Craik69e5adf2014-08-14 13:34:01 -070059
John Reckf6481082016-02-02 15:18:23 -080060 ANDROID_API void computeCurrentTransform(Matrix4* outMatrix) const;
John Reck25fbb3f2014-06-12 13:46:45 -070061
John Recke4267ea2014-06-03 15:53:15 -070062 void finish(SkRect* totalDirty);
63
64private:
John Recka447d292014-06-11 18:39:44 -070065 void pushCommon();
66 void applyMatrix4Transform(DirtyStack* frame);
67 void applyRenderNodeTransform(DirtyStack* frame);
68
John Recke4267ea2014-06-03 15:53:15 -070069 LinearAllocator mAllocator;
70 DirtyStack* mHead;
71};
72
John Recke4267ea2014-06-03 15:53:15 -070073} /* namespace uirenderer */
74} /* namespace android */
75
76#endif /* DAMAGEACCUMULATOR_H */