2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "pixmap-image-impl.h"
22 #include <dali/integration-api/debug.h>
25 #include <gl/egl-image-extensions.h>
26 #include <gl/egl-factory.h>
27 #include <adaptor-impl.h>
28 #include <render-surface.h>
30 // Allow this to be encoded and saved:
31 #include <platform-abstractions/tizen/resource-loader/resource-loader.h>
32 #include <bitmap-saver.h>
42 using Dali::Integration::PixelBuffer;
44 PixmapImage* PixmapImage::New(unsigned int width, unsigned int height, Dali::PixmapImage::ColorDepth depth, Any pixmap )
46 PixmapImage* image = new PixmapImage( width, height, depth, pixmap );
47 DALI_ASSERT_DEBUG( image && "PixmapImage allocation failed." );
49 // 2nd phase construction
50 if(image) //< Defensive in case we ever compile without exceptions.
58 PixmapImage::PixmapImage( unsigned int width, unsigned int height, Dali::PixmapImage::ColorDepth depth, Any pixmap )
64 mEglImageExtensions( NULL )
66 DALI_ASSERT_ALWAYS( Adaptor::IsAvailable() );
67 EglFactory& eglFactory = Adaptor::GetImplementation( Adaptor::Get() ).GetEGLFactory();
68 mEglImageExtensions = eglFactory.GetImageExtensions();
69 SetBlending( mColorDepth );
71 DALI_ASSERT_DEBUG( mEglImageExtensions );
74 void PixmapImage::Initialize()
78 PixmapImage::~PixmapImage()
82 Any PixmapImage::GetPixmap() const
84 DALI_ASSERT_ALWAYS( false && "PixmapImage::GetPixmap() is not supported for Wayland." );
88 bool PixmapImage::GetPixels(std::vector<unsigned char>& pixbuf, unsigned& width, unsigned& height, Pixel::Format& pixelFormat) const
93 bool PixmapImage::EncodeToFile(const std::string& filename) const
95 std::vector< unsigned char > pixbuf;
96 unsigned int width(0), height(0);
97 Pixel::Format pixelFormat;
99 if(GetPixels(pixbuf, width, height, pixelFormat))
101 return Dali::EncodeToFile(&pixbuf[0], filename, pixelFormat, width, height);
106 bool PixmapImage::GlExtensionCreate()
111 void PixmapImage::GlExtensionDestroy()
113 mEglImageExtensions->DestroyImageKHR(mEglImageKHR);
118 unsigned int PixmapImage::TargetTexture()
120 mEglImageExtensions->TargetTextureKHR(mEglImageKHR);
125 void PixmapImage::SetBlending(Dali::PixmapImage::ColorDepth depth)
129 case Dali::PixmapImage::COLOR_DEPTH_16: //Pixel::RGB565
130 case Dali::PixmapImage::COLOR_DEPTH_24: // Pixel::RGB888
132 mBlendingRequired = false;
135 case Dali::PixmapImage::COLOR_DEPTH_8: //Pixel::A8
136 case Dali::PixmapImage::COLOR_DEPTH_32: // Pixel::RGBA8888
138 mBlendingRequired = true;
143 DALI_ASSERT_DEBUG(0 && "unknown color enum");
148 void PixmapImage::GetPixmapDetails()
152 } // namespace Adaptor
154 } // namespace internal