2 * Copyright (c) 2015 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/integration-api/gl-abstraction.h>
28 #include <dali/integration-api/gl-defines.h>
35 using namespace Dali::Pixel;
37 void ConvertToGlFormat( Format pixelformat, unsigned& pixelDataType, unsigned& internalFormat )
39 // Compressed textures have no pixelDataType, so init to an invalid value:
46 pixelDataType = GL_UNSIGNED_BYTE;
47 internalFormat= GL_ALPHA;
53 pixelDataType = GL_UNSIGNED_BYTE;
54 internalFormat= GL_LUMINANCE;
60 pixelDataType = GL_UNSIGNED_BYTE;
61 internalFormat= GL_LUMINANCE_ALPHA;
67 pixelDataType = GL_UNSIGNED_SHORT_5_6_5;
68 internalFormat= GL_RGB;
74 DALI_LOG_ERROR("Pixel format BGR565 is not supported by GLES.\n");
75 pixelDataType = GL_UNSIGNED_SHORT_5_6_5;
77 internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
79 internalFormat= GL_RGBA; // alpha is reserved but not used
86 pixelDataType = GL_UNSIGNED_SHORT_4_4_4_4;
87 internalFormat= GL_RGBA;
93 DALI_LOG_ERROR("Pixel format BGRA4444 is not supported by GLES.\n");
94 pixelDataType = GL_UNSIGNED_SHORT_4_4_4_4;
96 internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
98 internalFormat= GL_RGBA; // alpha is reserved but not used
105 pixelDataType = GL_UNSIGNED_SHORT_5_5_5_1;
106 internalFormat= GL_RGBA;
112 DALI_LOG_ERROR("Pixel format BGRA5551 is not supported by GLES.\n");
113 pixelDataType = GL_UNSIGNED_SHORT_5_5_5_1;
115 internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
117 internalFormat= GL_RGBA; // alpha is reserved but not used
124 pixelDataType = GL_UNSIGNED_BYTE;
125 internalFormat= GL_RGB;
131 pixelDataType = GL_UNSIGNED_BYTE;
132 internalFormat= GL_RGBA; // alpha is reserved but not used
138 pixelDataType = GL_UNSIGNED_BYTE;
140 internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
142 internalFormat= GL_RGBA; // alpha is reserved but not used
149 pixelDataType = GL_UNSIGNED_BYTE;
150 internalFormat= GL_RGBA;
156 pixelDataType = GL_UNSIGNED_BYTE;
158 internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
160 internalFormat= GL_RGBA; // alpha is reserved but not used
165 // GLES 3.0 standard compressed formats:
166 case COMPRESSED_R11_EAC:
168 DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_R11_EAC.\n");
169 internalFormat = 0x9270; ///! < Hardcoded until we move to GLES 3.0 or greater.
172 case COMPRESSED_SIGNED_R11_EAC:
174 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SIGNED_R11_EAC.\n" );
175 internalFormat = 0x9271; ///! < Hardcoded until we move to GLES 3.0 or greater.
179 case COMPRESSED_RG11_EAC:
181 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_RG11_EAC.\n" );
182 internalFormat = 0x9272; ///! < Hardcoded until we move to GLES 3.0 or greater.
185 case COMPRESSED_SIGNED_RG11_EAC:
187 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SIGNED_RG11_EAC.\n" );
188 internalFormat = 0x9273; ///! < Hardcoded until we move to GLES 3.0 or greater.
191 case COMPRESSED_RGB8_ETC2:
193 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_RGB8_ETC2.\n" );
194 internalFormat = 0x9274; ///! < Hardcoded until we move to GLES 3.0 or greater.
197 case COMPRESSED_SRGB8_ETC2:
199 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SRGB8_ETC2.\n" );
200 internalFormat = 0x9275; ///! < Hardcoded until we move to GLES 3.0 or greater.
203 case COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
205 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2.\n" );
206 internalFormat = 0x9276; ///! < Hardcoded until we move to GLES 3.0 or greater.
209 case COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
211 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2.\n" );
212 internalFormat = 0x9277; ///! < Hardcoded until we move to GLES 3.0 or greater.
215 case COMPRESSED_RGBA8_ETC2_EAC:
217 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_RGBA8_ETC2_EAC.\n" );
218 internalFormat = 0x9278; ///! < Hardcoded until we move to GLES 3.0 or greater.
221 case COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
223 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ETC2_EAC.\n" );
224 internalFormat = 0x9279; ///! < Hardcoded until we move to GLES 3.0 or greater.
228 // GLES 2 extension compressed formats:
229 case COMPRESSED_RGB8_ETC1:
231 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using non-standard GLES 2.0 extension compressed pixel format COMPRESSED_RGB8_ETC1.\n" );
232 internalFormat = 0x8D64; ///! < Hardcoded so we can test before we move to GLES 3.0 or greater.
235 case COMPRESSED_RGB_PVRTC_4BPPV1:
237 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using non-standard GLES 2.0 extension compressed pixel format COMPRESSED_RGB_PVRTC_4BPPV1.\n" );
238 internalFormat = 0x8C00; ///! < Hardcoded so we can test before we move to GLES 3.0 or greater.
244 Bitmap* Bitmap::New( const Profile profile = BITMAP_2D_PACKED_PIXELS,
245 ResourcePolicy::Discardable discardable = ResourcePolicy::OWNED_DISCARD )
247 DALI_ASSERT_DEBUG(profile == BITMAP_2D_PACKED_PIXELS || profile == BITMAP_COMPRESSED);
251 /** A 2D array of pixels where each pixel is a whole number of bytes
252 * and each scanline of the backing memory buffer may have additional
253 * bytes off the right edge if requested, and there may be additional
254 * scanlines past the bottom of the image in the buffer if requested.*/
255 case BITMAP_2D_PACKED_PIXELS:
257 Bitmap * const bitmap = new Dali::Internal::BitmapPackedPixel( discardable );
261 /** The data for the bitmap is buffered in an opaque form.*/
262 case BITMAP_COMPRESSED:
264 return new Dali::Internal::BitmapCompressed( discardable );
271 Bitmap::Bitmap( ResourcePolicy::Discardable discardable, Dali::Integration::PixelBuffer* pixBuf)
274 mPixelFormat(Pixel::RGBA8888),
275 mHasAlphaChannel(true),
276 mAlphaChannelUsed(true),
278 mDiscardable(discardable)
282 PixelBuffer* Bitmap::GetBufferOwnership()
284 PixelBuffer* buffer = mData;
289 void Bitmap::DiscardBuffer()
291 if( mDiscardable == ResourcePolicy::OWNED_DISCARD )
299 DALI_LOG_TRACE_METHOD(Debug::Filter::gImage);
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