Merge "Updated test harness code to enable styling through links." 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 #include <dali/public-api/images/native-image.h>
29
30
31 namespace Dali
32 {
33 class NativeImage;
34
35 namespace Internal
36 {
37
38 namespace TextureFactory
39 {
40
41 Internal::Texture* NewBitmapTexture( Integration::Bitmap* const bitmap, Context& context, ResourcePolicy::Discardable discardPolicy )
42 {
43   DALI_ASSERT_DEBUG( bitmap );
44   Texture * texture = 0;
45   Integration::Bitmap::PackedPixelsProfile * const  packedPixelBitmapView = bitmap->GetPackedPixelsProfile();
46   if( packedPixelBitmapView )
47   {
48     texture = new BitmapTexture( bitmap, packedPixelBitmapView, context, discardPolicy );
49   }
50   else
51   {
52     Internal::BitmapCompressed * const compressedBitmap = dynamic_cast<Dali::Internal::BitmapCompressed*>( bitmap );
53     if( compressedBitmap != 0 )
54     {
55       texture = new CompressedBitmapTexture( compressedBitmap, context, discardPolicy );
56     }
57   }
58   if( texture )
59   {
60     if( !texture->Init() )
61     {
62       delete texture;
63       return NULL;
64     }
65   }
66   return texture;
67 }
68
69 Internal::Texture* NewBitmapTexture( unsigned int      width,
70                                      unsigned int      height,
71                                      Pixel::Format     pixelFormat,
72                                      bool              clearPixels,
73                                      Context&          context,
74                                      ResourcePolicy::Discardable discardPolicy )
75 {
76   Texture *texture=new BitmapTexture(width, height, pixelFormat, clearPixels, context, discardPolicy);
77
78   return texture;
79 }
80
81
82 Internal::Texture* NewNativeImageTexture( NativeImage& nativeImg, Context& context )
83 {
84   NativeTexture* texture = new NativeTexture(&nativeImg, context);
85   if (!texture->Init())
86   {
87     delete texture;
88     return NULL;
89   }
90   return texture;
91 }
92
93 Internal::Texture* NewFrameBufferTexture( unsigned int width,
94                                           unsigned int height,
95                                           Pixel::Format pixelFormat,
96                                           Context& context )
97 {
98   FrameBufferTexture* texture = new FrameBufferTexture(width, height, pixelFormat, context);
99   if (!texture->Init())
100   {
101     delete texture;
102     return NULL;
103   }
104   return texture;
105 }
106
107 Internal::Texture* NewFrameBufferTexture( NativeImagePtr nativeImage,
108                                           Context& context )
109 {
110   NativeFrameBufferTexture* texture = new NativeFrameBufferTexture(nativeImage, context);
111   if (!texture->Init())
112   {
113     delete texture;
114     return NULL;
115   }
116   return texture;
117 }
118
119
120
121 } // TextureFactory
122 } // Internal
123 } // Dali