2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/integration-api/bitmap.h>
24 #include <dali/integration-api/debug.h>
25 #include <dali/integration-api/platform-abstraction.h>
26 #include <dali/internal/event/common/thread-local-storage.h>
27 #include <dali/internal/event/images/bitmap-packed-pixel.h>
28 #include <dali/internal/event/images/bitmap-compressed.h>
29 #include <dali/internal/event/images/bitmap-external.h>
30 #include <dali/integration-api/gl-abstraction.h>
31 #include <dali/integration-api/gl-defines.h>
38 using namespace Dali::Pixel;
40 void ConvertToGlFormat( Format pixelformat, unsigned& pixelDataType, unsigned& internalFormat )
42 // Compressed textures have no pixelDataType, so init to an invalid value:
49 pixelDataType = GL_UNSIGNED_BYTE;
50 internalFormat= GL_ALPHA;
56 pixelDataType = GL_UNSIGNED_BYTE;
57 internalFormat= GL_LUMINANCE;
63 pixelDataType = GL_UNSIGNED_BYTE;
64 internalFormat= GL_LUMINANCE_ALPHA;
70 pixelDataType = GL_UNSIGNED_SHORT_5_6_5;
71 internalFormat= GL_RGB;
77 DALI_LOG_ERROR("Pixel format BGR565 is not supported by GLES.\n");
78 pixelDataType = GL_UNSIGNED_SHORT_5_6_5;
80 internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
82 internalFormat= GL_RGBA; // alpha is reserved but not used
89 pixelDataType = GL_UNSIGNED_SHORT_4_4_4_4;
90 internalFormat= GL_RGBA;
96 DALI_LOG_ERROR("Pixel format BGRA4444 is not supported by GLES.\n");
97 pixelDataType = GL_UNSIGNED_SHORT_4_4_4_4;
99 internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
101 internalFormat= GL_RGBA; // alpha is reserved but not used
108 pixelDataType = GL_UNSIGNED_SHORT_5_5_5_1;
109 internalFormat= GL_RGBA;
115 DALI_LOG_ERROR("Pixel format BGRA5551 is not supported by GLES.\n");
116 pixelDataType = GL_UNSIGNED_SHORT_5_5_5_1;
118 internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
120 internalFormat= GL_RGBA; // alpha is reserved but not used
127 pixelDataType = GL_UNSIGNED_BYTE;
128 internalFormat= GL_RGB;
134 pixelDataType = GL_UNSIGNED_BYTE;
135 internalFormat= GL_RGBA; // alpha is reserved but not used
141 pixelDataType = GL_UNSIGNED_BYTE;
143 internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
145 internalFormat= GL_RGBA; // alpha is reserved but not used
152 pixelDataType = GL_UNSIGNED_BYTE;
153 internalFormat= GL_RGBA;
159 pixelDataType = GL_UNSIGNED_BYTE;
161 internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
163 internalFormat= GL_RGBA; // alpha is reserved but not used
168 // GLES 3.0 standard compressed formats:
169 case COMPRESSED_R11_EAC:
171 DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_R11_EAC.\n");
172 internalFormat = 0x9270; ///! < Hardcoded until we move to GLES 3.0 or greater.
175 case COMPRESSED_SIGNED_R11_EAC:
177 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SIGNED_R11_EAC.\n" );
178 internalFormat = 0x9271; ///! < Hardcoded until we move to GLES 3.0 or greater.
182 case COMPRESSED_RG11_EAC:
184 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_RG11_EAC.\n" );
185 internalFormat = 0x9272; ///! < Hardcoded until we move to GLES 3.0 or greater.
188 case COMPRESSED_SIGNED_RG11_EAC:
190 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SIGNED_RG11_EAC.\n" );
191 internalFormat = 0x9273; ///! < Hardcoded until we move to GLES 3.0 or greater.
194 case COMPRESSED_RGB8_ETC2:
196 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_RGB8_ETC2.\n" );
197 internalFormat = 0x9274; ///! < Hardcoded until we move to GLES 3.0 or greater.
200 case COMPRESSED_SRGB8_ETC2:
202 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SRGB8_ETC2.\n" );
203 internalFormat = 0x9275; ///! < Hardcoded until we move to GLES 3.0 or greater.
206 case COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
208 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2.\n" );
209 internalFormat = 0x9276; ///! < Hardcoded until we move to GLES 3.0 or greater.
212 case COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
214 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2.\n" );
215 internalFormat = 0x9277; ///! < Hardcoded until we move to GLES 3.0 or greater.
218 case COMPRESSED_RGBA8_ETC2_EAC:
220 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_RGBA8_ETC2_EAC.\n" );
221 internalFormat = 0x9278; ///! < Hardcoded until we move to GLES 3.0 or greater.
224 case COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
226 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ETC2_EAC.\n" );
227 internalFormat = 0x9279; ///! < Hardcoded until we move to GLES 3.0 or greater.
231 // GLES 2 extension compressed formats:
232 case COMPRESSED_RGB8_ETC1:
234 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using non-standard GLES 2.0 extension compressed pixel format COMPRESSED_RGB8_ETC1.\n" );
235 internalFormat = 0x8D64; ///! < Hardcoded so we can test before we move to GLES 3.0 or greater.
238 case COMPRESSED_RGB_PVRTC_4BPPV1:
240 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using non-standard GLES 2.0 extension compressed pixel format COMPRESSED_RGB_PVRTC_4BPPV1.\n" );
241 internalFormat = 0x8C00; ///! < Hardcoded so we can test before we move to GLES 3.0 or greater.
247 Bitmap* Bitmap::New( const Profile profile = BITMAP_2D_PACKED_PIXELS,
248 ResourcePolicy::Discardable discardable = ResourcePolicy::DISCARD )
250 DALI_ASSERT_DEBUG(profile == BITMAP_2D_PACKED_PIXELS || profile == BITMAP_COMPRESSED);
254 /** A 2D array of pixels where each pixel is a whole number of bytes
255 * and each scanline of the backing memory buffer may have additional
256 * bytes off the right edge if requested, and there may be additional
257 * scanlines past the bottom of the image in the buffer if requested.*/
258 case BITMAP_2D_PACKED_PIXELS:
260 Bitmap * const bitmap = new Dali::Internal::BitmapPackedPixel( discardable );
264 /** The data for the bitmap is buffered in an opaque form.*/
265 case BITMAP_COMPRESSED:
267 return new Dali::Internal::BitmapCompressed( discardable );
274 Bitmap::Bitmap( ResourcePolicy::Discardable discardable, Dali::Integration::PixelBuffer* pixBuf)
277 mPixelFormat(Pixel::RGBA8888),
278 mHasAlphaChannel(true),
279 mAlphaChannelUsed(true),
281 mDiscardable(discardable)
285 void Bitmap::DiscardBuffer()
287 if( mDiscardable == ResourcePolicy::DISCARD )
293 PixelBuffer* Bitmap::ReleaseBuffer()
295 PixelBuffer* const data = mData;
297 // Ownership of mData has been transferred, so indicate that mData pointer is no longer valid:
305 DALI_LOG_TRACE_METHOD(Debug::Filter::gImage);
306 if( mDiscardable == ResourcePolicy::DISCARD )
314 void Bitmap::DeletePixelBuffer()
325 void Bitmap::Initialize( Pixel::Format pixelFormat,
329 DALI_ASSERT_DEBUG(width * height < (32 * 1024) * (32 * 1024) && "The total area of the bitmap is too great.\n");
331 mImageHeight = height;
332 mPixelFormat = pixelFormat;
334 mHasAlphaChannel = Pixel::HasAlpha(pixelFormat);
337 } //namespace Integration