[dali_1.0.16] Merge branch 'tizen'
[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/render/gl-resources/texture-cache.h>
30 #include <dali/internal/common/bitmap-upload.h>
31 #include <dali/integration-api/bitmap.h>
32 #include <dali/internal/event/images/bitmap-compressed.h>
33 #include <dali/integration-api/debug.h>
34
35 namespace Dali
36 {
37
38 namespace Internal
39 {
40
41 class CompressedBitmapTexture;
42 typedef IntrusivePtr<CompressedBitmapTexture> CompressedBitmapTexturePointer;
43
44 /**
45  * Compressed Texture class.
46  * If you want to load a file to a CompressedBitmapTexture use
47  * TextureManager::GetTexture()
48  * Compressed textures differ from ordinary ones in that their in-memory
49  * representation cannot be inspected at a pixel level by simple pointer
50  * arithmetic and in that they cannot be partially updated.
51  */
52 class CompressedBitmapTexture : public Texture
53 {
54 public:
55   /**
56    * Constructor
57    * Creates a new texture object from a Bitmap
58    * @param[in] bitmap The Bitmap
59    * @param[in] context The GL context
60    * @param[in] discardPolicy The discard policy
61    */
62   CompressedBitmapTexture( Internal::BitmapCompressed* const bitmap, Context& context, ResourcePolicy::Discardable discardPolicy );
63
64   /**
65    * Destructor.
66    */
67   virtual ~CompressedBitmapTexture();
68
69 public:
70   /**
71    * @copydoc Texture::Init
72    */
73   virtual bool Init();
74
75   /**
76    * @copydoc Texture::GetWidth
77    */
78   virtual unsigned int GetWidth() const;
79
80   /**
81    * @copydoc Texture::GetHeight
82    */
83   virtual unsigned int GetHeight() const;
84
85   /**
86    * @copydoc Texture::HasAlphaChannel
87    */
88   virtual bool HasAlphaChannel() const;
89
90   /**
91    * @copydoc Texture::IsFullyOpaque
92    * 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?
93    */
94   virtual bool IsFullyOpaque() const;
95
96   /**
97    * Bitmap has been reloaded - update the texture appropriately.
98    * @param[in] bitmap The new bitmap
99    */
100   virtual void Update( Integration::Bitmap* bitmap );
101
102   /**
103    * @return Return true if the texture should be updated on GL texture creation.
104    */
105   virtual bool UpdateOnCreate();
106
107 protected:
108   /**
109    * @copydoc Texture::CreateGlTexture
110    */
111   virtual bool CreateGlTexture();
112
113 private:
114
115   /**
116    * Assigns the bitmap data to an OpenGL texture
117    * Creates a new texture object and copies
118    * the image data held in the pixels parameter
119    * @param[in] generateTexture True if we should generate a GL texture id
120    * @param[in] pixels The pixel data
121    */
122   void AssignBitmap( bool generateTexture, const unsigned char* pixels, const size_t bufferSize );
123
124 private:
125   Internal::BitmapCompressedPtr mBitmap;      ///< The Bitmap the Texture was created from (may be NULL)
126   ResourcePolicy::Discardable mDiscardPolicy;
127
128   // Changes scope, should be at end of class
129   DALI_LOG_OBJECT_STRING_DECLARATION;
130 };
131 } //namespace Internal
132 } //namespace Dali
133
134 #endif //__DALI_INTERNAL_COMPRESSED_BITMAP_TEXTURE_H__