Exemplo n.º 1
1
/**
 * Find a compatible camera modes:
 *    1) the same aspect ration as the native display window, which should be a
 *       rotated version of the physical device
 *    2) the smallest resolution in the camera mode list
 * This is to minimize the later color space conversion workload.
 */
bool NDKCamera::MatchCaptureSizeRequest(ANativeWindow* display,
                                        ImageFormat* resView,
                                        ImageFormat* resCap) {
  DisplayDimension disp(ANativeWindow_getWidth(display),
                        ANativeWindow_getHeight(display));
  if (cameraOrientation_ == 90 || cameraOrientation_ == 270) {
    disp.Flip();
  }

  ACameraMetadata* metadata;
  CALL_MGR(
      getCameraCharacteristics(cameraMgr_, activeCameraId_.c_str(), &metadata));
  ACameraMetadata_const_entry entry;
  CALL_METADATA(getConstEntry(
      metadata, ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS, &entry));
  // format of the data: format, width, height, input?, type int32
  bool foundIt = false;
  DisplayDimension foundRes(4000, 4000);
  DisplayDimension maxJPG(0, 0);

  for (int i = 0; i < entry.count; i += 4) {
    int32_t input = entry.data.i32[i + 3];
    int32_t format = entry.data.i32[i + 0];
    if (input) continue;

    if (format == AIMAGE_FORMAT_YUV_420_888 || format == AIMAGE_FORMAT_JPEG) {
      DisplayDimension res(entry.data.i32[i + 1],
                           entry.data.i32[i + 2]);
      if (!disp.IsSameRatio(res)) continue;
      if (format == AIMAGE_FORMAT_YUV_420_888 && foundRes > res) {
        foundIt = true;
        foundRes = res;
      } else if (format == AIMAGE_FORMAT_JPEG && res > maxJPG) {
        maxJPG = res;
      }
    }
  }

  if (foundIt) {
    resView->width = foundRes.org_width();
    resView->height = foundRes.org_height();
    resCap->width = maxJPG.org_width();
    resCap->height = maxJPG.org_height();
  } else {
    LOGW("Did not find any compatible camera resolution, taking 640x480");
    if (disp.IsPortrait()) {
      resView->width = 480;
      resView->height = 640;
    } else {
      resView->width = 640;
      resView->height = 480;
    }
    *resCap = *resView;
  }
  resView->format = AIMAGE_FORMAT_YUV_420_888;
  resCap->format = AIMAGE_FORMAT_JPEG;
  return foundIt;
}
Exemplo n.º 2
0
static void onAppCmd(struct android_app* app, int32_t cmd)
{
	if (!app)
	{
		return;
	}

	switch(cmd)
	{
		case APP_CMD_INIT_WINDOW:
			{
				int32_t orientation = AConfiguration_getOrientation (g_app->config);

				int32_t width;
				int32_t height;

				if (orientation == ACONFIGURATION_ORIENTATION_PORT)
				{
					width = ANativeWindow_getWidth(g_app->window);
					height = ANativeWindow_getHeight(g_app->window);
				}
				else
				{
					height = ANativeWindow_getWidth(g_app->window);
					width = ANativeWindow_getHeight(g_app->window);
				}

				if (width != g_width || height != g_height)
				{
					g_width = width;
					g_height = height;
				}

				g_nativeWindow = app->window;
			}
	        break;

	    case APP_CMD_TERM_WINDOW:
	    case APP_CMD_DESTROY:

	    	if (g_nativeWindow)
	    	{
		    	_glusWindowInternalClose();

		    	g_nativeWindow = 0;
	    	}

			g_width = -1;
			g_height = -1;

	    	app->destroyRequested = 1;

	    	break;
	}
}
Exemplo n.º 3
0
static void engine_handle_cmd(android_app* app, int32_t cmd)
{
    Engine* engine = (Engine*)app->userData;
    switch (cmd)
    {
        case APP_CMD_INIT_WINDOW:
            if (app->window != NULL)
            {
                LOGI("APP_CMD_INIT_WINDOW");

                engine->capture = new cv::VideoCapture(0);

                union {double prop; const char* name;} u;
                u.prop = engine->capture->get(CV_CAP_PROP_SUPPORTED_PREVIEW_SIZES_STRING);

                int view_width = ANativeWindow_getWidth(app->window);
                int view_height = ANativeWindow_getHeight(app->window);

                cv::Size camera_resolution;
                if (u.name)
                    camera_resolution = calc_optimal_camera_resolution(u.name, 640, 480);
                else
                {
                    LOGE("Cannot get supported camera camera_resolutions");
                    camera_resolution = cv::Size(ANativeWindow_getWidth(app->window),
                                          ANativeWindow_getHeight(app->window));
                }

                if ((camera_resolution.width != 0) && (camera_resolution.height != 0))
                {
                    engine->capture->set(CV_CAP_PROP_FRAME_WIDTH, camera_resolution.width);
                    engine->capture->set(CV_CAP_PROP_FRAME_HEIGHT, camera_resolution.height);
                }

                float scale = std::min((float)view_width/camera_resolution.width,
                                       (float)view_height/camera_resolution.height);

                if (ANativeWindow_setBuffersGeometry(app->window, (int)(view_width/scale),
                    int(view_height/scale), WINDOW_FORMAT_RGBA_8888) < 0)
                {
                    LOGE("Cannot set pixel format!");
                    return;
                }

                LOGI("Camera initialized at resoution %dx%d", camera_resolution.width, camera_resolution.height);
            }
            break;
        case APP_CMD_TERM_WINDOW:
            LOGI("APP_CMD_TERM_WINDOW");

            engine->capture->release();
            break;
    }
}
Exemplo n.º 4
0
bool CEGLNativeTypeAndroid::GetNativeResolution(RESOLUTION_INFO *res) const
{
  EGLNativeWindowType *nativeWindow = (EGLNativeWindowType*)CXBMCApp::GetNativeWindow(30000);
  if (!nativeWindow)
    return false;

  if (!m_width || !m_height)
  {
    ANativeWindow_acquire(*nativeWindow);
    res->iWidth = ANativeWindow_getWidth(*nativeWindow);
    res->iHeight= ANativeWindow_getHeight(*nativeWindow);
    ANativeWindow_release(*nativeWindow);
  }
  else
  {
    res->iWidth = m_width;
    res->iHeight = m_height;
  }

  res->fRefreshRate = currentRefreshRate();
  res->dwFlags= D3DPRESENTFLAG_PROGRESSIVE;
  res->iScreen       = 0;
  res->bFullScreen   = true;
  res->iSubtitles    = (int)(0.965 * res->iHeight);
  res->fPixelRatio   = 1.0f;
  res->iScreenWidth  = res->iWidth;
  res->iScreenHeight = res->iHeight;
  res->strMode       = StringUtils::Format("%dx%d @ %.2f%s - Full Screen", res->iScreenWidth, res->iScreenHeight, res->fRefreshRate,
  res->dwFlags & D3DPRESENTFLAG_INTERLACED ? "i" : "");
  CLog::Log(LOGNOTICE,"Current resolution: %s\n",res->strMode.c_str());
  return true;
}
Exemplo n.º 5
0
	int Width() const
	{
		if (app == nullptr || app->window == nullptr)
			return 0;

		return ANativeWindow_getWidth(app->window);
	}
