John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 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 | |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 19 | #include <cutils/compiler.h> |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 20 | #include <utils/LinearAllocator.h> |
| 21 | |
| 22 | #include <SkMatrix.h> |
| 23 | #include <SkRect.h> |
| 24 | |
| 25 | #include "utils/Macros.h" |
| 26 | |
John Reck | c128823 | 2015-08-12 13:39:11 -0700 | [diff] [blame] | 27 | // 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 |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 29 | #define DIRTY_MIN (-0x7ffffff - 1) |
John Reck | c128823 | 2015-08-12 13:39:11 -0700 | [diff] [blame] | 30 | #define DIRTY_MAX (0x7ffffff) |
| 31 | |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 32 | namespace android { |
| 33 | namespace uirenderer { |
| 34 | |
| 35 | struct DirtyStack; |
| 36 | class RenderNode; |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 37 | class Matrix4; |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 38 | |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame] | 39 | class DamageAccumulator { |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 40 | PREVENT_COPY_AND_ASSIGN(DamageAccumulator); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 41 | |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 42 | public: |
| 43 | DamageAccumulator(); |
| 44 | // mAllocator will clean everything up for us, no need for a dtor |
| 45 | |
| 46 | // Push a transform node onto the stack. This should be called prior |
| 47 | // to any dirty() calls. Subsequent calls to dirty() |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 48 | // will be affected by the transform when popTransform() is called. |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame] | 49 | void pushTransform(const RenderNode* transform); |
| 50 | void pushTransform(const Matrix4* transform); |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 51 | |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 52 | // Pops a transform node from the stack, propagating the dirty rect |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 53 | // up to the parent node. Returns the IDamageTransform that was just applied |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame] | 54 | void popTransform(); |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 55 | |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame] | 56 | void dirty(float left, float top, float right, float bottom); |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 57 | |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 58 | // Returns the current dirty area, *NOT* transformed by pushed transforms |
Chris Craik | c71bfca | 2014-08-21 10:18:58 -0700 | [diff] [blame] | 59 | void peekAtDirty(SkRect* dest) const; |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame] | 60 | |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 61 | ANDROID_API void computeCurrentTransform(Matrix4* outMatrix) const; |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 62 | |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 63 | void finish(SkRect* totalDirty); |
| 64 | |
| 65 | private: |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 66 | void pushCommon(); |
| 67 | void applyMatrix4Transform(DirtyStack* frame); |
| 68 | void applyRenderNodeTransform(DirtyStack* frame); |
| 69 | |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 70 | LinearAllocator mAllocator; |
| 71 | DirtyStack* mHead; |
| 72 | }; |
| 73 | |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 74 | } /* namespace uirenderer */ |
| 75 | } /* namespace android */ |
| 76 | |
| 77 | #endif /* DAMAGEACCUMULATOR_H */ |