Merge "Merge Handle & Constrainable" into 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/integration-api/gl-defines.h>
22 #include <dali/internal/render/gl-resources/texture.h>
23 #include <dali/internal/render/gl-resources/bitmap-texture.h>
24 #include <dali/internal/render/gl-resources/compressed-bitmap-texture.h>
25 #include <dali/internal/render/gl-resources/native-texture.h>
26 #include <dali/internal/render/gl-resources/frame-buffer-texture.h>
27 #include <dali/internal/render/gl-resources/native-frame-buffer-texture.h>
28
29
30 namespace Dali
31 {
32 class NativeImageInterface;
33
34 namespace Internal
35 {
36
37 namespace TextureFactory
38 {
39
40 Internal::Texture* NewBitmapTexture( Integration::Bitmap* const bitmap, Context& context, ResourcePolicy::Discardable discardPolicy )
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, discardPolicy );
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, discardPolicy );
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                                      ResourcePolicy::Discardable discardPolicy )
74 {
75   Texture *texture=new BitmapTexture(width, height, pixelFormat, clearPixels, context, discardPolicy);
76
77   return texture;
78 }
79
80
81 Internal::Texture* NewNativeImageTexture( NativeImageInterface& nativeImg, Context& context )
82 {
83   NativeTexture* texture = new NativeTexture(&nativeImg, context);
84   if (!texture->Init())
85   {
86     delete texture;
87     return NULL;
88   }
89   return texture;
90 }
91
92 Internal::Texture* NewFrameBufferTexture( unsigned int width,
93                                           unsigned int height,
94                                           Pixel::Format pixelFormat,
95                                           Context& context )
96 {
97   FrameBufferTexture* texture = new FrameBufferTexture(width, height, pixelFormat, context);
98   if (!texture->Init())
99   {
100     delete texture;
101     return NULL;
102   }
103   return texture;
104 }
105
106 Internal::Texture* NewFrameBufferTexture( NativeImageInterfacePtr nativeImage,
107                                           Context& context )
108 {
109   NativeFrameBufferTexture* texture = new NativeFrameBufferTexture(nativeImage, context);
110   if (!texture->Init())
111   {
112     delete texture;
113     return NULL;
114   }
115   return texture;
116 }
117
118
119
120 } // TextureFactory
121 } // Internal
122 } // Dali