Exemplo n.º 6
0
static void get_screen_dimensions(engine* e) {

	// 縦置きの向き (APad)
	//	06-04 15:47:33.845: D/get_screen_dimensions(13014): ANativeWindow_getWidth: 480
	//	06-04 15:47:33.845: D/get_screen_dimensions(13014): ANativeWindow_getHeight: 752

	// 横置きの向き (APad)
	//	06-04 15:48:38.785: D/get_screen_dimensions(13098): ANativeWindow_getWidth: 800
	//	06-04 15:48:38.785: D/get_screen_dimensions(13098): ANativeWindow_getHeight: 432

	screen_width = (int)ANativeWindow_getWidth(e->app->window);
	screen_height = (int)ANativeWindow_getHeight(e->app->window);

	screen_margin_x_l = screen_width*0.13f;
	screen_margin_x_r = screen_width*0.110f;
	screen_margin_y_t = screen_height*0.187f;
	screen_margin_y_b = screen_height*0.26f;

	LOGD("get_screen_dimensions", "ANativeWindow_getWidth: %d", screen_width);
	LOGD("get_screen_dimensions", "ANativeWindow_getHeight: %d", screen_height);
	LOGD("get_screen_dimensions", "screen_margin_x_l: %d", screen_margin_x_l);
	LOGD("get_screen_dimensions", "screen_margin_x_r: %d", screen_margin_x_r);
	LOGD("get_screen_dimensions", "screen_margin_y_t: %d", screen_margin_y_t);
	LOGD("get_screen_dimensions", "screen_margin_y_b: %d", screen_margin_y_b);
}
Exemplo n.º 7
0
static void _onAppCmd(struct android_app* app, int32_t cmd)
{
    if (!app || app != g_app)
    {
        return;
    }

    switch (cmd)
    {
        case APP_CMD_INIT_WINDOW:
        {
            g_width = ANativeWindow_getWidth(g_app->window);
            g_height = ANativeWindow_getHeight(g_app->window);

            g_nativeAndroidWindow = app->window;
        }
        break;

        case APP_CMD_TERM_WINDOW:
        case APP_CMD_DESTROY:

            g_app->destroyRequested = 1;

            break;
    }
}
Exemplo n.º 8
0
void StWindowImpl::updateWindowPos() {
    if(myMaster.hRC.isNull()) {
        return;
    }

    EGLint aWidth  = 0, aHeight = 0;
    if(myMaster.hWindowGl != NULL) {
        aWidth  = ANativeWindow_getWidth (myMaster.hWindowGl);
        aHeight = ANativeWindow_getHeight(myMaster.hWindowGl);
    } else if(myMaster.eglSurface != EGL_NO_SURFACE) {
        eglQuerySurface(myMaster.hRC->getDisplay(), myMaster.eglSurface, EGL_WIDTH,  &aWidth);
        eglQuerySurface(myMaster.hRC->getDisplay(), myMaster.eglSurface, EGL_HEIGHT, &aHeight);
    } else {
        return;
    }

    if(myRectNorm.width()  == aWidth
    && myRectNorm.height() == aHeight) {
        return;
    }

    myRectNorm.left()   = 0;
    myRectNorm.top()    = 0;
    myRectNorm.right()  = myRectNorm.left() + aWidth;
    myRectNorm.bottom() = myRectNorm.top()  + aHeight;
    myRectFull = myRectNorm;

    myStEvent.Size.init(getEventTime(), myRectNorm.width(), myRectNorm.height(), myForcedAspect);
    signals.onResize->emit(myStEvent.Size);
}
Exemplo n.º 9
0
extern void GetPlatformWindowDimensions(void* nativeHandle, int* width, int* height)
{
    ANativeWindow* w = ANativeWindow_fromSurface(Jni, (jobject)nativeHandle);
    VERBOSE("Got native window for measurements %p", w);
    *width = ANativeWindow_getWidth(w);
    *height = ANativeWindow_getHeight(w);
    ANativeWindow_release(w);
}
Exemplo n.º 10
0
gboolean gst_imx_egl_viv_sink_egl_platform_init_window(GstImxEglVivSinkEGLPlatform *platform, guintptr window_handle, G_GNUC_UNUSED gboolean event_handling, G_GNUC_UNUSED GstVideoInfo *video_info, G_GNUC_UNUSED gboolean fullscreen, gint x_coord, gint y_coord, G_GNUC_UNUSED guint width, G_GNUC_UNUSED guint height, G_GNUC_UNUSED gboolean borderless)
{
	EGLint num_configs, format;
	EGLConfig config;
	int actual_x, actual_y, actual_width, actual_height;

	static EGLint const eglconfig_attribs[] =
	{
		EGL_RED_SIZE, 1,
		EGL_GREEN_SIZE, 1,
		EGL_BLUE_SIZE, 1,
		EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
		EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
		EGL_NONE
	};

	static EGLint const ctx_attribs[] =
	{
		EGL_CONTEXT_CLIENT_VERSION, 2,
		EGL_NONE
	};

	platform->native_window = (EGLNativeWindowType)window_handle;

	if (!eglChooseConfig(platform->egl_display, eglconfig_attribs, &config, 1, &num_configs))
	{
		GST_ERROR("eglChooseConfig failed: %s", gst_imx_egl_viv_sink_egl_platform_get_last_error_string());
		return FALSE;
	}

	if (!eglGetConfigAttrib(platform->egl_display, config, EGL_NATIVE_VISUAL_ID, &format)) {
		GST_ERROR("eglGetConfigAttrib failed: %s", gst_imx_egl_viv_sink_egl_platform_get_last_error_string());
		return FALSE;
	}

	ANativeWindow_setBuffersGeometry(platform->native_window, 0, 0, format);

	actual_x = x_coord;
	actual_y = y_coord;
	actual_width = ANativeWindow_getWidth(platform->native_window);
	actual_height = ANativeWindow_getHeight(platform->native_window);

	GST_INFO("Window geometry: (%d, %d, %d, %d)", actual_x, actual_y, actual_width, actual_height);

	eglBindAPI(EGL_OPENGL_ES_API);

	platform->egl_context = eglCreateContext(platform->egl_display, config, EGL_NO_CONTEXT, ctx_attribs);
	platform->egl_surface = eglCreateWindowSurface(platform->egl_display, config, platform->native_window, NULL);

	eglMakeCurrent(platform->egl_display, platform->egl_surface, platform->egl_surface, platform->egl_context);

	if (platform->window_resized_event_cb != NULL)
		platform->window_resized_event_cb(platform, actual_width, actual_height, platform->user_context);
	else
		glViewport(actual_x, actual_y, actual_width, actual_height);

	return TRUE;
}
Exemplo n.º 11
0
GLUSvoid _glusOsPollEvents()
{
	int ident;
    int events;
    struct android_poll_source* androidPollSource;

    while ((ident = ALooper_pollAll( 0, NULL, &events, (void**)&androidPollSource)) >= 0)
    {
         if (androidPollSource != NULL)
         {
        	 androidPollSource->process(g_app, androidPollSource);
         }
    }

	int32_t orientation = AConfiguration_getOrientation (g_app->config);

	int32_t width;
	int32_t height;

	if (orientation == ACONFIGURATION_ORIENTATION_PORT)
	{
		width = ANativeWindow_getWidth(g_app->window);
		height = ANativeWindow_getHeight(g_app->window);
	}
	else
	{
		height = ANativeWindow_getWidth(g_app->window);
		width = ANativeWindow_getHeight(g_app->window);
	}

	if (width != g_width || height != g_height)
	{
		g_width = width;
		g_height = height;

		_glusWindowInternalReshape(g_width, g_height);
	}

    if (g_app->destroyRequested != 0 )
    {
    	_glusWindowInternalClose();
    }
}
Exemplo n.º 12
0
/**
  * Process the next main command.
  */
