ScreenRotation.c
上传用户:lqx1163
上传日期:2014-08-13
资源大小:9183k
文件大小:16k
源码类别:

MTK

开发平台:

C/C++

  1. /*****************************************************************************
  2. *  Copyright Statement:
  3. *  --------------------
  4. *  This software is protected by Copyright and the information contained
  5. *  herein is confidential. The software may not be copied and the information
  6. *  contained herein may not be used or disclosed except with the written
  7. *  permission of MediaTek Inc. (C) 2005
  8. *
  9. *  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  10. *  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  11. *  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
  12. *  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  13. *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  14. *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  15. *  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  16. *  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  17. *  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
  18. *  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
  19. *  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
  20. *  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
  21. *
  22. *  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
  23. *  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  24. *  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  25. *  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
  26. *  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
  27. *
  28. *  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
  29. *  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
  30. *  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
  31. *  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
  32. *  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
  33. *
  34. *****************************************************************************/
  35. /*****************************************************************************
  36.  *
  37.  * Filename:
  38.  * ---------
  39.  *  ScreenRotation.c
  40.  *
  41.  * Project:
  42.  * --------
  43.  *  MAUI
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *  MMI screen rotation 
  48.  *  Available after MT6217 & MT6219, but not MT6218B
  49.  *
  50.  * Author:
  51.  * -------
  52.  * -------
  53.  *
  54.  *============================================================================
  55.  *             HISTORY
  56.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  57.  *------------------------------------------------------------------------------
  58.  * removed!
  59.  *
  60.  * removed!
  61.  * removed!
  62.  * removed!
  63.  *
  64.  * removed!
  65.  * removed!
  66.  * removed!
  67.  *
  68.  * removed!
  69.  * removed!
  70.  * removed!
  71.  *
  72.  * removed!
  73.  * removed!
  74.  * removed!
  75.  *
  76.  * removed!
  77.  * removed!
  78.  * removed!
  79.  *
  80.  * removed!
  81.  * removed!
  82.  * removed!
  83.  *
  84.  *------------------------------------------------------------------------------
  85.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  86.  *============================================================================
  87.  ****************************************************************************/
  88. #include "MMI_features.h"
  89. #ifdef __MMI_SCREEN_ROTATE__
  90. #include "PixtelDataTypes.h"
  91. #include "gdi_include.h"
  92. #include "kal_non_specific_general_types.h"
  93. #include "lcd_if.h"
  94. #include "EventsGprot.h"
  95. #include "GlobalDefs.h"
  96. #include "FrameworkStruct.h"
  97. #include "DebugInitDef.h"
  98. #include "gdi_include.h"
  99. #include "wgui_categories.h"
  100. #include "IdleAppDef.h" /* SCREEN_ROTATION_DUMMY_ID */
  101. #include "TimerEvents.h"        /* FRM_SCREEN_ROTATION_TIMER */
  102. #include "EventsDcl.h"  /* StartMyTimer() */
  103. #include "HistoryGprot.h"       /* DisplayIdleScreen() */
  104. #include "AllAppGprot.h"        /* setup_UI_wrappers() */
  105. #include "wgui_status_icons.h"
  106. #include "ScreenRotationGprot.h"
  107. #ifndef GDI_USING_LAYER_ROTATE
  108. #error "Hardware does not support rotation"
  109. #endif 
  110. extern S32 MAIN_LCD_device_width;
  111. extern S32 MAIN_LCD_device_height;
  112. extern void UpdateUITheme(void);
  113. /***************************************************************************** 
  114. * Define
  115. *****************************************************************************/
  116. /***************************************************************************** 
  117. * Typedef 
  118. *****************************************************************************/
  119. typedef struct
  120. {
  121.     U8 wh_swapped;  /* width-height swapped */
  122.     U8 lcd_layer_rotate;
  123. } frm_screen_rotation_struct;
  124. /***************************************************************************** 
  125. * Local Variable
  126. *****************************************************************************/
  127. static const frm_screen_rotation_struct g_screen_rotation_data[MMI_FRM_SCREEN_ROTATE_MAX_TYPE] = 
  128. {
  129.     {0, GDI_LCD_LAYER_ROTATE_0},
  130.     {1, GDI_LCD_LAYER_ROTATE_90},
  131.     {0, GDI_LCD_LAYER_ROTATE_180},
  132.     {1, GDI_LCD_LAYER_ROTATE_270},
  133.     {0, GDI_LCD_LAYER_ROTATE_0_MIRROR},
  134.     {1, GDI_LCD_LAYER_ROTATE_90_MIRROR},
  135.     {0, GDI_LCD_LAYER_ROTATE_180_MIRROR},
  136.     {1, GDI_LCD_LAYER_ROTATE_270_MIRROR}
  137. };
  138. /* Rotation value of the current screen with mmi_frm_screen_rotate() */
  139. static mmi_frm_screen_rotate_enum g_mmi_frm_screen_rotate = MMI_FRM_SCREEN_ROTATE_0;
  140. /* Rotation value of the current screen with mmi_frm_set_self_rotation_flag()  (-1 if not set) */
  141. static S32 g_mmi_frm_self_screen_rotate = -1;
  142. /* Rotation value of the previous screen */
  143. static mmi_frm_screen_rotate_enum g_mmi_frm_previous_screen_rotate = MMI_FRM_SCREEN_ROTATE_0;
  144. /***************************************************************************** 
  145. * Local Function
  146. *****************************************************************************/
  147. /*****************************************************************************
  148.  * FUNCTION
  149.  *  mmi_frm_rotate_screen_setup_environment
  150.  * DESCRIPTION
  151.  *  
  152.  * PARAMETERS
  153.  *  data        [IN]        
  154.  * RETURNS
  155.  *  void
  156.  *****************************************************************************/
  157. static void mmi_frm_rotate_screen_setup_environment(const frm_screen_rotation_struct *data)
  158. {
  159.     /*----------------------------------------------------------------*/
  160.     /* Local Variables                                                */
  161.     /*----------------------------------------------------------------*/
  162.     /*----------------------------------------------------------------*/
  163.     /* Code Body                                                      */
  164.     /*----------------------------------------------------------------*/
  165.     if (data->wh_swapped)
  166.     {
  167.         MAIN_LCD_device_height = GDI_LCD_WIDTH;
  168.         MAIN_LCD_device_width = GDI_LCD_HEIGHT;
  169.     }
  170.     else
  171.     {
  172.         MAIN_LCD_device_height = GDI_LCD_HEIGHT;
  173.         MAIN_LCD_device_width = GDI_LCD_WIDTH;
  174.     }
  175.     gdi_layer_resize(MAIN_LCD_device_width, MAIN_LCD_device_height);
  176.     /* Setup basic UI global varaibles */
  177.     setup_UI_wrappers();
  178.     /* Re-intialize UI components . */
  179.     wgui_init();
  180.     arrange_status_icons();
  181.     /* Update to current theme setting. */
  182.     UpdateUITheme();
  183. }
  184. /***************************************************************************** 
  185. * Global Variable
  186. *****************************************************************************/
  187. /***************************************************************************** 
  188. * Global Function
  189. *****************************************************************************/
  190. /*****************************************************************************
  191.  * FUNCTION
  192.  *  mmi_frm_screen_rotate
  193.  * DESCRIPTION
  194.  *  
  195.  * PARAMETERS
  196.  *  rotation        [IN]        
  197.  * RETURNS
  198.  *  void
  199.  *****************************************************************************/
  200. void mmi_frm_screen_rotate(mmi_frm_screen_rotate_enum rotation)
  201. {
  202.     /*----------------------------------------------------------------*/
  203.     /* Local Variables                                                */
  204.     /*----------------------------------------------------------------*/
  205.     /*----------------------------------------------------------------*/
  206.     /* Code Body                                                      */
  207.     /*----------------------------------------------------------------*/
  208.     if (g_mmi_frm_screen_rotate == rotation || rotation < 0 || rotation >= MMI_FRM_SCREEN_ROTATE_MAX_TYPE)
  209.     {
  210.         return;
  211.     }
  212.     if (GDI_LCD_WIDTH != GDI_LCD_HEIGHT &&
  213.         (g_screen_rotation_data[rotation].wh_swapped != g_screen_rotation_data[g_mmi_frm_screen_rotate].wh_swapped))
  214.     {
  215.         g_mmi_frm_screen_rotate = rotation;
  216.         gdi_lcd_set_rotate(g_screen_rotation_data[rotation].lcd_layer_rotate);
  217.         mmi_frm_rotate_screen_setup_environment(&g_screen_rotation_data[g_mmi_frm_screen_rotate]);
  218.     }
  219.     else
  220.     {
  221.         g_mmi_frm_screen_rotate = rotation;
  222.         gdi_lcd_set_rotate(g_screen_rotation_data[rotation].lcd_layer_rotate);
  223.     }
  224. }
  225. /*****************************************************************************
  226.  * FUNCTION
  227.  *  mmi_frm_set_self_rotation_flag
  228.  * DESCRIPTION
  229.  *  Sometimes applications changes the rotation of GDI layer by itself without using mmi_frm_screen_rotate() for
  230.  *  some reasons. (For example, when image sensor is rotated, GDI layer for camera preview needs to be rotated, too)
  231.  *  
  232.  *  After screen is switched, mmi_frm_get_previous_screen_rotate() returns the value set in this function.
  233.  * PARAMETERS
  234.  *  rotation        [IN]        
  235.  * RETURNS
  236.  *  void
  237.  *****************************************************************************/
  238. void mmi_frm_set_self_rotation_flag(mmi_frm_screen_rotate_enum rotation)
  239. {
  240.     /*----------------------------------------------------------------*/
  241.     /* Local Variables                                                */
  242.     /*----------------------------------------------------------------*/
  243.     /*----------------------------------------------------------------*/
  244.     /* Code Body                                                      */
  245.     /*----------------------------------------------------------------*/
  246.     g_mmi_frm_self_screen_rotate = (S32) rotation;
  247. }
  248. /*****************************************************************************
  249.  * FUNCTION
  250.  *  mmi_frm_reset_screen_rotation
  251.  * DESCRIPTION
  252.  *  Reset screen rotation and context and reset the rotation of base layer.
  253.  * PARAMETERS
  254.  *  void
  255.  * RETURNS
  256.  *  void
  257.  *****************************************************************************/
  258. void mmi_frm_reset_screen_rotation(void)
  259. {
  260.     /*----------------------------------------------------------------*/
  261.     /* Local Variables                                                */
  262.     /*----------------------------------------------------------------*/
  263.     MMI_BOOL clear_screen = MMI_FALSE;
  264.     /*----------------------------------------------------------------*/
  265.     /* Code Body                                                      */
  266.     /*----------------------------------------------------------------*/
  267.     if (g_mmi_frm_self_screen_rotate >= 0)
  268.     {
  269.         g_mmi_frm_previous_screen_rotate = (mmi_frm_screen_rotate_enum) g_mmi_frm_self_screen_rotate;
  270.         g_mmi_frm_self_screen_rotate = -1;
  271.         /* Unnecessary to set 'clear_screen' because the application will do it in its screen exit handler */
  272.     }
  273.     else
  274.     {
  275.         g_mmi_frm_previous_screen_rotate = g_mmi_frm_screen_rotate;
  276.         if (g_mmi_frm_screen_rotate != MMI_FRM_SCREEN_ROTATE_0)
  277.         {
  278.             clear_screen = MMI_TRUE;
  279.         }
  280.     }
  281.     mmi_frm_screen_rotate(MMI_FRM_SCREEN_ROTATE_0);
  282.     /* 
  283.      * Note: after screen is rotated, the content of LCD double buffer is wrong.
  284.      *
  285.      * If backlight was off and the next screen turn on backlight, it will BLT the 
  286.      * content of LCD double buffer to the screen, and the screen is messed.
  287.      *
  288.      * Framework should be responsible to clear the screen to black to avoid blinking 
  289.      * when backlight is turned on.
  290.      */
  291.     if (clear_screen)
  292.     {
  293.         gdi_layer_clear(GDI_COLOR_BLACK);
  294.     }
  295. }
  296. /*****************************************************************************
  297.  * FUNCTION
  298.  *  mmi_frm_is_previous_screen_width_height_swapped
  299.  * DESCRIPTION
  300.  *  Check whether the previous screen has swapped width and height
  301.  * PARAMETERS
  302.  *  void
  303.  * RETURNS
  304.  *  MMI_BOOL
  305.  *****************************************************************************/
  306. MMI_BOOL mmi_frm_is_previous_screen_width_height_swapped(void)
  307. {
  308.     /*----------------------------------------------------------------*/
  309.     /* Local Variables                                                */
  310.     /*----------------------------------------------------------------*/
  311.     /*----------------------------------------------------------------*/
  312.     /* Code Body                                                      */
  313.     /*----------------------------------------------------------------*/
  314.     if (GDI_LCD_WIDTH != GDI_LCD_HEIGHT && g_screen_rotation_data[g_mmi_frm_previous_screen_rotate].wh_swapped)
  315.     {
  316.         return MMI_TRUE;
  317.     }
  318.     else
  319.     {
  320.         return MMI_FALSE;
  321.     }
  322. }
  323. /*****************************************************************************
  324.  * FUNCTION
  325.  *  mmi_frm_get_previous_screen_rotate
  326.  * DESCRIPTION
  327.  *  Get the previous screen rotation value
  328.  *  
  329.  *  It is typically used screens like popup dialog because they need to preserve the display of the previous screens.
  330.  * PARAMETERS
  331.  *  void
  332.  * RETURNS
  333.  *  mmi_frm_screen_rotate_enum
  334.  *****************************************************************************/
  335. mmi_frm_screen_rotate_enum mmi_frm_get_previous_screen_rotate(void)
  336. {
  337.     /*----------------------------------------------------------------*/
  338.     /* Local Variables                                                */
  339.     /*----------------------------------------------------------------*/
  340.     /*----------------------------------------------------------------*/
  341.     /* Code Body                                                      */
  342.     /*----------------------------------------------------------------*/
  343.     return g_mmi_frm_previous_screen_rotate;
  344. }
  345. /*****************************************************************************
  346.  * FUNCTION
  347.  *  mmi_frm_is_screen_width_height_swapped
  348.  * DESCRIPTION
  349.  *  Check whether the current screen has swapped width and height
  350.  * PARAMETERS
  351.  *  void
  352.  * RETURNS
  353.  *  MMI_BOOL
  354.  *****************************************************************************/
  355. MMI_BOOL mmi_frm_is_screen_width_height_swapped(void)
  356. {
  357.     /*----------------------------------------------------------------*/
  358.     /* Local Variables                                                */
  359.     /*----------------------------------------------------------------*/
  360.     /*----------------------------------------------------------------*/
  361.     /* Code Body                                                      */
  362.     /*----------------------------------------------------------------*/
  363.     if (GDI_LCD_WIDTH != GDI_LCD_HEIGHT && g_screen_rotation_data[g_mmi_frm_screen_rotate].wh_swapped)
  364.     {
  365.         return MMI_TRUE;
  366.     }
  367.     else
  368.     {
  369.         return MMI_FALSE;
  370.     }
  371. }
  372. /*****************************************************************************
  373.  * FUNCTION
  374.  *  mmi_frm_get_screen_rotate
  375.  * DESCRIPTION
  376.  *  Get the current screen rotation value
  377.  * PARAMETERS
  378.  *  void
  379.  * RETURNS
  380.  *  mmi_frm_screen_rotate_enum
  381.  *****************************************************************************/
  382. mmi_frm_screen_rotate_enum mmi_frm_get_screen_rotate(void)
  383. {
  384.     /*----------------------------------------------------------------*/
  385.     /* Local Variables                                                */
  386.     /*----------------------------------------------------------------*/
  387.     /*----------------------------------------------------------------*/
  388.     /* Code Body                                                      */
  389.     /*----------------------------------------------------------------*/
  390.     return g_mmi_frm_screen_rotate;
  391. }
  392. #else /* __MMI_SCREEN_ROTATE__ */ 
  393. int screen_rotation_dummy;  /* Get rid of compile warning */
  394. #endif /* __MMI_SCREEN_ROTATE__ */