Merge remote-tracking branch 'origin/tizen' into new_text
[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/buffer-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/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[in] context The GL context
59    * @param[in] discardPolicy The discard policy
60    */
61   CompressedBitmapTexture( Internal::BitmapCompressed* const bitmap, Context& context, ResourcePolicy::Discardable discardPolicy );
62
63   /**
64    * Destructor.
65    */
66   virtual ~CompressedBitmapTexture();
67
68 public:
69   /**
70    * @copydoc Texture::Init
71    */
72   virtual bool Init();
73
74   /**
75    * @copydoc Texture::GetWidth
76    */
77   virtual unsigned int GetWidth() const;
78
79   /**
80    * @copydoc Texture::GetHeight
81    */
82   virtual unsigned int GetHeight() const;
83
84   /**
85    * @copydoc Texture::HasAlphaChannel
86    */
87   virtual bool HasAlphaChannel() const;
88
89   /**
90    * @copydoc Texture::IsFullyOpaque
91    * 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?
92    */
93   virtual bool IsFullyOpaque() const;
94
95   /**
96    * Bitmap has been reloaded - update the texture appropriately.
97    * @param[in] bitmap The new bitmap
98    */
99   virtual void Update( Integration::Bitmap* bitmap );
100
101   /**
102    * @return Return true if the texture should be updated on GL texture creation.
103    */
104   virtual bool UpdateOnCreate();
105
106 protected:
107   /**
108    * @copydoc Texture::CreateGlTexture
109    */
110   virtual bool CreateGlTexture();
111
112 private:
113
114   /**
115    * Assigns the bitmap data to an OpenGL texture
116    * Creates a new texture object and copies
117    * the image data held in the pixels parameter
118    * @param[in] generateTexture True if we should generate a GL texture id
119    * @param[in] pixels The pixel data
120    */
121   void AssignBitmap( bool generateTexture, const unsigned char* pixels, const size_t bufferSize );
122
123 private:
124   Internal::BitmapCompressedPtr mBitmap;      ///< The Bitmap the Texture was created from (may be NULL)
125   ResourcePolicy::Discardable mDiscardPolicy;
126   Pixel::Format  mPixelFormat;
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__