[dali_1.9.22] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / public-api / rendering / texture.cpp
1 /*
2  * Copyright (c) 2020 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/public-api/rendering/texture.h>          // Dali::Texture
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/event/rendering/texture-impl.h> // Dali::Internal::Texture
23 #include <dali/internal/event/images/pixel-data-impl.h> // Dali::Internal::PixelData
24
25
26 namespace Dali
27 {
28
29 Texture Texture::New( TextureType::Type type, Pixel::Format format, uint32_t width, uint32_t height )
30 {
31   Internal::TexturePtr texture = Internal::Texture::New(type, format, width, height );
32   return Texture( texture.Get() );
33 }
34
35 Texture Texture::New( NativeImageInterface& nativeImageInterface )
36 {
37   Internal::TexturePtr texture = Internal::Texture::New( nativeImageInterface );
38   return Texture( texture.Get() );
39 }
40
41 Texture::Texture()
42 {
43 }
44
45 Texture::~Texture()
46 {
47 }
48
49 Texture::Texture( const Texture& handle )
50 : BaseHandle( handle )
51 {
52 }
53
54 Texture Texture::DownCast( BaseHandle handle )
55 {
56   return Texture( dynamic_cast<Dali::Internal::Texture*>(handle.GetObjectPtr()));
57 }
58
59 Texture& Texture::operator=( const Texture& handle )
60 {
61   BaseHandle::operator=( handle );
62   return *this;
63 }
64
65 Texture::Texture( Texture&& rhs ) =  default;
66
67 Texture& Texture::operator=( Texture&& rhs ) =  default;
68
69 bool Texture::Upload( PixelData pixelData )
70 {
71   Internal::PixelData& internalPixelData = GetImplementation( pixelData );
72   return GetImplementation(*this).Upload( &internalPixelData );
73 }
74
75 bool Texture::Upload( PixelData pixelData,
76                uint32_t layer, uint32_t mipmap,
77                uint32_t xOffset, uint32_t yOffset,
78                uint32_t width, uint32_t height )
79 {
80   Internal::PixelData& internalPixelData = GetImplementation( pixelData );
81   return GetImplementation(*this).Upload( &internalPixelData, layer, mipmap, xOffset, yOffset, width, height );
82 }
83
84 void Texture::GenerateMipmaps()
85 {
86   return GetImplementation(*this).GenerateMipmaps();
87 }
88
89 uint32_t Texture::GetWidth() const
90 {
91   return GetImplementation(*this).GetWidth();
92 }
93
94 uint32_t Texture::GetHeight() const
95 {
96   return GetImplementation(*this).GetHeight();
97 }
98
99 Texture::Texture( Internal::Texture* pointer )
100 : BaseHandle( pointer )
101 {
102 }
103
104 } //namespace Dali