[dali_1.0.1] Merge branch 'tizen'
[platform/core/uifw/dali-core.git] / dali / internal / render / gl-resources / texture-factory.cpp
1 /*
2  * Copyright (c) 2014 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 #include "texture-factory.h"
19
20 #include <dali/integration-api/bitmap.h>
21 #include <dali/internal/render/gl-resources/texture.h>
22 #include <dali/internal/render/gl-resources/bitmap-texture.h>
23 #include <dali/internal/render/gl-resources/compressed-bitmap-texture.h>
24 #include <dali/internal/render/gl-resources/native-texture.h>
25 #include <dali/internal/render/gl-resources/frame-buffer-texture.h>
26 #include <dali/internal/render/gl-resources/native-frame-buffer-texture.h>
27 #include <dali/public-api/images/native-image.h>
28
29
30 namespace Dali
31 {
32 class NativeImage;
33
34 namespace Internal
35 {
36
37 namespace TextureFactory
38 {
39
40 Internal::Texture* NewBitmapTexture( Integration::Bitmap* const bitmap, Context& context )
41 {
42   DALI_ASSERT_DEBUG( bitmap );
43   Texture * texture = 0;
44   Integration::Bitmap::PackedPixelsProfile * const  packedPixelBitmapView = bitmap->GetPackedPixelsProfile();
45   if( packedPixelBitmapView )
46   {
47     texture = new BitmapTexture( bitmap, packedPixelBitmapView, context );
48   }
49   else
50   {
51     Internal::BitmapCompressed * const compressedBitmap = dynamic_cast<Dali::Internal::BitmapCompressed*>( bitmap );
52     if( compressedBitmap != 0 )
53     {
54       texture = new CompressedBitmapTexture( compressedBitmap, context );
55     }
56   }
57   if( texture )
58   {
59     if( !texture->Init() )
60     {
61       delete texture;
62       return NULL;
63     }
64   }
65   return texture;
66 }
67
68 Internal::Texture* NewBitmapTexture( unsigned int      width,
69                                      unsigned int      height,
70                                      Pixel::Format     pixelFormat,
71                                      bool              clearPixels,
72                                      Context&          context )
73 {
74   Texture *texture=new BitmapTexture(width, height, pixelFormat, clearPixels, context);
75
76   return texture;
77 }
78
79
80 Internal::Texture* NewNativeImageTexture( NativeImage& nativeImg, Context& context )
81 {
82   NativeTexture* texture = new NativeTexture(&nativeImg, context);
83   if (!texture->Init())
84   {
85     delete texture;
86     return NULL;
87   }
88   return texture;
89 }
90
91 Internal::Texture* NewFrameBufferTexture( unsigned int width,
92                                           unsigned int height,
93                                           Pixel::Format pixelFormat,
94                                           Context& context )
95 {
96   FrameBufferTexture* texture = new FrameBufferTexture(width, height, pixelFormat, context);
97   if (!texture->Init())
98   {
99     delete texture;
100     return NULL;
101   }
102   return texture;
103 }
104
105 Internal::Texture* NewFrameBufferTexture( NativeImagePtr nativeImage,
106                                           Context& context )
107 {
108   NativeFrameBufferTexture* texture = new NativeFrameBufferTexture(nativeImage, context);
109   if (!texture->Init())
110   {
111     delete texture;
112     return NULL;
113   }
114   return texture;
115 }
116
117
118
119 } // TextureFactory
120 } // Internal
121 } // Dali
122