static void engine_handle_cmd(struct android_app* app, int32_t cmd) 
{
  struct engine* engine = (struct engine*)app->userData;
  switch (cmd) {
    case APP_CMD_SAVE_STATE:
      // The system has asked us to save our current state.  Do so.
      engine->app->savedState = malloc(sizeof(struct saved_state));
      *((struct saved_state*)engine->app->savedState) = engine->state;
      engine->app->savedStateSize = sizeof(struct saved_state);
      break;
    case APP_CMD_INIT_WINDOW:
      // The window is being shown, get it ready.
      if (engine->app->window != NULL) 
      {
        engine_init_display(engine);

        nuiAndroidBridge::androidResize(ANativeWindow_getWidth(app->window), ANativeWindow_getHeight(app->window));
        nuiButton* pButton = new nuiButton("Prout!");
//        pButton->SetPosition(nuiCenter);
        gpBridge->AddChild(pButton);

        engine_draw_frame(engine);
        engine->animating = 1;
      }
      break;
    case APP_CMD_TERM_WINDOW:
      // The window is being hidden or closed, clean it up.
      engine_term_display(engine);
      break;
    case APP_CMD_GAINED_FOCUS:
      // When our app gains focus, we start monitoring the accelerometer.
      if (engine->accelerometerSensor != NULL) 
      {
        ASensorEventQueue_enableSensor(engine->sensorEventQueue,
                                       engine->accelerometerSensor);
        // We'd like to get 60 events per second (in us).
        ASensorEventQueue_setEventRate(engine->sensorEventQueue,
                                       engine->accelerometerSensor, (1000L/60)*1000);
      }
      break;
    case APP_CMD_LOST_FOCUS:
      // When our app loses focus, we stop monitoring the accelerometer.
      // This is to avoid consuming battery while not being used.
      if (engine->accelerometerSensor != NULL) 
      {
        ASensorEventQueue_disableSensor(engine->sensorEventQueue,
                                        engine->accelerometerSensor);
      }
      // Also stop animating.
      engine->animating = 1;
      engine_draw_frame(engine);
      break;
  }
}
Exemplo n.º 13
0
/*
* IN_Android_EventToWindowCoordinates
*/
static bool IN_Android_EventToWindowCoordinates( const AInputEvent *event, size_t p, int *x, int *y )
{
	ANativeWindow *window = sys_android_app->window;

	if( !window )
		return false;

	*x = ( AMotionEvent_getX( event, p ) / ( float )ANativeWindow_getWidth( window ) ) * viddef.width;
	*y = ( AMotionEvent_getY( event, p ) / ( float )ANativeWindow_getHeight( window ) ) * viddef.height;
	return true;
}
Exemplo n.º 14
0
unsigned int VID_GetSysModes( vidmode_t *modes )
{
	ANativeWindow *window = sys_android_app->window;
	int windowWidth, windowHeight;
	int density;
	float densityStep;
	int i;

	if( !window )
		return 0;

	windowWidth = ANativeWindow_getWidth( window );
	windowHeight = ANativeWindow_getHeight( window );
	if( windowHeight > windowWidth )
	{
		// The window may be created in portrait orientation sometimes, for example, when launching in sleep mode.
		int tempWidth = windowWidth;
		windowWidth = windowHeight;
		windowHeight = tempWidth;
	}

	if( windowHeight <= 480 )
	{
		if( modes )
		{
			modes[0].width = windowWidth;
			modes[0].height = windowHeight;
		}
		return 1;
	}

	density = AConfiguration_getDensity( sys_android_app->config );
	if( !density )
		density = ACONFIGURATION_DENSITY_MEDIUM;
	densityStep = 1.0f - ( float )( density - 40 ) / ( float )density;

	for( i = 0; ; i++ )
	{
		float scale = 1.0f - densityStep * ( float )i;
		int width = windowWidth * scale;
		int height = windowHeight * scale;

		if( ( width <= 0 ) || ( height < 480 ) )
			break;

		if( modes )
		{
			modes[i].width = width;
			modes[i].height = height;
		}
	}

	return i;
}
Exemplo n.º 15
0
static int32_t MyHandleInput(struct android_app* app, AInputEvent* event)
{
	// Forward input events to Gainput
	gainput::InputManager* inputManager = (gainput::InputManager*)app->userData;
	static bool resSet = false;
	if (!resSet)
	{
		inputManager->SetDisplaySize(ANativeWindow_getWidth(app->window), ANativeWindow_getHeight(app->window));
		resSet = true;
	}
	return inputManager->HandleInput(event);
}
Exemplo n.º 16
0
EGLNativeWindowType cInterfaceEGLAndroid::InitializePlatform(EGLNativeWindowType host_window, EGLConfig config)
{
	EGLint format;
	eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &format);
	ANativeWindow_setBuffersGeometry(host_window, 0, 0, format);

	const int width = ANativeWindow_getWidth(host_window);
	const int height = ANativeWindow_getHeight(host_window);
	GLInterface->SetBackBufferDimensions(width, height);

	return host_window;
}
Exemplo n.º 17
0
//-----------------------------------------------------------------------------
OsWindow::OsWindow(uint32_t width, uint32_t height) :
	m_window(NULL),
	m_width(0),
	m_height(0),
	m_x(0),
	m_y(0)
{
	m_window = window;

	m_width = ANativeWindow_getWidth(m_window);
	m_height = ANativeWindow_getHeight(m_window);

    set_android_window(m_window);
}
Exemplo n.º 18
0
static void onContentRectChanged(ANativeActivity* activity, const ARect* rect)
{
    // Retrieve our activity states from the activity instance
    sf::priv::ActivityStates* states = sf::priv::retrieveStates(activity);
    sf::Lock lock(states->mutex);

    // Send an event to warn people about the window move/resize
    sf::Event event;
    event.type = sf::Event::Resized;
    event.size.width = ANativeWindow_getWidth(states->window);
    event.size.height = ANativeWindow_getHeight(states->window);

    states->forwardEvent(event);
}
Exemplo n.º 19
0
Arquivo: main.cpp Projeto: Nom1vk/VES
/**
 * Process the next main command.
 */
