Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix native screen initialization for BB10

Screen initialization has simplified from PlayBook.  Update samples that
aren't using glview to reflect the proper way.

Also, stop calling navigator_rotation_lock().  It is rarely needed as long
as the proper rotation behaviour is specified in the bar-descriptor.xml
file.
  • Loading branch information...
commit fdc990596874b6c9d2dc0921f8c28739fff21360 1 parent e685a7c
@nlandry nlandry authored
View
58 BelligerentBlocks/src/bbutil.c
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <assert.h>
#include <ctype.h>
#include <unistd.h>
#include <stdio.h>
@@ -202,61 +201,28 @@ bbutil_init_egl(screen_context_t ctx) {
return EXIT_FAILURE;
}
- int screen_resolution[2];
+ const char *env = getenv("WIDTH");
- rc = screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_SIZE, screen_resolution);
- if (rc) {
- perror("screen_get_display_property_iv");
+ if (0 == env) {
+ perror("failed getenv for WIDTH");
bbutil_terminate();
return EXIT_FAILURE;
}
- int angle = atoi(getenv("ORIENTATION"));
+ int width = atoi(env);
- screen_display_mode_t screen_mode;
- rc = screen_get_display_property_pv(screen_disp, SCREEN_PROPERTY_MODE, (void**)&screen_mode);
- if (rc) {
- perror("screen_get_display_property_pv");
- bbutil_terminate();
- return EXIT_FAILURE;
- }
+ env = getenv("HEIGHT");
- int size[2];
- rc = screen_get_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, size);
- if (rc) {
- perror("screen_get_window_property_iv");
+ if (0 == env) {
+ perror("failed getenv for HEIGHT");
bbutil_terminate();
return EXIT_FAILURE;
}
- int buffer_size[2] = {size[0], size[1]};
+ int height = atoi(env);
+ int size[2] = { width, height };
- if ((angle == 0) || (angle == 180)) {
- if (((screen_mode.width > screen_mode.height) && (size[0] < size[1])) ||
- ((screen_mode.width < screen_mode.height) && (size[0] > size[1]))) {
- buffer_size[1] = size[0];
- buffer_size[0] = size[1];
- }
- } else if ((angle == 90) || (angle == 270)){
- if (((screen_mode.width > screen_mode.height) && (size[0] > size[1])) ||
- ((screen_mode.width < screen_mode.height && size[0] < size[1]))) {
- buffer_size[1] = size[0];
- buffer_size[0] = size[1];
- }
- } else {
- fprintf(stderr, "Navigator returned an unexpected orientation angle.\n");
- bbutil_terminate();
- return EXIT_FAILURE;
- }
-
- rc = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, buffer_size);
- if (rc) {
- perror("screen_set_window_property_iv");
- bbutil_terminate();
- return EXIT_FAILURE;
- }
-
- rc = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ROTATION, &angle);
+ rc = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, size);
if (rc) {
perror("screen_set_window_property_iv");
bbutil_terminate();
@@ -483,7 +449,7 @@ void bbutil_render_text(font_t* font, const char* msg, float x, float y, float r
int i, c;
GLfloat *vertices;
GLfloat *texture_coords;
- GLshort* indices;
+ GLushort* indices;
float pen_x = 0.0f;
@@ -506,7 +472,7 @@ void bbutil_render_text(font_t* font, const char* msg, float x, float y, float r
vertices = (GLfloat*) malloc(sizeof(GLfloat) * 8 * msg_len);
texture_coords = (GLfloat*) malloc(sizeof(GLfloat) * 8 * msg_len);
- indices = (GLshort*) malloc(sizeof(GLfloat) * 6 * msg_len);
+ indices = (GLushort*) malloc(sizeof(GLushort) * 6 * msg_len);
for(i = 0; i < msg_len; ++i) {
c = msg[i];
View
53 GoodCitizen/bbutil.c
@@ -201,61 +201,28 @@ bbutil_init_egl(screen_context_t ctx) {
return EXIT_FAILURE;
}
- int screen_resolution[2];
+ const char *env = getenv("WIDTH");
- rc = screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_SIZE, screen_resolution);
- if (rc) {
- perror("screen_get_display_property_iv");
+ if (0 == env) {
+ perror("failed getenv for WIDTH");
bbutil_terminate();
return EXIT_FAILURE;
}
- int angle = atoi(getenv("ORIENTATION"));
+ int width = atoi(env);
- screen_display_mode_t screen_mode;
- rc = screen_get_display_property_pv(screen_disp, SCREEN_PROPERTY_MODE, (void**)&screen_mode);
- if (rc) {
- perror("screen_get_display_property_pv");
- bbutil_terminate();
- return EXIT_FAILURE;
- }
+ env = getenv("HEIGHT");
- int size[2];
- rc = screen_get_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, size);
- if (rc) {
- perror("screen_get_window_property_iv");
+ if (0 == env) {
+ perror("failed getenv for HEIGHT");
bbutil_terminate();
return EXIT_FAILURE;
}
- int buffer_size[2] = {size[0], size[1]};
+ int height = atoi(env);
+ int size[2] = { width, height };
- if ((angle == 0) || (angle == 180)) {
- if (((screen_mode.width > screen_mode.height) && (size[0] < size[1])) ||
- ((screen_mode.width < screen_mode.height) && (size[0] > size[1]))) {
- buffer_size[1] = size[0];
- buffer_size[0] = size[1];
- }
- } else if ((angle == 90) || (angle == 270)){
- if (((screen_mode.width > screen_mode.height) && (size[0] > size[1])) ||
- ((screen_mode.width < screen_mode.height && size[0] < size[1]))) {
- buffer_size[1] = size[0];
- buffer_size[0] = size[1];
- }
- } else {
- fprintf(stderr, "Navigator returned an unexpected orientation angle.\n");
- bbutil_terminate();
- return EXIT_FAILURE;
- }
-
- rc = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, buffer_size);
- if (rc) {
- perror("screen_set_window_property_iv");
- bbutil_terminate();
- return EXIT_FAILURE;
- }
-
- rc = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ROTATION, &angle);
+ rc = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, size);
if (rc) {
perror("screen_set_window_property_iv");
bbutil_terminate();
View
23 GoodCitizen/main.c
@@ -14,23 +14,24 @@
* limitations under the License.
*/
-#include <screen/screen.h>
+#include "bbutil.h"
+
#include <bps/navigator.h>
#include <bps/screen.h>
#include <bps/bps.h>
#include <bps/event.h>
-#include <bps/orientation.h>
+
+#include <screen/screen.h>
+
+#include <EGL/egl.h>
+#include <GLES/gl.h>
+
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <math.h>
-#include <EGL/egl.h>
-#include <GLES/gl.h>
-
-#include "bbutil.h"
-
static GLfloat radio_btn_unselected_vertices[8], radio_btn_selected_vertices[8],
background_portrait_vertices[8], background_landscape_vertices[8],
*background_vertices;
@@ -752,14 +753,6 @@ int main(int argc, char *argv[]) {
return 0;
}
- //Signal BPS library that navigator orientation is not to be locked
- if (BPS_SUCCESS != navigator_rotation_lock(false)) {
- fprintf(stderr, "navigator_rotation_lock failed\n");
- bbutil_terminate();
- screen_destroy_context(screen_cxt);
- return 0;
- }
-
while (!shutdown) {
// Handle user input and accelerometer
handle_events();
View
53 HelloWorldDisplay/bbutil.c
@@ -201,61 +201,28 @@ bbutil_init_egl(screen_context_t ctx) {
return EXIT_FAILURE;
}
- int screen_resolution[2];
+ const char *env = getenv("WIDTH");
- rc = screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_SIZE, screen_resolution);
- if (rc) {
- perror("screen_get_display_property_iv");
+ if (0 == env) {
+ perror("failed getenv for WIDTH");
bbutil_terminate();
return EXIT_FAILURE;
}
- int angle = atoi(getenv("ORIENTATION"));
+ int width = atoi(env);
- screen_display_mode_t screen_mode;
- rc = screen_get_display_property_pv(screen_disp, SCREEN_PROPERTY_MODE, (void**)&screen_mode);
- if (rc) {
- perror("screen_get_display_property_pv");
- bbutil_terminate();
- return EXIT_FAILURE;
- }
+ env = getenv("HEIGHT");
- int size[2];
- rc = screen_get_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, size);
- if (rc) {
- perror("screen_get_window_property_iv");
+ if (0 == env) {
+ perror("failed getenv for HEIGHT");
bbutil_terminate();
return EXIT_FAILURE;
}
- int buffer_size[2] = {size[0], size[1]};
+ int height = atoi(env);
+ int size[2] = { width, height };
- if ((angle == 0) || (angle == 180)) {
- if (((screen_mode.width > screen_mode.height) && (size[0] < size[1])) ||
- ((screen_mode.width < screen_mode.height) && (size[0] > size[1]))) {
- buffer_size[1] = size[0];
- buffer_size[0] = size[1];
- }
- } else if ((angle == 90) || (angle == 270)){
- if (((screen_mode.width > screen_mode.height) && (size[0] > size[1])) ||
- ((screen_mode.width < screen_mode.height && size[0] < size[1]))) {
- buffer_size[1] = size[0];
- buffer_size[0] = size[1];
- }
- } else {
- fprintf(stderr, "Navigator returned an unexpected orientation angle.\n");
- bbutil_terminate();
- return EXIT_FAILURE;
- }
-
- rc = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, buffer_size);
- if (rc) {
- perror("screen_set_window_property_iv");
- bbutil_terminate();
- return EXIT_FAILURE;
- }
-
- rc = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ROTATION, &angle);
+ rc = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, size);
if (rc) {
perror("screen_set_window_property_iv");
bbutil_terminate();
View
34 HelloWorldDisplay/main.c
@@ -14,26 +14,28 @@
* limitations under the License.
*/
-#include <ctype.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/keycodes.h>
-#include <screen/screen.h>
+#include "bbutil.h"
+
+#include <png.h>
+
#include <bps/navigator.h>
#include <bps/screen.h>
#include <bps/bps.h>
#include <bps/event.h>
-#include <bps/orientation.h>
-#include <math.h>
-#include <time.h>
+
#include <screen/screen.h>
+#include <sys/keycodes.h>
+
#include <EGL/egl.h>
#include <GLES/gl.h>
-#include "png.h"
-#include "bbutil.h"
+#include <math.h>
+#include <time.h>
+#include <ctype.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
static float width, height;
static GLuint background;
@@ -177,14 +179,6 @@ int main(int argc, char **argv) {
return 0;
}
- //Signal BPS library that navigator orientation is to be locked
- if (BPS_SUCCESS != navigator_rotation_lock(true)) {
- fprintf(stderr, "navigator_rotation_lock failed\n");
- bbutil_terminate();
- screen_destroy_context(screen_cxt);
- return 0;
- }
-
//Signal BPS library that navigator and screen events will be requested
if (BPS_SUCCESS != screen_request_events(screen_cxt)) {
fprintf(stderr, "screen_request_events failed\n");

1 comment on commit fdc9905

@doturner

Is there any chance you could elaborate a bit on why you shouldn't use navigator_rotation_lock? As far as I can make out, if your application is locked to a given aspect ratio by specifying in the bar-descriptor.xml, you must also use navigator_rotation_lock(true) so that the 'swipe up' gesture does not move around the screen when the device is rotated.

Please sign in to comment.
Something went wrong with that request. Please try again.