License conversion from Flora to Apache 2.0
[platform/core/uifw/dali-core.git] / dali / internal / render / gl-resources / compressed-bitmap-texture.h
1 #ifndef __DALI_INTERNAL_COMPRESSED_BITMAP_TEXTURE_H__
2 #define __DALI_INTERNAL_COMPRESSED_BITMAP_TEXTURE_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <string>
23 #include <stdint.h>
24
25 // INTERNAL INCLUDES
26 #include <dali/public-api/images/bitmap-image.h>
27 #include <dali/internal/common/message.h>
28 #include <dali/internal/render/gl-resources/texture.h>
29 #include <dali/internal/common/bitmap-upload.h>
30 #include <dali/integration-api/bitmap.h>
31 #include <dali/internal/event/images/bitmap-compressed.h>
32 #include <dali/integration-api/debug.h>
33
34 namespace Dali
35 {
36
37 namespace Internal
38 {
39
40 class CompressedBitmapTexture;
41 typedef IntrusivePtr<CompressedBitmapTexture> CompressedBitmapTexturePointer;
42
43 /**
44  * Compressed Texture class.
45  * If you want to load a file to a CompressedBitmapTexture use
46  * TextureManager::GetTexture()
47  * Compressed textures differ from ordinary ones in that their in-memory
48  * representation cannot be inspected at a pixel level by simple pointer
49  * arithmetic and in that they cannot be partially updated.
50  */
51 class CompressedBitmapTexture : public Texture
52 {
53 public:
54   /**
55    * Constructor
56    * Creates a new texture object from a Bitmap
57    * @param[in] bitmap The Bitmap
58    * @param     context The GL context
59    */
60   CompressedBitmapTexture( Internal::BitmapCompressed* const bitmap, Context& context );
61
62   /**
63    * Destructor.
64    */
65   virtual ~CompressedBitmapTexture();
66
67 public:
68   /**
69    * @copydoc Texture::Init
70    */
71   virtual bool Init();
72
73   /**
74    * @copydoc Texture::GetWidth
75    */
76   virtual unsigned int GetWidth() const;
77
78   /**
79    * @copydoc Texture::GetHeight
80    */
81   virtual unsigned int GetHeight() const;
82
83   /**
84    * @copydoc Texture::HasAlphaChannel
85    */
86   virtual bool HasAlphaChannel() const;
87
88   /**
89    * @copydoc Texture::IsFullyOpaque
90    * Always returns false as we can't know what is going on inside the encoded pixel data. ///!Todo: Revise this decision: Paul, didn't you want the opposite assumption?
91    */
92   virtual bool IsFullyOpaque() const;
93
94   /**
95    * Bitmap has been reloaded - update the texture appropriately.
96    * @param[in] bitmap The new bitmap
97    */
98   virtual void Update( Integration::Bitmap* bitmap );
99
100   /**
101    * @return Return true if the texture should be updated on GL texture creation.
102    */
103   virtual bool UpdateOnCreate();
104
105 protected:
106   /**
107    * @copydoc Texture::CreateGlTexture
108    */
109   virtual bool CreateGlTexture();
110
111 private:
112
113   /**
114    * Assigns the bitmap data to an OpenGL texture
115    * Creates a new texture object and copies
116    * the image data held in the pixels parameter
117    * @param[in] generateTexture True if we should generate a GL texture id
118    * @param[in] pixels The pixel data
119    */
120   void AssignBitmap( bool generateTexture, const unsigned char* pixels, const size_t bufferSize );
121
122 private:
123   Internal::BitmapCompressedPtr mBitmap;      ///< The Bitmap the Texture was created from (may be NULL)
124
125   // Changes scope, should be at end of class
126   DALI_LOG_OBJECT_STRING_DECLARATION;
127 };
128 } //namespace Internal
129 } //namespace Dali
130
131 #endif //__DALI_INTERNAL_COMPRESSED_BITMAP_TEXTURE_H__