static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
    struct engine* engine = (struct engine*)app->userData;
    switch (cmd) {
        case APP_CMD_SAVE_STATE:
            // The system has asked us to save our current state.  Do so.
            engine->app->savedState = malloc(sizeof(struct saved_state));
            *((struct saved_state*)engine->app->savedState) = engine->state;
            engine->app->savedStateSize = sizeof(struct saved_state);
            break;
        case APP_CMD_INIT_WINDOW:
            if (app->window != NULL) {
                int32_t width = ANativeWindow_getWidth(app->window);
                int32_t height = ANativeWindow_getHeight(app->window);
                ANativeWindow_setBuffersGeometry(app->window, width, height, 1);
                LOGI("Window format is now %d",ANativeWindow_getFormat(app->window));
            }
            // The window is being shown, get it ready.
            if (engine->app->window != NULL) {
                engine_init_display(engine);
                engine_draw_frame(engine);
            }
            break;
        case APP_CMD_TERM_WINDOW:
            // The window is being hidden or closed, clean it up.
            engine_term_display(engine);
            break;
        case APP_CMD_GAINED_FOCUS:
            // When our app gains focus, we start monitoring the accelerometer.
            if (engine->accelerometerSensor != NULL) {
                ASensorEventQueue_enableSensor(engine->sensorEventQueue,
                        engine->accelerometerSensor);
                // We'd like to get 60 events per second (in us).
                ASensorEventQueue_setEventRate(engine->sensorEventQueue,
                        engine->accelerometerSensor, (1000L/60)*1000);
            }
            break;
        case APP_CMD_LOST_FOCUS:
            // When our app loses focus, we stop monitoring the accelerometer.
            // This is to avoid consuming battery while not being used.
            if (engine->accelerometerSensor != NULL) {
                ASensorEventQueue_disableSensor(engine->sensorEventQueue,
                        engine->accelerometerSensor);
            }
            // Also stop animating.
            engine->animating = 0;
            engine_draw_frame(engine);
            break;
    }
}
Exemplo n.º 20
0
//callback
extern void __android_handle_cmd(struct android_app* app, int32_t cmd) {
	switch(cmd){
		case APP_CMD_INIT_WINDOW: 
			setIsAndroidValidDevice(true);
			if(initAndroid) 
				initAndroid(app->userData);
		break;
		case APP_CMD_TERM_WINDOW: 
			if(termAndroid) 
				termAndroid(app->userData);
		break;
		case APP_CMD_PAUSE: 
			setIsAndroidValidDevice(false);
			if(pauseAndroid) 
				pauseAndroid(app->userData);
		break;
		case APP_CMD_WINDOW_RESIZED:
			if(windowResized){ 
				int32_t width = ANativeWindow_getWidth(getAndroidApp()->window);
				int32_t height = ANativeWindow_getHeight(getAndroidApp()->window);
				windowResized(app->userData,(int)width,(int)height);
			}
		break;
		case APP_CMD_RESUME: 
			if(resumeAndroid) 
				resumeAndroid(app->userData);
		break;  
		case APP_CMD_CONFIG_CHANGED:
			if(configChange) 
				configChange(app->userData);
        break;
		case APP_CMD_SAVE_STATE:			
			if(saveStateAndroid) 
				saveStateAndroid(app->userData);
        break;
		case APP_CMD_GAINED_FOCUS: 
			setEnableAccelerometer((1000L/60)*1000);
			if(getFocusAndroid) 
				getFocusAndroid(app->userData);
		break;  
		case APP_CMD_LOST_FOCUS: 
			setDisableAccelerometer();
			if(lostFocusAndroid) 
				lostFocusAndroid(app->userData);
		break;
		default:break;
	}
	
}
Exemplo n.º 21
0
	void processCommand(struct android_app* androidApp, int32_t cmd)
	{
		switch (cmd)
		{
			case APP_CMD_SAVE_STATE:
			{
				
			}
			break;
			case APP_CMD_INIT_WINDOW:
			{
				RIO_ASSERT(androidApp->window != NULL, "Android window is NULL");
				bgfx::androidSetWindow(app->window);
				// Push metrics here since Android does not trigger APP_CMD_WINDOW_RESIZED
				const int32_t width = ANativeWindow_getWidth(androidApp->window);
				const int32_t height = ANativeWindow_getHeight(androidApp->window);
				deviceEventQueue.pushResolutionEvent(width, height);
				if (!mainThread.getIsRunning())
				{
					mainThread.start(mainThreadFunction, &mainThreadArgs);
				}
			}
			break;
			case APP_CMD_TERM_WINDOW:
			{
				// The window is being hidden or closed, clean it up.
			}
			break;
			case APP_CMD_WINDOW_RESIZED:
			{
				// Not triggered by Android
			}
			break;
			case APP_CMD_GAINED_FOCUS:
			{
			}
			break;
			case APP_CMD_LOST_FOCUS:
			{
			}
			break;
			case APP_CMD_DESTROY:
			{
				deviceEventQueue.pushExitEvent();
			}
			break;
		}
	}
