Merge remote-tracking branch 'origin/tizen' into new_text
[platform/core/uifw/dali-adaptor.git] / adaptors / wayland / pixmap-image-impl-wl.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 "pixmap-image-impl.h"
20
21 // EXTERNAL INCLUDES
22 #include <dali/integration-api/debug.h>
23
24 // INTERNAL INCLUDES
25 #include <gl/egl-image-extensions.h>
26 #include <gl/egl-factory.h>
27 #include <adaptor-impl.h>
28 #include <render-surface.h>
29
30 // Allow this to be encoded and saved:
31 #include <platform-abstractions/tizen/resource-loader/resource-loader.h>
32 #include <bitmap-saver.h>
33
34 namespace Dali
35 {
36
37 namespace Internal
38 {
39
40 namespace Adaptor
41 {
42 using Dali::Integration::PixelBuffer;
43
44 PixmapImage* PixmapImage::New(unsigned int width, unsigned int height, Dali::PixmapImage::ColorDepth depth, Any pixmap )
45 {
46   PixmapImage* image = new PixmapImage( width, height, depth, pixmap );
47   DALI_ASSERT_DEBUG( image && "PixmapImage allocation failed." );
48
49   // 2nd phase construction
50   if(image) //< Defensive in case we ever compile without exceptions.
51   {
52     image->Initialize();
53   }
54
55   return image;
56 }
57
58 PixmapImage::PixmapImage( unsigned int width, unsigned int height, Dali::PixmapImage::ColorDepth depth, Any pixmap )
59 : mWidth( width ),
60   mHeight( height ),
61   mOwnPixmap( true ),
62   mColorDepth( depth ),
63   mEglImageKHR( NULL ),
64   mEglImageExtensions( NULL )
65 {
66   DALI_ASSERT_ALWAYS( Adaptor::IsAvailable() );
67   EglFactory& eglFactory = Adaptor::GetImplementation( Adaptor::Get() ).GetEGLFactory();
68   mEglImageExtensions = eglFactory.GetImageExtensions();
69   SetBlending( mColorDepth );
70
71   DALI_ASSERT_DEBUG( mEglImageExtensions );
72 }
73
74 void PixmapImage::Initialize()
75 {
76 }
77
78 PixmapImage::~PixmapImage()
79 {
80 }
81
82 Any PixmapImage::GetPixmap() const
83 {
84   DALI_ASSERT_ALWAYS( false && "PixmapImage::GetPixmap() is not supported for Wayland." );
85   return Any();
86 }
87
88 bool PixmapImage::GetPixels(std::vector<unsigned char>& pixbuf, unsigned& width, unsigned& height, Pixel::Format& pixelFormat) const
89 {
90     return false;
91 }
92
93 bool PixmapImage::EncodeToFile(const std::string& filename) const
94 {
95   std::vector< unsigned char > pixbuf;
96   unsigned int width(0), height(0);
97   Pixel::Format pixelFormat;
98
99   if(GetPixels(pixbuf, width, height, pixelFormat))
100   {
101     return Dali::EncodeToFile(&pixbuf[0], filename, pixelFormat, width, height);
102   }
103   return false;
104 }
105
106 bool PixmapImage::GlExtensionCreate()
107 {
108     return false;
109 }
110
111 void PixmapImage::GlExtensionDestroy()
112 {
113   mEglImageExtensions->DestroyImageKHR(mEglImageKHR);
114
115   mEglImageKHR = NULL;
116 }
117
118 unsigned int PixmapImage::TargetTexture()
119 {
120   mEglImageExtensions->TargetTextureKHR(mEglImageKHR);
121
122   return 0;
123 }
124
125 void PixmapImage::SetBlending(Dali::PixmapImage::ColorDepth depth)
126 {
127   switch (depth)
128   {
129     case Dali::PixmapImage::COLOR_DEPTH_16: //Pixel::RGB565
130     case Dali::PixmapImage::COLOR_DEPTH_24: // Pixel::RGB888
131     {
132       mBlendingRequired = false;
133       break;
134     }
135     case Dali::PixmapImage::COLOR_DEPTH_8: //Pixel::A8
136     case Dali::PixmapImage::COLOR_DEPTH_32: // Pixel::RGBA8888
137     {
138       mBlendingRequired = true;
139       break;
140     }
141     default:
142     {
143       DALI_ASSERT_DEBUG(0 && "unknown color enum");
144     }
145   }
146 }
147
148 void PixmapImage::GetPixmapDetails()
149 {
150 }
151
152 } // namespace Adaptor
153
154 } // namespace internal
155
156 } // namespace Dali