X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fupdate%2Fcommon%2Fdouble-buffered.h;h=65f7cd698fa30bacf3868d562e902eedde42f5b5;hb=1fdfbc2906bc1dcae714eedfbe6c7f94cd6f9364;hp=1662c3e8125de7ad9ce819c6aebcd8b03123f1da;hpb=ce20e9f082e811130930d13c9e9edc1da4ce1013;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/update/common/double-buffered.h b/dali/internal/update/common/double-buffered.h index 1662c3e..65f7cd6 100644 --- a/dali/internal/update/common/double-buffered.h +++ b/dali/internal/update/common/double-buffered.h @@ -1,50 +1,48 @@ -#ifndef __DALI_INTERNAL_SCENE_GRAPH_DOUBLE_BUFFERED_H__ -#define __DALI_INTERNAL_SCENE_GRAPH_DOUBLE_BUFFERED_H__ - -// -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.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://floralicense.org/license/ -// -// 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. -// +#ifndef DALI_INTERNAL_SCENE_GRAPH_DOUBLE_BUFFERED_H +#define DALI_INTERNAL_SCENE_GRAPH_DOUBLE_BUFFERED_H + +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * 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. + * + */ // INTERNAL INCLUDES -#include -#include -#include +#include +#include namespace Dali { - namespace Internal { - // The number of buffers per scene-graph property static const unsigned int NUM_SCENE_GRAPH_BUFFERS = 2; -// Buffer index used when reading off-stage values -static const unsigned int ARBITRARY_OFF_STAGE_BUFFER = 0; - namespace SceneGraph { - /** * Templated class for a double-buffered value. - * This simplifies init code, and forces explicit initialization. */ -template +template class DoubleBuffered { public: + DoubleBuffered() + : mValue1(), + mValue2() + { + } DoubleBuffered(const T& val) : mValue1(val), @@ -52,22 +50,21 @@ public: { } - inline T& operator[](const size_t i) + inline T& operator[](const BufferIndex i) { DALI_ASSERT_DEBUG(i < NUM_SCENE_GRAPH_BUFFERS); - return *(&mValue1+i); + return *(&mValue1 + i); } - inline const T& operator[](const size_t i) const + inline const T& operator[](const BufferIndex i) const { DALI_ASSERT_DEBUG(i < NUM_SCENE_GRAPH_BUFFERS); - return *(&mValue1+i); + return *(&mValue1 + i); } private: - // Undefined DoubleBuffered(const DoubleBuffered&); @@ -75,124 +72,145 @@ private: DoubleBuffered& operator=(const DoubleBuffered& rhs); private: - T mValue1; T mValue2; }; /** - * Templated class for a double-buffered value, initialized with 3 value parameters. - * This simplifies init code, and forces explicit initialization. + * @brief Specialization for owner-pointer + * + * This class takes ownership of the pointers and releases the memory when the pointer + * is no longer used by either buffer */ -template -class DoubleBuffered3 +template +class DoubleBuffered > { public: - - DoubleBuffered3(const T& val) - : mValue1(val), - mValue2(val) + /** + * Class that deals with setting a value + */ + class Setter { - } - - DoubleBuffered3(P val1, P val2, P val3) - : mValue1(val1, val2, val3), - mValue2(val1, val2, val3) + public: + /** + * @brief Assignment operator to that a value that will later + * be set in the correct buffer index of the object referenced by the setter. + */ + Setter& operator=(T* value) + { + mValue = value; + return *this; + } + + ~Setter() + { + mObject.Set(mIndex, mValue); + } + + private: + Setter(DoubleBuffered& object, + BufferIndex i, + T* value) + : mObject(object), + mIndex(i), + mValue(value) + { + } + + Setter(const Setter& rhs) + : mObject(rhs.mObject), + mIndex(rhs.mIndex), + mValue(rhs.mValue) + { + } + + DoubleBuffered& mObject; ///< Double-buffered object that will be changed + const BufferIndex mIndex; ///< Buffer index that will be changed + T* mValue; ///< Value of the pointer + + friend class DoubleBuffered; + }; + + DoubleBuffered() + : mValue1(NULL), + mValue2(NULL) { } - inline T& operator[](const size_t i) + DoubleBuffered(T* val) + : mValue1(val), + mValue2(val) { - DALI_ASSERT_DEBUG(i < NUM_SCENE_GRAPH_BUFFERS); - - return *(&mValue1+i); } - inline const T& operator[](const size_t i) const + ~DoubleBuffered() { - DALI_ASSERT_DEBUG(i < NUM_SCENE_GRAPH_BUFFERS); - - return *(&mValue1+i); + if(mValue2 != mValue1) + { + delete mValue2; + } + delete mValue1; } -private: - - // Undefined - DoubleBuffered3(const DoubleBuffered3&); - - // Undefined - DoubleBuffered3& operator=(const DoubleBuffered3& rhs); - -private: - - T mValue1; - T mValue2; -}; - -/** - * Templated class for a double-buffered value, initialized with 4 value parameters. - * This simplifies init code, and forces explicit initialization. - */ -template -class DoubleBuffered4 -{ -public: - - DoubleBuffered4(const T& val) - : mValue1(val), - mValue2(val) + void Set(BufferIndex i, T* value) { + T*& current = *(&mValue1 + i); + T*& previous = *(&mValue1 + 1u - i); + + if(current != value && current != previous) + { + delete current; + } + current = value; } - DoubleBuffered4(P val1, P val2, P val3, P val4) - : mValue1(val1, val2, val3, val4), - mValue2(val1, val2, val3, val4) + Setter operator[](BufferIndex i) { + return Setter(*this, i, *(&mValue1 + i)); } - inline T& operator[](const size_t i) + const T* operator[](BufferIndex i) const { DALI_ASSERT_DEBUG(i < NUM_SCENE_GRAPH_BUFFERS); - return *(&mValue1+i); + return *(&mValue1 + i); } - inline const T& operator[](const size_t i) const + /** + * Auto-age the property: if it was set the previous frame, + * then copy the value into the current frame's buffer. + */ + void CopyPrevious(BufferIndex i) { DALI_ASSERT_DEBUG(i < NUM_SCENE_GRAPH_BUFFERS); - return *(&mValue1+i); + T*& current = *(&mValue1 + i); + T*& previous = *(&mValue1 + 1u - i); + + if(current != previous) + { + delete current; + } + + current = previous; } private: - // Undefined - DoubleBuffered4(const DoubleBuffered4&); + DoubleBuffered(const DoubleBuffered&); // Undefined - DoubleBuffered4& operator=(const DoubleBuffered4& rhs); + DoubleBuffered& operator=(const DoubleBuffered& rhs); private: - - T mValue1; - T mValue2; + T* mValue1; + T* mValue2; }; -typedef DoubleBuffered DoubleBufferedInt; -typedef DoubleBuffered DoubleBufferedFloat; -typedef DoubleBuffered DoubleBufferedBool; - -typedef DoubleBuffered3 DoubleBufferedVector3; -typedef DoubleBuffered4 DoubleBufferedVector4; - -typedef DoubleBuffered4 DoubleBufferedQuaternion; - -typedef DoubleBuffered DoubleBufferedMatrix; - } // namespace SceneGraph } // namespace Internal } // namespace Dali -#endif // __DALI_INTERNAL_SCENE_GRAPH_DOUBLE_BUFFERED_H__ +#endif // DALI_INTERNAL_SCENE_GRAPH_DOUBLE_BUFFERED_H