#include <new>
#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <Ecore_X.h>
#include <Evas.h>
extern "C"
{
+#include <X11/Xproto.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <dri2.h>
+#include <tbm_bufmgr.h>
+#include <xf86drm.h>
#include <elm_config.h>
}
#include <livebox-service.h>
//#define _PIXMAP_TEST
//#define _BUFFER_TEST
-#if defined(_PIXMAP_TEST)
-extern "C"
-{
-#include <stdio.h>
-#include <stdlib.h>
-#include <X11/Xproto.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <dri2.h>
-#define virtual UICTRL_INTERNAL_VIRTUAL_REDEFINE
-#define private UICTRL_INTERNAL_PRIVATE_REDEFINE
-#include <libdrm/drm_slp_bufmgr.h>
-#undef virtual
-#undef private
-}
-#endif // _PIXMAP_TEST
-
using namespace std;
using namespace Tizen::Base;
using namespace Tizen::Base::Collection;
namespace
{
-#if defined(_PIXMAP_TEST)
-
-drm_slp_bufmgr __bufMgr = null;
-int __FileCount = 0;
+tbm_bufmgr __pTbmBufmgr = null;
+int __fileCount = 0;
+int __drmFileDescriptor = -1;
void
dump_bmp(const char* pFileName, const void* pData, int width, int height)
{
- int i = 0;
+ FILE* pFile = null;
struct
{
unsigned int nimpcolors;
} bmp_dib_v3_header_t = { 0x28, 0, 0, 1, 24, 0, 0, 0, 0, 0, 0 };
- unsigned int* pBlocks = null;
+ if (pFileName != null)
+ {
+ pFile = fopen(pFileName, "w+");
+ }
- FILE* pFile = fopen(pFileName, "w+");
if (pFile == null)
{
- SysLog(NID_SHELL, "failed to fopen [%s]", pFileName);
+ SysSecureLog(NID_UI_CTRL,"Failed to open %s", pFileName);
return;
}
- else
- {
- bmpfile_header.filesz = sizeof(bmpfile_magic) + sizeof(bmpfile_header) + sizeof(bmp_dib_v3_header_t) + width * height * 3;
- bmp_dib_v3_header_t.header_sz = sizeof(bmp_dib_v3_header_t);
- bmp_dib_v3_header_t.width = width;
- bmp_dib_v3_header_t.height = -height;
- bmp_dib_v3_header_t.nplanes = 1;
- bmp_dib_v3_header_t.bmp_bytesz = width * height * 3;
- fwrite(&bmpfile_magic, sizeof(bmpfile_magic), 1, pFile);
- fwrite(&bmpfile_header, sizeof(bmpfile_header), 1, pFile);
- fwrite(&bmp_dib_v3_header_t, sizeof(bmp_dib_v3_header_t), 1, pFile);
+ bmpfile_header.filesz = sizeof(bmpfile_magic) + sizeof(bmpfile_header) + sizeof(bmp_dib_v3_header_t) + width * height * 3;
+ bmp_dib_v3_header_t.header_sz = sizeof(bmp_dib_v3_header_t);
+ bmp_dib_v3_header_t.width = width;
+ bmp_dib_v3_header_t.height = -height;
+ bmp_dib_v3_header_t.nplanes = 1;
+ bmp_dib_v3_header_t.bmp_bytesz = width * height * 3;
- pBlocks = (unsigned int*)pData;
- for (i = 0; i < (height * width); i++)
- fwrite(&pBlocks[i], 3, 1, pFile);
+ fwrite(&bmpfile_magic, sizeof(bmpfile_magic), 1, pFile);
+ fwrite(&bmpfile_header, sizeof(bmpfile_header), 1, pFile);
+ fwrite(&bmp_dib_v3_header_t, sizeof(bmp_dib_v3_header_t), 1, pFile);
- fclose(pFile);
- }
+ unsigned int* pBlocks = (unsigned int*)pData;
- return;
+ for (int i = 0; i < (height * width); i++)
+ {
+ fwrite(&pBlocks[i], 3, 1, pFile);
+ }
+
+ fclose(pFile);
}
-drm_slp_bufmgr
+tbm_bufmgr
bufmgr_get(Display* pDisplay, Pixmap pixmap)
{
- int screen;
- int drm_fd;
- drm_slp_bufmgr bufmgr;
- int eventBase, errorBase;
- int dri2Major, dri2Minor;
- char* pDriverName, *pDeviceName;
- drm_magic_t magic;
-
- screen = DefaultScreen(pDisplay);
+ int screen = DefaultScreen(pDisplay);
- /* DRI2 */
- if (!DRI2QueryExtension (pDisplay, &eventBase, &errorBase))
+ // DRI2
+ int eventBase = 0;
+ int errorBase = 0;
+ if (!DRI2QueryExtension(pDisplay, &eventBase, &errorBase))
{
- SysLog(NID_SHELL, "!!Error : DRI2QueryExtension !!\n");
+ SysSecureLog(NID_UI_CTRL, "Failed to get value of DRI2QueryExtension.");
return null;
}
- if (!DRI2QueryVersion (pDisplay, &dri2Major, &dri2Minor))
+ int dri2Major = 0;
+ int dri2Minor = 0;
+ if (!DRI2QueryVersion(pDisplay, &dri2Major, &dri2Minor))
{
- SysLog(NID_SHELL, "!!Error : DRI2QueryVersion !!\n");
+ SysSecureLog(NID_UI_CTRL, "Failed to get value of DRI2QueryVersion.");
return null;
}
- if (!DRI2Connect (pDisplay, RootWindow(pDisplay, screen), &pDriverName, &pDeviceName))
+ char* pDriverName = null;
+ char* pDeviceName = null;
+ if (!DRI2Connect(pDisplay, RootWindow(pDisplay, screen), &pDriverName, &pDeviceName))
{
- SysLog(NID_SHELL, "!!Error : DRI2Connect !!\n");
+ SysSecureLog(NID_UI_CTRL, "Failed to get value of DRI2Connect.");
return null;
}
- SysLog(NID_SHELL, "Open drm device : %s\n", pDeviceName);
+ SysSecureLog(NID_UI_CTRL, "The current name of open drm device is %s.", pDeviceName);
- /* get the drm_fd though opening the deviceName */
- drm_fd = open (pDeviceName, O_RDWR);
- if (drm_fd < 0)
+ // Get the drm_fd though opening the deviceName
+ __drmFileDescriptor = open(pDeviceName, O_RDWR);
+ if (__drmFileDescriptor < 0)
{
- SysLog(NID_SHELL, "!!Error : cannot open drm device (%s)\n", pDeviceName);
+ SysSecureLog(NID_UI_CTRL, "Failed to open drm device (%s)", pDeviceName);
return null;
}
- /* get the drm magic */
- drmGetMagic(drm_fd, &magic);
- printf("drm magic = %d \n", magic);
-
+ // Get the drm magic
+ drm_magic_t magic;
+ drmGetMagic(__drmFileDescriptor, &magic);
if (!DRI2Authenticate(pDisplay, RootWindow(pDisplay, screen), magic))
{
- SysLog(NID_SHELL, "!!Error : DRI2Authenticate !!\n");
- close (drm_fd);
+ SysSecureLog(NID_UI_CTRL, "Failed to get value of DRI2Authenticate.");
+ close(__drmFileDescriptor);
+ __drmFileDescriptor = -1;
return null;
}
- /* drm slp buffer manager init */
- bufmgr = drm_slp_bufmgr_init (drm_fd, null);
+ // tbm buffer manager init
+ tbm_bufmgr bufmgr = tbm_bufmgr_init(__drmFileDescriptor);
if (!bufmgr)
{
- SysLog(NID_SHELL, "!!Error : failed to init buffer manager \n");
- close (drm_fd);
+ SysSecureLog(NID_UI_CTRL, "Failed to initialize buffer manager.");
+ close(__drmFileDescriptor);
+ __drmFileDescriptor = -1;
return null;
}
- DRI2CreateDrawable (pDisplay, pixmap);
+ DRI2CreateDrawable(pDisplay, pixmap);
return bufmgr;
}
-void
-pixmap_update(Display* pDisplay, drm_slp_bufmgr bufmgr, Pixmap pixmap, int x, int y, int width, int height)
-{
- DRI2Buffer* pDri2_buffers = null;
- unsigned int attachments[1];
- int dri2_count, dri2_out_count;
- int dri2_width, dri2_height, dri2_stride;
- drm_slp_bo bo;
- int opt;
- void* pVirtualBuf = null;
+static void
+pixmap_update(Display* pDisplay, tbm_bufmgr bufmgr, Pixmap pixmap, int x, int y, int width, int height)
+{
+ int dri2_width = 0;
+ int dri2_height = 0;
+ unsigned int attachments[1] = { DRI2BufferFrontLeft };
+ int dri2_count = 1;
+ int dri2_out_count = 0;
+
+ int opt = TBM_OPTION_READ|TBM_OPTION_WRITE;
char imgFile[100] = {0,};
- attachments[0] = DRI2BufferFrontLeft;
- dri2_count = 1;
- pDri2_buffers = DRI2GetBuffers (pDisplay, pixmap, &dri2_width, &dri2_height,
- attachments, dri2_count, &dri2_out_count);
+ tbm_bo bo;
+ tbm_bo_handle bo_handle;
- if (!pDri2_buffers)
- {
- SysLog(NID_SHELL, "[Error] : failed to get buffers\n");
- goto update_done;
- }
+ DRI2Buffer* pDri2_buffers = DRI2GetBuffers (pDisplay, pixmap, &dri2_width, &dri2_height, attachments, dri2_count, &dri2_out_count);
+ SysTryLogCatch(NID_UI_CTRL, pDri2_buffers != null, , "Failed to get buffers.");
+ SysTryLogCatch(NID_UI_CTRL, pDri2_buffers[0].name != null, , "Failed to get a handle of the dri2 buffer.");
- if (!pDri2_buffers[0].name)
+ SysSecureLog(NID_UI_CTRL, "The current name of Dri2_buffers[0] is %d.", pDri2_buffers[0].name);
+
+ bo = tbm_bo_import(bufmgr, pDri2_buffers[0].name);
+ SysTryLogCatch(NID_UI_CTRL, bo != null, , "Failed to import bo (key : %d).", pDri2_buffers[0].name);
+
+ bo_handle = tbm_bo_map(bo, TBM_DEVICE_CPU, opt);
+ SysTryLogCatch(NID_UI_CTRL, bo_handle.ptr != null, , "Failed to get map.");
+
+ memset(imgFile, 0, sizeof(imgFile));
+ sprintf(imgFile,"./dump%d.bmp", __fileCount++);
+
+ if (__fileCount == 5 || __fileCount == 20)
{
- SysLog(NID_SHELL, "[Error] : a handle of the dri2 buffer is null \n ");
- goto update_done;
+ dump_bmp(imgFile, bo_handle.ptr, dri2_width, dri2_height);
}
- bo = drm_slp_bo_import(bufmgr, pDri2_buffers[0].name);
- if (!bo)
+CATCH:
+ if (bo_handle.ptr)
{
- goto update_done;
+ tbm_bo_unmap(bo);
}
- dri2_stride = pDri2_buffers[0].pitch;
-
- opt = DRM_SLP_OPTION_READ|DRM_SLP_OPTION_WRITE;
- pVirtualBuf = (void*)drm_slp_bo_map (bo, DRM_SLP_DEVICE_CPU, opt);
- if (!pVirtualBuf)
+ if (bo)
{
- SysLog(NID_SHELL, "[Error] : failed to map \n");
- goto update_done;
+ tbm_bo_unref(bo);
}
- memset(imgFile, 0, sizeof(imgFile));
- sprintf(imgFile,"./dump%d.bmp", __FileCount++);
- dump_bmp(imgFile, pVirtualBuf, dri2_width, dri2_height);
-
-update_done:
- if (pVirtualBuf)
- drm_slp_bo_unmap(bo, DRM_SLP_DEVICE_CPU);
- if (bo)
- drm_slp_bo_unref(bo);
if (pDri2_buffers)
+ {
free(pDri2_buffers);
+ }
}
void
ecore_x_pixmap_geometry_get(pixmap, &x, &y, &width, &height);
SysTryReturnVoidResult(NID_SHELL, (width > 0) && (height > 0), E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid [0x%x %d %d].", pixmap, width , height);
- if (__bufMgr)
+ if (__drmFileDescriptor > -1)
+ {
+ close(__drmFileDescriptor);
+ __drmFileDescriptor = -1;
+ }
+
+ if (__pTbmBufmgr)
{
- drm_slp_bufmgr_destroy(__bufMgr);
- __bufMgr = null;
+ tbm_bufmgr_deinit(__pTbmBufmgr);
+ __pTbmBufmgr = null;
}
- if (__bufMgr == null)
- __bufMgr = bufmgr_get((Display*)ecore_x_display_get(), pixmap);
+ if (__pTbmBufmgr == null)
+ {
+ __pTbmBufmgr = bufmgr_get((Display*)ecore_x_display_get(), pixmap);
+ }
- if (__bufMgr != null)
+ if (__pTbmBufmgr != null)
{
- pixmap_update((Display*)ecore_x_display_get(), __bufMgr, pixmap, 0, 0, width, height);
+ pixmap_update((Display*)ecore_x_display_get(), __pTbmBufmgr, pixmap, 0, 0, width, height);
}
else
- SysLog(NID_SHELL, "can't get pixmap __bufMgr");
+ {
+ SysSecureLog(NID_UI_CTRL, "can't get pixmap gBufmgr");
+ }
- SysLog(NID_SHELL, "dump pixmap [%d]", pixmap);
+ SysSecureLog(NID_UI_CTRL, "dump pixmap[%d]", pixmap);
}
-#endif // _PIXMAP_TEST
-
}
namespace Tizen { namespace Graphics