common: revise the identifier() implementation
[platform/core/graphics/tizenvg.git] / src / lib / tvgPaint.h
index 31dcbf4..8cfae71 100644 (file)
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *               http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- *
+ * Copyright (c) 2020-2021 Samsung Electronics Co., Ltd. All rights reserved.
+
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
  */
 #ifndef _TVG_PAINT_H_
 #define _TVG_PAINT_H_
 
+#include "tvgRender.h"
+
+
 namespace tvg
 {
-    struct PaintMethod
+    enum ContextFlag {Invalid = 0, FastTrack = 1};
+
+    struct Iterator
+    {
+        virtual ~Iterator() {}
+        virtual const Paint* next() = 0;
+        virtual uint32_t count() = 0;
+        virtual void begin() = 0;
+    };
+
+    struct StrategyMethod
     {
-        virtual ~PaintMethod(){}
+        virtual ~StrategyMethod() {}
 
         virtual bool dispose(RenderMethod& renderer) = 0;
-        virtual bool update(RenderMethod& renderer, const RenderTransform* pTransform, uint32_t pFlag) = 0;
+        virtual void* update(RenderMethod& renderer, const RenderTransform* transform, uint32_t opacity, Array<RenderData>& clips, RenderUpdateFlag pFlag) = 0;   //Return engine data if it has.
         virtual bool render(RenderMethod& renderer) = 0;
-
-        virtual bool rotate(float degree) = 0;
-        virtual bool scale(float factor) = 0;
-        virtual bool translate(float x, float y) = 0;
-        virtual bool transform(const Matrix& m) = 0;
-        virtual bool bounds(float* x, float* y, float* w, float* h) const = 0;
-
+        virtual bool bounds(float* x, float* y, float* w, float* h) = 0;
+        virtual RenderRegion bounds(RenderMethod& renderer) const = 0;
+        virtual Paint* duplicate() = 0;
+        virtual Iterator* iterator() = 0;
     };
 
     struct Paint::Impl
     {
-        PaintMethod* method = nullptr;
+        StrategyMethod* smethod = nullptr;
+        RenderTransform* rTransform = nullptr;
+        uint32_t renderFlag = RenderUpdateFlag::None;
+        Paint* cmpTarget = nullptr;
+        CompositeMethod cmpMethod = CompositeMethod::None;
+        uint32_t ctxFlag = ContextFlag::Invalid;
+        uint32_t id;
+        uint8_t opacity = 255;
 
         ~Impl() {
-            if (method) delete(method);
+            if (cmpTarget) delete(cmpTarget);
+            if (smethod) delete(smethod);
+            if (rTransform) delete(rTransform);
         }
-    };
 
+        void method(StrategyMethod* method)
+        {
+            smethod = method;
+        }
 
-    template<class T>
-    struct TransformMethod : PaintMethod
-    {
-        T* inst = nullptr;
+        bool transform(const Matrix& m)
+        {
+            if (!rTransform) {
+                rTransform = new RenderTransform();
+                if (!rTransform) return false;
+            }
+            rTransform->override(m);
+            renderFlag |= RenderUpdateFlag::Transform;
+
+            return true;
+        }
 
-        TransformMethod(T* inst) : inst(_inst) {}
-        ~TransformMethod(){}
+        Matrix* transform()
+        {
+            if (rTransform) {
+                rTransform->update();
+                return &rTransform->m;
+            }
+            return nullptr;
+        }
 
-        bool rotate(float degree) override
+        RenderRegion bounds(RenderMethod& renderer) const
         {
-            return inst->rotate(degree);
+            return smethod->bounds(renderer);
         }
 
-        bool scale(float factor) override
+        bool dispose(RenderMethod& renderer)
         {
-            return inst->scale(factor);
+            if (cmpTarget) cmpTarget->pImpl->dispose(renderer);
+            return smethod->dispose(renderer);
         }
 
-        bool translate(float x, float y) override
+        Iterator* iterator()
         {
-            return inst->translate(x, y);
+            return smethod->iterator();
         }
 
-        bool transform(const Matrix& m) override
+        bool composite(Paint* target, CompositeMethod method)
         {
-            return inst->transform(m);
+            if ((!target && method != CompositeMethod::None) || (target && method == CompositeMethod::None)) return false;
+            if (cmpTarget) delete(cmpTarget);
+            cmpTarget = target;
+            cmpMethod = method;
+            return true;
         }
 
-        bool bounds(float* x, float* y, float* w, float* h) const override
+        bool rotate(float degree);
+        bool scale(float factor);
+        bool translate(float x, float y);
+        bool bounds(float* x, float* y, float* w, float* h, bool transformed);
+        void* update(RenderMethod& renderer, const RenderTransform* pTransform, uint32_t opacity, Array<RenderData>& clips, uint32_t pFlag);
+        bool render(RenderMethod& renderer);
+        Paint* duplicate();
+    };
+
+
+    template<class T>
+    struct PaintMethod : StrategyMethod
+    {
+        T* inst = nullptr;
+
+        PaintMethod(T* _inst) : inst(_inst) {}
+        ~PaintMethod() {}
+
+        bool bounds(float* x, float* y, float* w, float* h) override
         {
             return inst->bounds(x, y, w, h);
         }
 
-        bool dispose(RenderMethod& renderer)
+        RenderRegion bounds(RenderMethod& renderer) const override
+        {
+            return inst->bounds(renderer);
+        }
+
+        bool dispose(RenderMethod& renderer) override
         {
             return inst->dispose(renderer);
         }
 
-        bool update(RenderMethod& renderer, const RenderTransform* pTransform, uint32_t pFlag)
+        void* update(RenderMethod& renderer, const RenderTransform* transform, uint32_t opacity, Array<RenderData>& clips, RenderUpdateFlag renderFlag) override
         {
-            return inst->update(renderer, pTransform, pFlag);
+            return inst->update(renderer, transform, opacity, clips, renderFlag);
         }
 
-        bool render(RenderMethod& renderer)
+        bool render(RenderMethod& renderer) override
         {
             return inst->render(renderer);
         }
+
+        Paint* duplicate() override
+        {
+            return inst->duplicate();
+        }
+
+        Iterator* iterator() override
+        {
+            return inst->iterator();
+        }
     };
 }
 
-#endif //_TVG_PAINT_H_
\ No newline at end of file
+#endif //_TVG_PAINT_H_