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_BitmapScreenCapture.cpp
20 * @brief This is the cpp file for BitmapScreenCapture.
27 #include <Ecore_Evas.h>
32 #include <X11/Xutil.h>
33 #include <X11/extensions/XShm.h>
34 #include <X11/Xatom.h>
36 #include <sys/types.h>
39 #include "FGrp_Callback.h"
47 Ecore_Evas* pEcoreEvas = static_cast<Ecore_Evas*>(Tizen::Graphics::_GetDefaultFrameEcoreEvasHandle());
49 if (pEcoreEvas == null)
54 return (Window) ecore_evas_window_get(pEcoreEvas);
58 namespace Tizen { namespace Graphics
62 _GetScreenShot(int depth, unsigned char*& pOutBuffer, int& screenWidth, int& screenHeight)
64 // check input parameter
75 // pBuffer should be NULL pointer
76 if (pOutBuffer != NULL)
82 unsigned char* pTempBuffer = 0;
84 Display* pDisplay = XOpenDisplay(NULL);
85 int displayWidth = DisplayWidth(pDisplay, DefaultScreen(pDisplay));
86 int displayHeight = DisplayHeight(pDisplay, DefaultScreen(pDisplay));
88 // Can not use a root window --> RootWindow(pDisplay, DefaultScreen(pDisplay))
89 Window root = GetEvasWindow();
91 XShmSegmentInfo shmInfo;
92 XImage* pXimage = XShmCreateImage(pDisplay, DefaultVisualOfScreen(DefaultScreenOfDisplay(pDisplay)), 24, ZPixmap,
93 NULL, &shmInfo, (unsigned int) displayWidth, (unsigned int) displayHeight);
99 shmInfo.shmid = shmget(IPC_PRIVATE, pXimage->bytes_per_line * pXimage->height, IPC_CREAT | 0777);
101 pXimage->data = (char*) shmat(shmInfo.shmid, 0, 0);
102 shmInfo.shmaddr = pXimage->data;
103 shmInfo.readOnly = False;
105 if (!XShmAttach(pDisplay, &shmInfo))
110 if (!XShmGetImage(pDisplay, root, pXimage, 0, 0, AllPlanes))
115 XSync(pDisplay, False);
117 // Apply screen rotation
124 atom_rotaion = XInternAtom(dpy, "X_SCREEN_ROTATION", True);
126 if (!atom_rotaion || !getXwindowProperty(root, atom_rotaion, XA_CARDINAL, (unsigned char*) &rotate, 1))
128 rotate = RR_Rotate_0;
131 if (rotate == RR_Rotate_90 || rotate == RR_Rotate_270)
133 rot_buffer = calloc(ximage->bytes_per_line * ximage->height, 1);
135 convert_image((uint32_t*) ximage->data,
136 (uint32_t*) rot_buffer,
137 PIXMAN_x8b8g8r8, PIXMAN_x8b8g8r8,
138 height, width, width, height,
139 (rotate == RR_Rotate_90) ? 90 : 270);
158 // copy from the captured buffer
160 int bufferSize = pXimage->bytes_per_line * pXimage->height;
162 pTempBuffer = new (std::nothrow) unsigned char[bufferSize];
164 if (pTempBuffer == NULL)
169 memcpy(pTempBuffer, pXimage->data, bufferSize);
173 pOutBuffer = pTempBuffer;
174 screenWidth = pXimage->width;
175 screenHeight = pXimage->height;
177 // release the captured buffer
179 XShmDetach(pDisplay, &shmInfo);
180 shmdt(shmInfo.shmaddr);
181 shmctl(shmInfo.shmid, IPC_RMID, NULL);
183 XDestroyImage(pXimage);
186 XCloseDisplay(pDisplay);
192 delete[] pTempBuffer;
196 XShmDetach(pDisplay, &shmInfo);
197 shmdt(shmInfo.shmaddr);
198 shmctl(shmInfo.shmid, IPC_RMID, NULL);
200 XDestroyImage(pXimage);
204 XCloseDisplay(pDisplay);
209 }} // Tizen::Graphics