2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FGrp_CanvasShow.cpp
20 * @brief This is the implementation file for internal Canvas class.
26 #include <Ecore_Evas.h>
31 #include <X11/Xutil.h>
32 #include <X11/extensions/XShm.h>
33 #include <X11/Xatom.h>
35 #include <sys/types.h>
38 #include "FGrp_Callback.h"
40 #include <FBaseSysLog.h>
43 namespace Tizen { namespace Graphics
49 Ecore_Evas* pEcoreEvas = static_cast<Ecore_Evas*>(_GetDefaultFrameEcoreEvasHandle());
53 ecore_evas_manual_render(pEcoreEvas);
58 _CanvasShowFromMemory(int xDest, int yDest, int xSour, int ySour, int wSour, int hSour, void* pMemory, int width, int height,
62 // check input parameter
72 // pBuffer should be NULL pointer
73 if (pMemory == null || width <= 0 || height <= 0)
79 Ecore_Evas* pEcoreEvas = static_cast<Ecore_Evas*>(_GetDefaultFrameEcoreEvasHandle());
81 if (pEcoreEvas == null)
89 Display* pHdisplay = XOpenDisplay(NULL);
90 int displayWidth = DisplayWidth(pHdisplay, DefaultScreen(pHdisplay));
91 int displayHeight = DisplayHeight(pHdisplay, DefaultScreen(pHdisplay));
93 //Window root = RootWindow(pHdisplay, DefaultScreen(pHdisplay));
94 Window root = (Window) ecore_evas_window_get(pEcoreEvas);
96 XShmSegmentInfo shmInfo;
97 XImage* pXimage = XShmCreateImage(pHdisplay, DefaultVisualOfScreen(DefaultScreenOfDisplay(pHdisplay)), 24, ZPixmap,
98 NULL, &shmInfo, (unsigned int) displayWidth, (unsigned int) displayHeight);
104 // EAPI void ecore_evas_comp_sync_set(Ecore_Evas *ee, Eina_Bool do_sync);
105 ecore_evas_comp_sync_set(pEcoreEvas, EINA_FALSE);
107 shmInfo.shmid = shmget(IPC_PRIVATE, pXimage->bytes_per_line * pXimage->height, IPC_CREAT | 0777);
109 pXimage->data = (char*) shmat(shmInfo.shmid, 0, 0);
110 shmInfo.shmaddr = pXimage->data;
111 shmInfo.readOnly = False;
113 // copy to image buffer
115 typedef unsigned long Pixel;
117 Pixel* pSrc = reinterpret_cast <Pixel*>(pMemory);
118 Pixel* pDst = reinterpret_cast <Pixel*>(pXimage->data);
119 int srcPitch = (bytesPerLine * 8 / depth);
120 int dstPitch = (pXimage->bytes_per_line * 8 / depth);
122 for (int y = 0; y < height; y++)
124 memcpy(pDst, pSrc, width * sizeof(Pixel));
130 if (!XShmAttach(pHdisplay, &shmInfo))
135 XShmPutImage(pHdisplay, root, DefaultGCOfScreen(DefaultScreenOfDisplay(pHdisplay)),
137 xSrc, ySrc, xDest, yDest, width, height, false);
139 XSync(pHdisplay, False);
141 ecore_evas_comp_sync_set(pEcoreEvas, EINA_TRUE);
143 // release the captured buffer
145 XShmDetach(pHdisplay, &shmInfo);
146 shmdt(shmInfo.shmaddr);
147 shmctl(shmInfo.shmid, IPC_RMID, NULL);
149 XDestroyImage(pXimage);
152 XCloseDisplay(pHdisplay);
157 Evas* pEvas = static_cast<Evas*>(_GetDefaultFrameEvasHandle());
161 evas_object_image_pixels_dirty_set((Evas_Object*) pEvas, true);
162 evas_object_show((Evas_Object*) pEvas);
171 XShmDetach(pHdisplay, &shmInfo);
172 shmdt(shmInfo.shmaddr);
173 shmctl(shmInfo.shmid, IPC_RMID, NULL);
175 XDestroyImage(pXimage);
179 XCloseDisplay(pHdisplay);
184 }} // Tizen::Graphics