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 | |
| 27 | namespace android { |
| 28 | namespace uirenderer { |
| 29 | |
| 30 | struct DirtyStack; |
| 31 | class RenderNode; |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 32 | class Matrix4; |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 33 | |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 34 | class IDamageAccumulator { |
| 35 | public: |
| 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; |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 40 | virtual void peekAtDirty(SkRect* dest) = 0; |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 41 | protected: |
| 42 | virtual ~IDamageAccumulator() {} |
| 43 | }; |
| 44 | |
| 45 | class DamageAccumulator : public IDamageAccumulator { |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 46 | PREVENT_COPY_AND_ASSIGN(DamageAccumulator); |
| 47 | public: |
| 48 | DamageAccumulator(); |
| 49 | // mAllocator will clean everything up for us, no need for a dtor |
| 50 | |
| 51 | // Push a transform node onto the stack. This should be called prior |
| 52 | // to any dirty() calls. Subsequent calls to dirty() |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 53 | // will be affected by the transform when popTransform() is called. |
| 54 | virtual void pushTransform(const RenderNode* transform); |
| 55 | virtual void pushTransform(const Matrix4* transform); |
| 56 | |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 57 | // Pops a transform node from the stack, propagating the dirty rect |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 58 | // up to the parent node. Returns the IDamageTransform that was just applied |
| 59 | virtual void popTransform(); |
| 60 | |
| 61 | virtual void dirty(float left, float top, float right, float bottom); |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 62 | |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 63 | // Returns the current dirty area, *NOT* transformed by pushed transforms |
| 64 | virtual void peekAtDirty(SkRect* dest); |
| 65 | |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 66 | void finish(SkRect* totalDirty); |
| 67 | |
| 68 | private: |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 69 | void pushCommon(); |
| 70 | void applyMatrix4Transform(DirtyStack* frame); |
| 71 | void applyRenderNodeTransform(DirtyStack* frame); |
| 72 | |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 73 | LinearAllocator mAllocator; |
| 74 | DirtyStack* mHead; |
| 75 | }; |
| 76 | |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 77 | class NullDamageAccumulator : public IDamageAccumulator { |
| 78 | PREVENT_COPY_AND_ASSIGN(NullDamageAccumulator); |
| 79 | public: |
| 80 | virtual void pushTransform(const RenderNode* transform) { } |
| 81 | virtual void pushTransform(const Matrix4* transform) { } |
| 82 | virtual void popTransform() { } |
| 83 | virtual void dirty(float left, float top, float right, float bottom) { } |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 84 | virtual void peekAtDirty(SkRect* dest) { dest->setEmpty(); } |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 85 | |
| 86 | ANDROID_API static NullDamageAccumulator* instance(); |
| 87 | |
| 88 | private: |
| 89 | NullDamageAccumulator() {} |
| 90 | ~NullDamageAccumulator() {} |
| 91 | |
| 92 | static NullDamageAccumulator sInstance; |
| 93 | }; |
| 94 | |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 95 | } /* namespace uirenderer */ |
| 96 | } /* namespace android */ |
| 97 | |
| 98 | #endif /* DAMAGEACCUMULATOR_H */ |