Test harness: Moved CompareType<> templates to own header
[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/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/gl-texture.h>
27
28
29 namespace Dali
30 {
31 class NativeImageInterface;
32
33 namespace Internal
34 {
35
36 namespace TextureFactory
37 {
38
39 Internal::Texture* NewBitmapTexture( Integration::Bitmap* const bitmap, Context& context, ResourcePolicy::Discardable discardPolicy )
40 {
41   DALI_ASSERT_DEBUG( bitmap );
42   Texture * texture = 0;
43   Integration::Bitmap::PackedPixelsProfile * const  packedPixelBitmapView = bitmap->GetPackedPixelsProfile();
44   if( packedPixelBitmapView )
45   {
46     texture = new BitmapTexture( bitmap, packedPixelBitmapView, context, discardPolicy );
47   }
48   else
49   {
50     Internal::BitmapCompressed * const compressedBitmap = dynamic_cast<Dali::Internal::BitmapCompressed*>( bitmap );
51     if( compressedBitmap != 0 )
52     {
53       texture = new CompressedBitmapTexture( compressedBitmap, context, discardPolicy );
54     }
55   }
56   if( texture )
57   {
58     if( !texture->Init() )
59     {
60       delete texture;
61       return NULL;
62     }
63   }
64   return texture;
65 }
66
67 Internal::Texture* NewBitmapTexture( unsigned int      width,
68                                      unsigned int      height,
69                                      Pixel::Format     pixelFormat,
70                                      bool              clearPixels,
71                                      Context&          context,
72                                      ResourcePolicy::Discardable discardPolicy )
73 {
74   Texture *texture=new BitmapTexture(width, height, pixelFormat, clearPixels, context, discardPolicy);
75
76   return texture;
77 }
78
79
80 Internal::Texture* NewNativeImageTexture( NativeImageInterface& 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                                           RenderBuffer::Format bufferFormat,
95                                           Context& context )
96 {
97   FrameBufferTexture* texture = new FrameBufferTexture(width, height, pixelFormat, bufferFormat, 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   FrameBufferTexture* texture = new FrameBufferTexture(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