Allow to create EncodedImageBuffer by moved data
[platform/core/uifw/dali-adaptor.git] / dali / internal / imaging / common / encoded-image-buffer-impl.cpp
1 /*
2  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
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  */
17
18 // CLASS HEADER
19 #include <dali/internal/imaging/common/encoded-image-buffer-impl.h>
20
21 // EXTERNAL INCLUDE
22 #include <dali/devel-api/common/hash.h>
23
24 namespace Dali
25 {
26 namespace Internal
27 {
28 EncodedImageBuffer::EncodedImageBuffer(const RawBufferType& buffer, ImageType type)
29 : mBuffer(buffer),
30   mType(type)
31 {
32   mBufferHash = CalculateHash(mBuffer);
33 }
34
35 EncodedImageBuffer::EncodedImageBuffer(RawBufferType&& buffer, ImageType type)
36 : mBuffer(std::move(buffer)),
37   mType(type)
38 {
39   mBufferHash = CalculateHash(mBuffer);
40 }
41
42 EncodedImageBuffer::~EncodedImageBuffer()
43 {
44 }
45
46 IntrusivePtr<EncodedImageBuffer> EncodedImageBuffer::New(const RawBufferType& buffer, ImageType type)
47 {
48   IntrusivePtr<EncodedImageBuffer> internal = new EncodedImageBuffer(buffer, type);
49
50   return internal;
51 }
52
53 IntrusivePtr<EncodedImageBuffer> EncodedImageBuffer::New(RawBufferType&& buffer, ImageType type)
54 {
55   IntrusivePtr<EncodedImageBuffer> internal = new EncodedImageBuffer(std::move(buffer), type);
56
57   return internal;
58 }
59
60 const EncodedImageBuffer::RawBufferType& EncodedImageBuffer::GetRawBuffer() const
61 {
62   return mBuffer;
63 }
64
65 std::size_t EncodedImageBuffer::GetHash() const
66 {
67   return mBufferHash;
68 }
69
70 void EncodedImageBuffer::SetImageType(Dali::EncodedImageBuffer::ImageType type)
71 {
72   mType = type;
73 }
74
75 Dali::EncodedImageBuffer::ImageType EncodedImageBuffer::GetImageType() const
76 {
77   return mType;
78 }
79
80 } // namespace Internal
81
82 } // namespace Dali