From 2b8ea8145a24000a5686e98ec115c329d8849715 Mon Sep 17 00:00:00 2001 From: James Chen Date: Sun, 17 Feb 2013 16:25:15 +0800 Subject: [PATCH] issue #1712: Getting DPI support for Blackberry. --- cocos2dx/platform/blackberry/CCDevice.cpp | 40 ++++++++++++++++++++++ cocos2dx/platform/blackberry/CCEGLView.cpp | 20 ++++++++--- cocos2dx/platform/blackberry/CCEGLView.h | 2 ++ 3 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 cocos2dx/platform/blackberry/CCDevice.cpp diff --git a/cocos2dx/platform/blackberry/CCDevice.cpp b/cocos2dx/platform/blackberry/CCDevice.cpp new file mode 100644 index 0000000000..f0072a3917 --- /dev/null +++ b/cocos2dx/platform/blackberry/CCDevice.cpp @@ -0,0 +1,40 @@ +#include "platform/CCDevice.h" +#include "CCEGLView.h" +#include "CCCommon.h" +#include +#include + +NS_CC_BEGIN + +float CCDevice::getDPI() +{ + static int dpi = -1; + if (dpi == -1) + { + screen_display_t screen_disp = CCEGLView::sharedOpenGLView()->getScreenDisplay(); +#ifdef BLACKBERRY10 + // Dev Alpha: 1280x768, 4.2", 356DPI, 0.6f scale + + screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_DPI, &dpi); +#else + // Playbook: 1024x600, 7", 170DPI, 1.25f scale + int screen_phys_size[2]; + + screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_PHYSICAL_SIZE, screen_phys_size); + //CCLog("screen_phys_size[%d,%d]", screen_phys_size[0], screen_phys_size[1]); + + int screen_resolution[2]; + screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_SIZE, screen_resolution); + //CCLog("screen_resolution[%d,%d]", screen_resolution[0], screen_resolution[1]); + double diagonal_pixels = sqrt((double)(screen_resolution[0] * screen_resolution[0] + screen_resolution[1] * screen_resolution[1])); + // 1 millimeter = 0.0393700787 inches + double diagonal_inches = 0.0393700787 * sqrt((double)(screen_phys_size[0] * screen_phys_size[0] + screen_phys_size[1] * screen_phys_size[1])); + dpi = (int)(diagonal_pixels / diagonal_inches + 0.5); + //CCLog("dpi = %d, pixel = %lf, inches = %lf", dpi, diagonal_pixels, diagonal_inches ); +#endif + } + //CCLog("dpi = %d", dpi); + return dpi; +} + +NS_CC_END diff --git a/cocos2dx/platform/blackberry/CCEGLView.cpp b/cocos2dx/platform/blackberry/CCEGLView.cpp index 7f166a996c..7017508f70 100644 --- a/cocos2dx/platform/blackberry/CCEGLView.cpp +++ b/cocos2dx/platform/blackberry/CCEGLView.cpp @@ -401,18 +401,23 @@ bool CCEGLView::initGL() screen_res[0] = atoi(width_str); screen_res[1] = atoi(height_str); - int rc = screen_set_window_property_iv(m_screenWindow, SCREEN_PROPERTY_BUFFER_SIZE, screen_res); + rc = screen_set_window_property_iv(m_screenWindow, SCREEN_PROPERTY_BUFFER_SIZE, screen_res); if (rc) { fprintf(stderr, "screen_set_window_property_iv(SCREEN_PROPERTY_BUFFER_SIZE)"); return false; } + + rc = screen_get_window_property_pv(m_screenWindow, SCREEN_PROPERTY_DISPLAY, (void **)&m_screen_display); + if (rc) + { + perror("screen_get_window_property_pv(SCREEN_PROPERTY_DISPLAY)"); + return false; + } } else { - - screen_display_t screen_display; - rc = screen_get_window_property_pv(m_screenWindow, SCREEN_PROPERTY_DISPLAY, (void **)&screen_display); + rc = screen_get_window_property_pv(m_screenWindow, SCREEN_PROPERTY_DISPLAY, (void **)&m_screen_display); if (rc) { perror("screen_get_window_property_pv(SCREEN_PROPERTY_DISPLAY)"); @@ -420,7 +425,7 @@ bool CCEGLView::initGL() } screen_display_mode_t screen_mode; - rc = screen_get_display_property_pv(screen_display, SCREEN_PROPERTY_MODE, (void**)&screen_mode); + rc = screen_get_display_property_pv(m_screen_display, SCREEN_PROPERTY_MODE, (void**)&screen_mode); if (rc) { perror("screen_get_display_property_pv(SCREEN_PROPERTY_MODE)"); @@ -793,4 +798,9 @@ bool CCEGLView::handleEvents() return true; } +screen_display_t CCEGLView::getScreenDisplay() const +{ + return m_screen_display; +} + NS_CC_END diff --git a/cocos2dx/platform/blackberry/CCEGLView.h b/cocos2dx/platform/blackberry/CCEGLView.h index 0a8e7824ee..23ece70dbc 100644 --- a/cocos2dx/platform/blackberry/CCEGLView.h +++ b/cocos2dx/platform/blackberry/CCEGLView.h @@ -64,6 +64,7 @@ public: static CCEGLView* sharedOpenGLView(); bool handleEvents(); + screen_display_t getScreenDisplay() const; private: void release(); @@ -89,6 +90,7 @@ private: screen_event_t m_screenEvent; screen_window_t m_screenWindow; screen_context_t m_screenContext; + screen_display_t m_screen_display; char m_windowGroupID[16]; };