Exemplo n.º 22
0
	bool AndroidWindow::Create(const Parameters &params)
	{
		mDisplay = eglGetDisplay(mNativeDisplay);

		if (mDisplay == EGL_NO_DISPLAY)
		{
			LogError("Unable to get EGL display", 0);
			return false;
		}

		mParameters = params;
		mParameters.Width = ANativeWindow_getWidth(mNativeWindow);
		mParameters.Height = ANativeWindow_getHeight(mNativeWindow);

		return true;
	}
Exemplo n.º 23
0
void WindowImplAndroid::forwardEvent(const Event& event)
{
    ActivityStates* states = getActivity(NULL);

    if (event.type == Event::GainedFocus)
    {
        WindowImplAndroid::singleInstance->m_size.x = ANativeWindow_getWidth(states->window);
        WindowImplAndroid::singleInstance->m_size.y = ANativeWindow_getHeight(states->window);
        WindowImplAndroid::singleInstance->m_windowBeingCreated = true;
    }
    else if (event.type == Event::LostFocus)
    {
        WindowImplAndroid::singleInstance->m_windowBeingDestroyed = true;
    }

    WindowImplAndroid::singleInstance->pushEvent(event);
}
Exemplo n.º 24
0
void fgPlatformProcessSingleEvent ( void )
{
  static int32_t last_width = -1;
  static int32_t last_height = -1;

  /* When the screen is resized, the window handle still points to the
     old window until the next SwapBuffer, while it's crucial to set
     the size (onShape) correctly before the next onDisplay callback.
     Plus we don't know if the next SwapBuffer already occurred at the
     time we process the event (e.g. during onDisplay). */
  /* So we do the check each time rather than on event. */
  /* Interestingly, on a Samsung Galaxy S/PowerVR SGX540 GPU/Android
     2.3, that next SwapBuffer is fake (but still necessary to get the
     new size). */
  SFG_Window* window = fgDisplay.pDisplay.single_window;
  if (window != NULL && window->Window.Handle != NULL) {
    int32_t width = ANativeWindow_getWidth(window->Window.Handle);
    int32_t height = ANativeWindow_getHeight(window->Window.Handle);
    if (width != last_width || height != last_height) {
      last_width = width;
      last_height = height;
      LOGI("width=%d, height=%d", width, height);
      if( FETCH_WCB( *window, Reshape ) )
	INVOKE_WCB( *window, Reshape, ( width, height ) );
      else
	glViewport( 0, 0, width, height );
      glutPostRedisplay();
    }
  }

  /* Read pending event. */
  int ident;
  int events;
  struct android_poll_source* source;
  /* This is called "ProcessSingleEvent" but this means we'd only
     process ~60 (screen Hz) mouse events per second, plus other ports
     are processing all events already.  So let's process all pending
     events. */
  /* if ((ident=ALooper_pollOnce(0, NULL, &events, (void**)&source)) >= 0) { */
  while ((ident=ALooper_pollAll(0, NULL, &events, (void**)&source)) >= 0) {
    /* Process this event. */
    if (source != NULL) {
      source->process(source->app, source);
    }
  }
}
Exemplo n.º 25
0
void Renderer::AHandleResize(ANativeActivity * activity, ANativeWindow * window)
{
	int32_t w, h;
	w = ANativeWindow_getWidth(window);
	h = ANativeWindow_getHeight(window);

	Engine* engine = System::GetInstance()->GetEngineData();
	engine->width = w;
	engine->height = h;

	Renderer::GetInstance()->m_resizeNeeded = true;

	if (System::GetInstance()->GetCurrentScene() != nullptr)
		System::GetInstance()->GetCurrentScene()->FlushDimensions();

	LOGI("Renderer: Resize scheduled %dx%d", w, h);
}
int JNICALL prepareSurface(JNIEnv* env, jclass clazz, jobject surface) {
	ANativeWindow* wnd = ANativeWindow_fromSurface(env, surface);
	if (!wnd)
		return -1;
	int ret = -2;
	int w = ANativeWindow_getWidth(wnd), h = ANativeWindow_getHeight(wnd);
	if (w > 0 && h > 0) {
		barW = w >> 8;
		barH = h & (~1); //make the height always an even number
		if (barW < 1)
			barW = 1;
		const int size = barW << 8;
		invBarW = 1.0f / (float)barW;
		barBins = ((size > w) ? ((w < 256) ? (w & ~7) : 256) : 256);
		barWidthInPixels = barBins * barW;
		recreateVoice = 1;
		ret = ANativeWindow_setBuffersGeometry(wnd, barWidthInPixels, barH, WINDOW_FORMAT_RGB_565);
	}
Exemplo n.º 27
0
	void process_command(struct android_app* app, int32_t cmd)
	{
		switch (cmd)
		{
			case APP_CMD_SAVE_STATE:
			{
				break;
			}
			case APP_CMD_INIT_WINDOW:
			{
				CE_ASSERT(app->window != NULL, "Android window is NULL");
				bgfx::androidSetWindow(app->window);
				// Push metrics here since Android does not trigger APP_CMD_WINDOW_RESIZED
				const int32_t width = ANativeWindow_getWidth(app->window);
				const int32_t height = ANativeWindow_getHeight(app->window);
				_queue.push_metrics_event(0, 0, width, height);
				_main_thread.start(func, &_margs);
				break;
			}
			case APP_CMD_TERM_WINDOW:
			{
				// The window is being hidden or closed, clean it up.
				break;
			}
			case APP_CMD_WINDOW_RESIZED:
			{
				// Not triggered by Android
				break;
			}
			case APP_CMD_GAINED_FOCUS:
			{
				break;
			}
			case APP_CMD_LOST_FOCUS:
			{
				break;
			}
			case APP_CMD_DESTROY:
			{
				_queue.push_exit_event(0);
				break;
			}
		}
	}
Exemplo n.º 28
0
void FAndroidWindow::CalculateSurfaceSize(void* InWindow, int32_t& SurfaceWidth, int32_t& SurfaceHeight)
{
	check(InWindow);
	ANativeWindow* Window = (ANativeWindow*)InWindow;

	SurfaceWidth =  ANativeWindow_getWidth(Window);
	SurfaceHeight = ANativeWindow_getHeight(Window);

	// some phones gave it the other way (so, if swap if the app is landscape, but width < height)
	if (!GAndroidIsPortrait && SurfaceWidth < SurfaceHeight)
	{
		Swap(SurfaceWidth, SurfaceHeight);
	}

	// ensure the size is divisible by a specified amount
	const int DividableBy = 8;
	SurfaceWidth  = ((SurfaceWidth  + DividableBy - 1) / DividableBy) * DividableBy;
	SurfaceHeight = ((SurfaceHeight + DividableBy - 1) / DividableBy) * DividableBy;
}
Exemplo n.º 29
0
float VID_GetPixelRatio( void ) {
	static float invDensity;
	int height;
	int windowWidth, windowHeight;

	if( !sys_android_app->window || !viddef.height ) {
		return 1.0f;
	}

	if( !invDensity ) {
		float density = AConfiguration_getDensity( sys_android_app->config ) * ( 1.0f / ( float )ACONFIGURATION_DENSITY_MEDIUM );
		if( !density ) {
			density = 1.0f / ( float )ACONFIGURATION_DENSITY_MEDIUM;
		}
		invDensity = 1.0f / density;
	}

	windowWidth = ANativeWindow_getWidth( sys_android_app->window );
	windowHeight = ANativeWindow_getHeight( sys_android_app->window );
	return ( float )viddef.height / ( ( float )( min( windowWidth, windowHeight ) ) * invDensity );
}
Exemplo n.º 30
0
void Java_com_oculus_vrappframework_VrApp_nativeSurfaceCreated( JNIEnv *jni, jclass clazz,
		jlong appPtr, jobject surface )
{
	LOG( "%p nativeSurfaceCreated( %p )", (void *)appPtr, surface );

	OVR::AppLocal * appLocal = (OVR::AppLocal *)appPtr;

	ANativeWindow * newNativeWindow = ANativeWindow_fromSurface( jni, surface );
	if ( ANativeWindow_getWidth( newNativeWindow ) < ANativeWindow_getHeight( newNativeWindow ) )
	{
		// An app that is relaunched after pressing the home button gets an initial surface with
		// the wrong orientation even though android:screenOrientation="landscape" is set in the
		// manifest. The choreographer callback will also never be called for this surface because
		// the surface is immediately replaced with a new surface with the correct orientation.
		WARN( "        Surface not in landscape mode!" );
	}

	LOG( "    pendingNativeWindow = ANativeWindow_fromSurface( jni, surface )" );
	appLocal->pendingNativeWindow = newNativeWindow;
	appLocal->GetMessageQueue().SendPrintf( "surfaceCreated " );
}