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>
22 #include <dali/integration-api/debug.h>
23 #include <dali/integration-api/platform-abstraction.h>
24 #include <dali/internal/event/common/thread-local-storage.h>
25 #include <dali/internal/event/images/bitmap-packed-pixel.h>
26 #include <dali/internal/event/images/bitmap-compressed.h>
27 #include <dali/internal/event/images/bitmap-external.h>
28 #include <dali/integration-api/gl-abstraction.h>
29 #include <dali/integration-api/gl-defines.h>
36 using namespace Dali::Pixel;
38 void ConvertToGlFormat( Format pixelformat, unsigned& pixelDataType, unsigned& internalFormat )
40 // Compressed textures have no pixelDataType, so init to an invalid value:
47 pixelDataType = GL_UNSIGNED_BYTE;
48 internalFormat= GL_ALPHA;
54 pixelDataType = GL_UNSIGNED_BYTE;
55 internalFormat= GL_LUMINANCE;
61 pixelDataType = GL_UNSIGNED_BYTE;
62 internalFormat= GL_LUMINANCE_ALPHA;
68 pixelDataType = GL_UNSIGNED_SHORT_5_6_5;
69 internalFormat= GL_RGB;
75 DALI_LOG_ERROR("Pixel format BGR565 is not supported by GLES.\n");
76 pixelDataType = GL_UNSIGNED_SHORT_5_6_5;
78 internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
80 internalFormat= GL_RGBA; // alpha is reserved but not used
87 pixelDataType = GL_UNSIGNED_SHORT_4_4_4_4;
88 internalFormat= GL_RGBA;
94 DALI_LOG_ERROR("Pixel format BGRA4444 is not supported by GLES.\n");
95 pixelDataType = GL_UNSIGNED_SHORT_4_4_4_4;
97 internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
99 internalFormat= GL_RGBA; // alpha is reserved but not used
106 pixelDataType = GL_UNSIGNED_SHORT_5_5_5_1;
107 internalFormat= GL_RGBA;
113 DALI_LOG_ERROR("Pixel format BGRA5551 is not supported by GLES.\n");
114 pixelDataType = GL_UNSIGNED_SHORT_5_5_5_1;
116 internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
118 internalFormat= GL_RGBA; // alpha is reserved but not used
125 pixelDataType = GL_UNSIGNED_BYTE;
126 internalFormat= GL_RGB;
132 pixelDataType = GL_UNSIGNED_BYTE;
133 internalFormat= GL_RGBA; // alpha is reserved but not used
139 pixelDataType = GL_UNSIGNED_BYTE;
141 internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
143 internalFormat= GL_RGBA; // alpha is reserved but not used
150 pixelDataType = GL_UNSIGNED_BYTE;
151 internalFormat= GL_RGBA;
157 pixelDataType = GL_UNSIGNED_BYTE;
159 internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
161 internalFormat= GL_RGBA; // alpha is reserved but not used
166 // GLES 3.0 standard compressed formats:
167 case COMPRESSED_R11_EAC:
169 DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_R11_EAC.\n");
170 internalFormat = 0x9270; ///! < Hardcoded until we move to GLES 3.0 or greater.
173 case COMPRESSED_SIGNED_R11_EAC:
175 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SIGNED_R11_EAC.\n" );
176 internalFormat = 0x9271; ///! < Hardcoded until we move to GLES 3.0 or greater.
180 case COMPRESSED_RG11_EAC:
182 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_RG11_EAC.\n" );
183 internalFormat = 0x9272; ///! < Hardcoded until we move to GLES 3.0 or greater.
186 case COMPRESSED_SIGNED_RG11_EAC:
188 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SIGNED_RG11_EAC.\n" );
189 internalFormat = 0x9273; ///! < Hardcoded until we move to GLES 3.0 or greater.
192 case COMPRESSED_RGB8_ETC2:
194 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_RGB8_ETC2.\n" );
195 internalFormat = 0x9274; ///! < Hardcoded until we move to GLES 3.0 or greater.
198 case COMPRESSED_SRGB8_ETC2:
200 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SRGB8_ETC2.\n" );
201 internalFormat = 0x9275; ///! < Hardcoded until we move to GLES 3.0 or greater.
204 case COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
206 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2.\n" );
207 internalFormat = 0x9276; ///! < Hardcoded until we move to GLES 3.0 or greater.
210 case COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
212 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2.\n" );
213 internalFormat = 0x9277; ///! < Hardcoded until we move to GLES 3.0 or greater.
216 case COMPRESSED_RGBA8_ETC2_EAC:
218 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_RGBA8_ETC2_EAC.\n" );
219 internalFormat = 0x9278; ///! < Hardcoded until we move to GLES 3.0 or greater.
222 case COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
224 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ETC2_EAC.\n" );
225 internalFormat = 0x9279; ///! < Hardcoded until we move to GLES 3.0 or greater.
229 // GLES 2 extension compressed formats:
230 case COMPRESSED_RGB8_ETC1:
232 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using non-standard GLES 2.0 extension compressed pixel format COMPRESSED_RGB8_ETC1.\n" );
233 internalFormat = 0x8D64; ///! < Hardcoded so we can test before we move to GLES 3.0 or greater.
236 case COMPRESSED_RGB_PVRTC_4BPPV1:
238 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using non-standard GLES 2.0 extension compressed pixel format COMPRESSED_RGB_PVRTC_4BPPV1.\n" );
239 internalFormat = 0x8C00; ///! < Hardcoded so we can test before we move to GLES 3.0 or greater.
245 Bitmap* Bitmap::New( const Profile profile = BITMAP_2D_PACKED_PIXELS,
246 ResourcePolicy::Discardable discardable = ResourcePolicy::OWNED_DISCARD )
248 DALI_ASSERT_DEBUG(profile == BITMAP_2D_PACKED_PIXELS || profile == BITMAP_COMPRESSED);
252 /** A 2D array of pixels where each pixel is a whole number of bytes
253 * and each scanline of the backing memory buffer may have additional
254 * bytes off the right edge if requested, and there may be additional
255 * scanlines past the bottom of the image in the buffer if requested.*/
256 case BITMAP_2D_PACKED_PIXELS:
258 Bitmap * const bitmap = new Dali::Internal::BitmapPackedPixel( discardable );
262 /** The data for the bitmap is buffered in an opaque form.*/
263 case BITMAP_COMPRESSED:
265 return new Dali::Internal::BitmapCompressed( discardable );
272 Bitmap::Bitmap( ResourcePolicy::Discardable discardable, Dali::Integration::PixelBuffer* pixBuf)
275 mPixelFormat(Pixel::RGBA8888),
276 mHasAlphaChannel(true),
277 mAlphaChannelUsed(true),
279 mDiscardable(discardable)
283 void Bitmap::DiscardBuffer()
285 if( mDiscardable == ResourcePolicy::OWNED_DISCARD )
293 DALI_LOG_TRACE_METHOD(Debug::Filter::gImage);
296 if( mDiscardable == ResourcePolicy::OWNED_DISCARD ||
297 mDiscardable == ResourcePolicy::OWNED_RETAIN )
305 void Bitmap::DeletePixelBuffer()
316 void Bitmap::Initialize( Pixel::Format pixelFormat,
320 DALI_ASSERT_DEBUG(width * height < (32 * 1024) * (32 * 1024) && "The total area of the bitmap is too great.\n");
322 mImageHeight = height;
323 mPixelFormat = pixelFormat;
325 mHasAlphaChannel = Pixel::HasAlpha(pixelFormat);
328 } //namespace Integration