Updates to handle context loss and regain
[platform/core/uifw/dali-core.git] / dali / internal / event / images / bitmap-compressed.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 // CLASS HEADER
19 #include <dali/internal/event/images/bitmap-compressed.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/common/core-impl.h>
23 #include <dali/integration-api/debug.h>
24
25 // INTERNAL INCLUDES
26 #include <dali/internal/common/core-impl.h>
27 #include <dali/integration-api/debug.h>
28
29 namespace Dali
30 {
31
32 namespace Internal
33 {
34 using namespace Dali::Pixel;
35
36 BitmapCompressed::BitmapCompressed( const ResourcePolicy::Discardable discardable )
37 : Bitmap( discardable ),
38   mBufferSize(0)
39 {
40 }
41
42 BitmapCompressed::~BitmapCompressed()
43 {
44   DALI_LOG_TRACE_METHOD(Debug::Filter::gImage);
45 }
46
47 void BitmapCompressed::Initialize( Pixel::Format pixelFormat,
48                           const unsigned int width,
49                           const unsigned int height,
50                           const size_t bufferSize )
51 {
52   Dali::Integration::Bitmap::Initialize( pixelFormat, width, height );
53   mBufferSize  = bufferSize;
54   mAlphaChannelUsed = false; // Default to not using Alpha as we cannot scan the pixels to look for transparent pixels. A follow-up work-item and patch will add an "assume alpha present" flag to ImageAttributes.
55 }
56
57 Dali::Integration::PixelBuffer* BitmapCompressed::ReserveBufferOfSize( Pixel::Format pixelFormat,
58                                     const unsigned int  width,
59                                     const unsigned int  height,
60                                     const size_t        bufferSize )
61 {
62   // Sanity check that a not-outrageous amount of data is being passed in (indicating a client error):
63   DALI_ASSERT_DEBUG(bufferSize < (1U << 27U) && "That is far too much compressed data."); // 128MB of compressed data == unreasonable.
64   // delete existing buffer
65   DeletePixelBuffer();
66
67   Initialize(pixelFormat, width, height, bufferSize);
68
69   mData = new Dali::Integration::PixelBuffer[bufferSize];
70
71   return mData;
72 }
73
74 } //namespace Integration
75
76 } //namespace Dali