Fixed OnBoundsChanged
authorHeeJu Kang <mobum.kang@samsung.com>
Wed, 8 May 2013 01:14:52 +0000 (10:14 +0900)
committerHeeJu Kang <mobum.kang@samsung.com>
Wed, 8 May 2013 02:32:07 +0000 (11:32 +0900)
Change-Id: I5bade5e2750133f376c05d67781380dda082ba9a
Signed-off-by: HeeJu Kang <mobum.kang@samsung.com>
src/FShell_AppWidgetFrame.cpp
src/FShell_AppWidgetPopup.cpp
src/FShell_AppWidgetViewManager.cpp

index 3bbee78..c30cec2 100644 (file)
@@ -94,11 +94,11 @@ _AppWidgetFrame::Initialize(const FloatDimension& size)
        r = CreateRootVisualElement();
        SysTryReturn(NID_SHELL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
-       FloatRectangle bounds(0.0f, 0.0f, 1.0f, 1.0f);
-       r = SetBounds(bounds, false);
+       FloatRectangle bounds(0.0f, 0.0f, size.width, size.height);
+       r = SetBounds(bounds);
        SysTryReturn(NID_SHELL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
-       __pAppWidgetLayer->SetLayerBounds(bounds);
+       __pAppWidgetLayer->SetLayerBounds(FloatRectangle(0.0f, 0.0f, 1.0f, 1.0f));
        __pAppWidgetLayer->SetShowState(false);
 
        __pAppWidgetFrameRootVisualElement->SetImplicitAnimationEnabled(false);
@@ -123,8 +123,8 @@ _AppWidgetFrame::SetProviderId(const String& providerId)
        SysTryReturn(NID_SHELL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
        FloatRectangle bounds(0.0f, 0.0f, __appwidgetSize.width, __appwidgetSize.height);
-       r = SetBounds(bounds);
-       SysTryReturn(NID_SHELL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       __pAppWidgetLayer->SetLayerBounds(bounds);
 
        return r;
 }
@@ -159,7 +159,7 @@ _AppWidgetFrame::SetLayerBounds(const FloatRectangle& bounds)
 {
        result r = E_SUCCESS;
 
-       if (__pAppWidgetFrameRootVisualElement)
+       if (__pAppWidgetFrameRootVisualElement && !GetProviderId().IsEmpty())
        {
                _AppWidgetLayer* pLayer = dynamic_cast<_AppWidgetLayer*>(__pAppWidgetFrameRootVisualElement->GetNativeLayer());
                r = GetLastResult();
@@ -175,7 +175,7 @@ _AppWidgetFrame::SetLayerBounds(const FloatRectangle& bounds)
 result
 _AppWidgetFrame::CreateLayer(void)
 {
-       unique_ptr<_AppWidgetLayer> pLayer(new (std::nothrow) _AppWidgetLayer(GetProviderId(), GetSizeF()));
+       unique_ptr<_AppWidgetLayer> pLayer(new (std::nothrow) _AppWidgetLayer(GetProviderId(), FloatDimension(1.0f, 1.0f)));
        SysTryReturn(NID_SHELL, pLayer, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
 
        result r = pLayer->Construct();
index 431bbf2..460b34e 100644 (file)
@@ -185,14 +185,14 @@ _AppWidgetPopup::Initialize(const FloatDimension& size)
        r = CreateRootVisualElement();
        SysTryReturn(NID_SHELL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
-       FloatRectangle bounds(0.0f, 0.0f, 1.0f, 1.0f);
-       r = SetBounds(bounds, false);
+       FloatRectangle bounds(0.0f, 0.0f, size.width, size.height);
+       r = SetBounds(bounds);
        SysTryReturn(NID_SHELL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
        r = __pAppWidgetPopupPresenter->Initialize();
        SysTryReturn(NID_SHELL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
-       __pAppWidgetPopupLayer->SetLayerBounds(bounds);
+       __pAppWidgetPopupLayer->SetLayerBounds(FloatRectangle(0.0f, 0.0f, 1.0f, 1.0f));
        __pAppWidgetPopupLayer->SetShowState(false);
 
        __pAppWidgetPopupRootVisualElement->SetImplicitAnimationEnabled(false);
@@ -218,8 +218,8 @@ _AppWidgetPopup::SetProviderId(const String& providerId)
        SysTryReturn(NID_SHELL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
        FloatRectangle bounds(0.0f, 0.0f, __appwidgetSize.width, __appwidgetSize.height);
-       r = SetBounds(bounds);
-       SysTryReturn(NID_SHELL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       __pAppWidgetPopupLayer->SetLayerBounds(bounds);
 
        return r;
 }
@@ -292,7 +292,7 @@ _AppWidgetPopup::SetLayerBounds(const FloatRectangle& bounds)
 {
        result r = E_SUCCESS;
 
-       if (__pAppWidgetPopupRootVisualElement)
+       if (__pAppWidgetPopupRootVisualElement && !GetProviderId().IsEmpty())
        {
                _AppWidgetPopupLayer* pLayer = dynamic_cast<_AppWidgetPopupLayer*>(__pAppWidgetPopupRootVisualElement->GetNativeLayer());
                r = GetLastResult();
@@ -337,7 +337,7 @@ _AppWidgetPopup::UpdateClientBounds(const FloatDimension& size, FloatRectangle&
 result
 _AppWidgetPopup::CreateLayer(void)
 {
-       unique_ptr<_AppWidgetPopupLayer> pLayer(new (std::nothrow) _AppWidgetPopupLayer(GetProviderId(), GetSizeF()));
+       unique_ptr<_AppWidgetPopupLayer> pLayer(new (std::nothrow) _AppWidgetPopupLayer(GetProviderId(), FloatDimension(1.0f, 1.0f)));
        SysTryReturn(NID_SHELL, pLayer, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
 
        result r = pLayer->Construct();
index 998234f..0f013d1 100644 (file)
 
 #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>
@@ -54,23 +62,6 @@ extern "C"
 //#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;
@@ -82,15 +73,14 @@ using namespace Tizen::Ui::Controls;
 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
        {
@@ -120,160 +110,154 @@ dump_bmp(const char* pFileName, const void* pData, int width, int height)
                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
@@ -287,27 +271,35 @@ DumpPixmap(int pixmap)
        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