Esempio n. 1
0
static EGLBoolean IJK_EGL_setSurfaceSize(IJK_EGL* egl, int width, int height)
{
    if (!IJK_EGL_isValid(egl))
        return EGL_FALSE;

#ifdef __ANDROID__
    egl->width  = IJK_EGL_getSurfaceWidth(egl);
    egl->height = IJK_EGL_getSurfaceHeight(egl);

    if (width != egl->width || height != egl->height) {
        int format = ANativeWindow_getFormat(egl->window);
        ALOGI("ANativeWindow_setBuffersGeometry(w=%d,h=%d) -> (w=%d,h=%d);",
            egl->width, egl->height,
            width, height);
        int ret = ANativeWindow_setBuffersGeometry(egl->window, width, height, format);
        if (ret) {
            ALOGE("[EGL] ANativeWindow_setBuffersGeometry() returned error %d", ret);
            return EGL_FALSE;
        }

        egl->width  = IJK_EGL_getSurfaceWidth(egl);
        egl->height = IJK_EGL_getSurfaceHeight(egl);
        return (egl->width && egl->height) ? EGL_TRUE : EGL_FALSE;
    }

    return EGL_TRUE;
#else
    // FIXME: other platform?
#endif
    return EGL_FALSE;
}
Esempio n. 2
0
File: main.cpp Progetto: 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;
    }
}
/**
 * Initialize an context for the current display.
 */
static int engine_init_display(struct engine* engine)
{
    int w, h, f, s, b;
    ps_color_format fmt;    

    ps_initialize();

    w = ANativeWindow_getWidth(engine->app->window);
    h = ANativeWindow_getHeight(engine->app->window);
    f = ANativeWindow_getFormat(engine->app->window);

    
    if (f == WINDOW_FORMAT_RGBA_8888 || f == WINDOW_FORMAT_RGBX_8888) {
        b = 4;
        fmt = COLOR_FORMAT_ARGB;
    } else {
        b = 2;
        fmt = COLOR_FORMAT_RGB565;
    }

    ANativeWindow_Buffer buffer;
    ANativeWindow_lock(engine->app->window, &buffer, 0);
    s = buffer.stride * b;
    // create canvas with fake buffer bits !
    engine->canvas = ps_canvas_create_with_data((uint8_t*)buffer.bits, fmt, w, h, s);
    engine->context = ps_context_create(engine->canvas, 0);
    init_context(engine->context, engine->canvas, (unsigned char*)buffer.bits);    
    set_image_data(selt2565.bits, COLOR_FORMAT_RGB565, selt2565.width, selt2565.height, selt2565.pitch);
    set_pattern_data(pat565.bits, COLOR_FORMAT_RGB565, pat565.width, pat565.height, pat565.pitch);
   // ps_scale(engine->context, 4, 4); // zoom 

    engine->width = w;
    engine->height = h;
    engine->bpp = b;
    engine->fmt = fmt;
    ANativeWindow_unlockAndPost(engine->app->window);

    return 0;

}
Esempio n. 4
0
void SwViewport::PrepareToDraw() {

    NativeWindow = ANativeWindow_fromSurface(Jni, (jobject)Window);

    VERBOSE("Got native window %p", NativeWindow);
    int width = ANativeWindow_getWidth(NativeWindow);
    int height = ANativeWindow_getHeight(NativeWindow);
    int format = ANativeWindow_getFormat(NativeWindow);
    VERBOSE("Size: %ix%i, Format: %i", width, height, format);
    ANativeWindow_Buffer buffer;
    ARect rc;
    rc.left = 0;
    rc.top =0;
    rc.right = width;
    rc.bottom = height;
    buffer.bits = nullptr;
    ANativeWindow_lock(NativeWindow, &buffer, &rc);
    VERBOSE("Locked data: %p", buffer.bits);
    SkColorType color = SKIA_COLOR_FORMAT;
    int stride  = buffer.stride;

    if(format == WINDOW_FORMAT_RGB_565)
    {
        color = kRGB_565_SkColorType;
        stride*=2;
    }
    else
        stride *= 4;
    VERBOSE("Using color format: %i, stride: %i", color, stride);



    Surface.reset(SkSurface::NewRasterDirect(SkImageInfo::Make(width, height, color, kOpaque_SkAlphaType),
                  buffer.bits, stride));
    VERBOSE("Surface: %p", Surface.get());
}
Esempio n. 5
0
bool
EGLRenderer::Init()
{
	std::cout << "Init" << std::endl;
    if (_display == EGL_NO_DISPLAY)
    {
		std::cout << "eglGetDisplay" << std::endl;
		_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
		if (!_display)
			return false;
		std::cout << "eglInitialize" << std::endl;
		EGLBoolean res = eglInitialize(_display, NULL, NULL);
		if (!res)
			return false;
		const EGLint RGBX_8888_ATTRIBS[] =
		{
			EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_SURFACE_TYPE,
			EGL_WINDOW_BIT, EGL_BLUE_SIZE, 8, EGL_GREEN_SIZE, 8,
			EGL_RED_SIZE, 8, EGL_DEPTH_SIZE, 8, EGL_NONE
		};
		
		const EGLint RGB_565_ATTRIBS[] =
		{
			EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_SURFACE_TYPE,
			EGL_WINDOW_BIT, EGL_BLUE_SIZE, 5, EGL_GREEN_SIZE, 6,
			EGL_RED_SIZE, 5, EGL_DEPTH_SIZE, 8, EGL_NONE
		};
		
		const EGLint* attribList;
		
		Android& android = Android::GetSingleton();
		int windowFormat = ANativeWindow_getFormat(android.GetAppState()->window);
		if ((windowFormat == WINDOW_FORMAT_RGBA_8888) || (windowFormat == WINDOW_FORMAT_RGBX_8888))
		{
			attribList = RGBX_8888_ATTRIBS;
		}
		else
		{
			attribList = RGB_565_ATTRIBS;
		}
		EGLConfig config;
		EGLint numConfigs;
		std::cout << "eglChooseConfig" << std::endl;
		res = eglChooseConfig(_display, attribList, &config, 1, &numConfigs);
		if (!res)
			return false;
		
		EGLint format;
		std::cout << "eglGetConfigAttrib" << std::endl;
		res = eglGetConfigAttrib(_display, config, EGL_NATIVE_VISUAL_ID, &format);
		if (!res)
			return false;
		std::cout << "ANativeWindow_setBuffersGeometry" << std::endl;
		int32_t setBufRes = ANativeWindow_setBuffersGeometry(android.GetAppState()->window, 0, 0, format);
		if (setBufRes != 0)
			return false;
		
		EGLNativeWindowType windowType;
		std::cout << "eglCreateWindowSurface" << std::endl;
		_renderSurface = eglCreateWindowSurface(_display, config, android.GetAppState()->window, NULL);
		if (_renderSurface == EGL_NO_SURFACE)
			return false;
		EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
		std::cout << "eglCreateContext" << std::endl;
		_context = eglCreateContext(_display, config, EGL_NO_CONTEXT, contextAttribs);
		if (_context == EGL_NO_CONTEXT)
			return false;
		std::cout << "eglMakeCurrent" << std::endl;
		res = eglMakeCurrent(_display, _renderSurface, _renderSurface, _context);
		if (!res)
			return false;
		EGLint temp = _width;
		std::cout << "eglQuerySurface EGL_WIDTH" << std::endl;
		res = eglQuerySurface(_display, _renderSurface, EGL_WIDTH, &temp);
		if (!res)
			return false;
		temp = _height;
		std::cout << "eglQuerySurface EGL_HEIGHT" << std::endl;
		res = eglQuerySurface(_display, _renderSurface, EGL_HEIGHT, &temp);
		if (!res)
			return false;
		
		_initialized = true;
		std::cout << "_initialized" << std::endl;
    }
	std::cout << "EndInit" << std::endl;
}
Esempio n. 6
0
int SDL_Android_NativeWindow_display_l(ANativeWindow *native_window, SDL_VoutOverlay *overlay)
{
    int retval;

    if (!native_window)
        return -1;

    if (!overlay) {
        ALOGE("SDL_Android_NativeWindow_display_l: NULL overlay");
        return -1;
    }

    if (overlay->w <= 0 || overlay->h <= 0) {
        ALOGE("SDL_Android_NativeWindow_display_l: invalid overlay dimensions(%d, %d)", overlay->w, overlay->h);
        return -1;
    }

    int curr_w = ANativeWindow_getWidth(native_window);
    int curr_h = ANativeWindow_getHeight(native_window);
    int curr_format = ANativeWindow_getFormat(native_window);
    int buff_w = CAPALIGN(overlay->w, 2);
    int buff_h = CAPALIGN(overlay->h, 2);

    AndroidHalFourccDescriptor *overlayDesc = native_window_get_desc(overlay->format);
    if (!overlayDesc) {
        ALOGE("SDL_Android_NativeWindow_display_l: unknown overlay format: %d", overlay->format);
        return -1;
    }

    AndroidHalFourccDescriptor *voutDesc = native_window_get_desc(curr_format);
    if (!voutDesc || voutDesc->hal_format != overlayDesc->hal_format) {
        ALOGD("ANativeWindow_setBuffersGeometry: w=%d, h=%d, f=%.4s(0x%x) => w=%d, h=%d, f=%.4s(0x%x)",
            curr_w, curr_h, (char*) &curr_format, curr_format,
            buff_w, buff_h, (char*) &overlay->format, overlay->format);
        retval = ANativeWindow_setBuffersGeometry(native_window, buff_w, buff_h, overlayDesc->hal_format);
        if (retval < 0) {
            ALOGE("SDL_Android_NativeWindow_display_l: ANativeWindow_setBuffersGeometry: failed %d", retval);
            return retval;
        }

        if (!voutDesc) {
            ALOGE("SDL_Android_NativeWindow_display_l: unknown hal format %d", curr_format);
            return -1;
        }
    }

    ANativeWindow_Buffer out_buffer;
    retval = ANativeWindow_lock(native_window, &out_buffer, NULL);
    if (retval < 0) {
        ALOGE("SDL_Android_NativeWindow_display_l: ANativeWindow_lock: failed %d", retval);
        return retval;
    }

    if (out_buffer.width != buff_w || out_buffer.height != buff_h) {
        ALOGE("unexpected native window buffer (%p)(w:%d, h:%d, fmt:'%.4s'0x%x), expecting (w:%d, h:%d, fmt:'%.4s'0x%x)",
            native_window,
            out_buffer.width, out_buffer.height, (char*)&out_buffer.format, out_buffer.format,
            buff_w, buff_h, (char*)&overlay->format, overlay->format);
        // TODO: 8 set all black
        ANativeWindow_unlockAndPost(native_window);
        ANativeWindow_setBuffersGeometry(native_window, buff_w, buff_h, overlayDesc->hal_format);
        return -1;
    }

    int render_ret = voutDesc->render(&out_buffer, overlay);
    if (render_ret < 0) {
        // TODO: 8 set all black
        // return after unlock image;
    }

    retval = ANativeWindow_unlockAndPost(native_window);
    if (retval < 0) {
        ALOGE("SDL_Android_NativeWindow_display_l: ANativeWindow_unlockAndPost: failed %d", retval);
        return retval;
    }

    return render_ret;
}
static DFBResult
InitLocal( AndroidData *android )
{
     /*
      * Here specify the attributes of the desired configuration.
      * Below, we select an EGLConfig with at least 8 bits per color
      * component compatible with on-screen windows
      */
     const EGLint attribs[] = {
             EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
             EGL_BLUE_SIZE, 8,
             EGL_GREEN_SIZE, 8,
             EGL_RED_SIZE, 8,
             EGL_ALPHA_SIZE, 8,
             EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
             EGL_NATIVE_VISUAL_ID, HAL_PIXEL_FORMAT_RGBA_8888,    // DSPF_ARGB
             EGL_NONE
     };

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

     EGLint w, h, dummy, format;
     EGLint numConfigs;
     EGLConfig config;
     EGLSurface surface;
     EGLContext context;

     EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);

     eglInitialize(display, 0, 0);

     /* Here, the application chooses the configuration it desires. In this
      * sample, we have a very simplified selection process, where we pick
      * the first EGLConfig that matches our criteria */
     eglChooseConfig(display, attribs, &config, 1, &numConfigs);

     /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is
      * guaranteed to be accepted by ANativeWindow_setBuffersGeometry().
      * As soon as we picked a EGLConfig, we can safely reconfigure the
      * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */
     eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);

     ANativeWindow_setBuffersGeometry( native_data.app->window, 0, 0, format);

//     ANativeActivity_setWindowFlags( native_data.app->window, AWINDOW_FLAG_FULLSCREEN | AWINDOW_FLAG_KEEP_SCREEN_ON , 0 );

     surface = eglCreateWindowSurface(display, config, native_data.app->window, NULL);
     context = eglCreateContext(display, config, NULL, ctx_attribs);

     if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) {
         LOGW("Unable to eglMakeCurrent");
         return -1;
     }

     eglQuerySurface(display, surface, EGL_WIDTH, &w);
     eglQuerySurface(display, surface, EGL_HEIGHT, &h);

     android->dpy = display;
     android->ctx = context;
     android->surface = surface;
     android->shared->screen_size.w = w;
     android->shared->screen_size.h = h;     

     if (strstr(glGetString(GL_RENDERER),"SGX"))
          android->shared->native_pixelformat = HAL_PIXEL_FORMAT_RGBA_8888; //ANativeWindow_getFormat(native_data.app->window);
     else
          android->shared->native_pixelformat = ANativeWindow_getFormat(native_data.app->window);

     // Initialize GL state.
//     glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
     glEnable(GL_CULL_FACE);
//     glShadeModel(GL_SMOOTH);
     glDisable(GL_DEPTH_TEST);



     // Just fill the screen with a color.
     glClearColor( .5, .5, .5, 1 );
     glClear( GL_COLOR_BUFFER_BIT );

     eglSwapBuffers( android->dpy, android->surface );

     return DFB_OK;
}
		static void onSurfaceChanged(JNIEnv * env, jclass jclazz, jobject surface, jint pixelFormat, jint width, jint height)
		{
			ANativeWindow* window =  ANativeWindow_fromSurface(env, surface);
			int nativePixelFormat = ANativeWindow_getFormat(window);
			jobViewer->onSurfaceChanged(window, nativePixelFormat, width, height);
		}
Esempio n. 9
0
static void * decode_and_render(FFmpegInfo *pInfo, int nframe)
{
    if (!pInfo) return NULL;

    LOGI("lock native window ...");
    ANativeWindow_acquire(pInfo->window);

    /* acquire window's information: width/height/format */
    AVPixelFormat pix_fmt;
    int win_format = ANativeWindow_getFormat(pInfo->window);
    int win_width = ANativeWindow_getWidth(pInfo->window);
    int win_height = ANativeWindow_getHeight(pInfo->window);
    if (win_format == WINDOW_FORMAT_RGBA_8888)
        pix_fmt = AV_PIX_FMT_RGBA;
    else if (win_format == WINDOW_FORMAT_RGB_565)
        pix_fmt = AV_PIX_FMT_RGB565;
    else {
        LOGE("unsupport window format");
        ANativeWindow_release(pInfo->window);
        return NULL;
    }

    LOGI("alloc decoded buffer w-%d, h-%d, f-%d", win_width, win_height, win_format);
    if (!pInfo->win_data || 
        pInfo->win_width != win_width || 
        pInfo->win_height != win_height || 
        pInfo->win_format != win_format ) {

        /* release old data */
        if (pInfo->win_data) {
            av_free(pInfo->win_data[0]);
            pInfo->win_data[0] = {NULL};
        }

        /* alloc decoded buffer */
        int ret = av_image_alloc(pInfo->win_data, pInfo->win_linesize,
                             win_width, win_height, pix_fmt, 1);
        if (ret < 0) {
            LOGE("Could not allocate raw video buffer");            
            ANativeWindow_release(pInfo->window);
            return NULL;
        }
        pInfo->win_bufsize = ret;
        pInfo->win_format = win_format;
        pInfo->win_width = win_width;
        pInfo->win_height = win_height;
    }

    /* read video frame and decode */
    int num_frames = 0;
    LOGI("read video frame and decode");
    pInfo->video_timestamp = -1;
    av_seek_frame(pInfo->fmt_ctx, pInfo->video_stream_idx, pInfo->video_timestamp, AVSEEK_FLAG_BACKWARD);

    pInfo->video_timestamp = 0;
    while (av_read_frame(pInfo->fmt_ctx, &pInfo->pkt) >= 0) {
        if (num_frames >= nframe) {
            break;
        }

        AVPacket orig_pkt = pInfo->pkt;
        /* process video stream */
        if (pInfo->pkt.stream_index == pInfo->video_stream_idx) {
            num_frames ++;
            AVCodecContext* dec_ctx = pInfo->video_dec_ctx;
            AVFrame* frame = pInfo->frame;
            pInfo->video_timestamp = frame->pts;
            LOGI("pkt.flags = %d, frame.pts=%d", pInfo->pkt.flags, frame->pts);

            /* decode video */
            int got_frame = 0;
            int ret = avcodec_decode_video2(dec_ctx, frame, &got_frame, &pInfo->pkt);
            if (ret < 0) {
                LOGE("Error decoding video frame");
                break;
            }

            /* decode success */
            if (got_frame) {
                /* copy video data from aligned buffer into unaligned */
                av_image_copy(pInfo->video_dst_data, pInfo->video_dst_linesize, 
                              (const uint8_t **)(frame->data), frame->linesize,
                              dec_ctx->pix_fmt, dec_ctx->width, dec_ctx->height);

                /* convert to required format */
                int ret = yuv2rgb(dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt, 
                                  pInfo->video_dst_linesize, pInfo->video_dst_data,
                                  pInfo->win_width, pInfo->win_height, pix_fmt, 
                                  pInfo->win_linesize, pInfo->win_data);

                /* do paint */
                LOGI("do paint on surface, ret=%d, decoded w=%d, h=%d, fmt=from %d to %d", ret, 
                      dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt, pix_fmt);
                struct ANativeWindow_Buffer data;
                ANativeWindow_lock(pInfo->window, &data, NULL);
                memcpy(data.bits, pInfo->win_data[0], pInfo->win_bufsize);
                ANativeWindow_unlockAndPost(pInfo->window);
            }

            /* seek to next key frame */
            av_seek_frame(pInfo->fmt_ctx, pInfo->video_stream_idx, pInfo->video_timestamp, AVSEEK_FLAG_BACKWARD);
        }
        av_free_packet(&orig_pkt);
    }
    //av_free_packet(&pkt);

    ANativeWindow_release(pInfo->window);
    LOGI("decode OK, number=%d", num_frames);
    return NULL;
}
	void Java_com_test_surfaceview_TestNative_Draw(JNIEnv* env,jobject obj,jstring jstr)
	{
		LOGI("Java_com_test_surfaceview_TestNative_Draw");
		char* path = jstring2string(env,jstr);
		if(g_assetManager == NULL)
		{
			LOGE("Get AAssetManager ERROR!");
		}
		 AAsset* asset = AAssetManager_open(g_assetManager, path,AASSET_MODE_UNKNOWN);
		 free(path);
		 path = NULL;
		 if(asset == NULL)
			 return ;
		 int  bufferLen = AAsset_getLength(asset);
		 unsigned char* buffer = (unsigned char*)malloc(bufferLen+1);
		 buffer[bufferLen] = 0;
		 int numBytesRead = AAsset_read(asset, buffer, bufferLen);
		 g_buffer = buffer;
		 g_bufferLen = bufferLen;
		 AAsset_close(asset);
		 LOGI("g_bufferLen=%d",g_bufferLen);
		BITMAPFILEHEADER  filehead;
		BITMAPINFOHEADER  head;
		memcpy(&filehead,g_buffer,sizeof(BITMAPFILEHEADER));
		memcpy(&head,g_buffer+sizeof(BITMAPFILEHEADER),sizeof(BITMAPINFOHEADER));
		if(filehead.bfType != 0x4D42)
		{
			free(buffer);
			buffer=NULL;
			return ;
		}
		ANativeWindow_setBuffersGeometry(g_nativeWindow,head.biWidth,head.biHeight,WINDOW_FORMAT_RGB_565);
		g_nWidth = ANativeWindow_getWidth(g_nativeWindow);
		g_nHeight = ANativeWindow_getHeight(g_nativeWindow);
		int nfomat  = ANativeWindow_getFormat(g_nativeWindow);
		LOGI("bfOffBits=%d,g_nWidth=%d,g_nHeight=%d,nfomat=%d",filehead.bfOffBits,g_nWidth,g_nHeight,nfomat);
		ANativeWindow_Buffer windowBuffer;
		if(ANativeWindow_lock(g_nativeWindow,&windowBuffer,NULL) <0 )
		{
			LOGE("cannot lock window");
		}
		else
		{
//			unsigned char* tmp =(unsigned char*)( g_buffer+filehead.bfOffBits);
//			unsigned int* data =(unsigned int*) windowBuffer.bits;
//			for(int i=0;i<head.biHeight;i++)
//			{
//				for(int j=0;j<head.biWidth;j++)
//				{
//					int nFlag = 0;
//					memcpy(&nFlag,tmp+(head.biWidth*i+j)*3,3);
//					data[i*windowBuffer.stride+j] = nFlag;
//				}
//				//memcpy(data+i*buffer.stride*2,tmp+(600-i-1)*800*2,800*2);
//			}
			unsigned short* data =(unsigned short*) windowBuffer.bits;
			unsigned char* tmp = (unsigned char*)(g_buffer+filehead.bfOffBits);
			LOGI("%d,%d,%d",head.biWidth,head.biHeight,head.biBitCount);
			int offsize = head.biBitCount/8;
			int lineByte=(head.biWidth* head.biBitCount/8+3)/4*4;
			LOGI("lineByte=%d",lineByte);
			for(int i=0;i<head.biHeight;i++)
			{
				for(int j=0;j<head.biWidth;j++,tmp+=offsize)
				{
					if(offsize>2)
						data[(head.biHeight-i-1)*windowBuffer.stride+j] = RGB565(*(tmp+2),*(tmp+1),*(tmp));
					else
						memcpy(&data[(head.biHeight-i-1)*windowBuffer.stride+j],tmp,2);
				}
				tmp+=(lineByte-offsize*head.biWidth);
			}
			LOGI("buffer.stride=%d,buffer.format=%d",windowBuffer.stride,windowBuffer.format);
			ANativeWindow_unlockAndPost(g_nativeWindow);
		}
		free(buffer);
		buffer=NULL;
		LOGI("Java_com_test_surfaceview_TestNative_Draw END!");
	}
Esempio n. 11
0
bool DisplayVkAndroid::isValidNativeWindow(EGLNativeWindowType window) const
{
    return (ANativeWindow_getFormat(window) >= 0);
}
Esempio n. 12
0
void EGLRenderer::Init()
{
    LOGD("EGLRenderer Init() begin");

	if (m_pState->window == NULL)
	{
		LOGD("app_state->window are null, EGLRenderer can not Init() now");
		return;
	}

    LOGD("Init EGL begin");
	if (m_display == EGL_NO_DISPLAY)
	{
		m_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
		assert(m_display!= EGL_NO_DISPLAY);

        EGLint majorEGLVersion, minorEGLVersion;
		EGLBoolean res = eglInitialize(m_display, &majorEGLVersion, &minorEGLVersion);
		assert(res);
        LOGD("EGL Major Version is %d", majorEGLVersion);
        LOGD("EGL Minor Version is %d", minorEGLVersion);

        EGLint OGLESVersionToken;

        #if defined(USE_GLES3)
            #if 0
            OGLESVersionToken = EGL_OPENGL_ES3_BIT_KHR;
            // Don't use EGL_OPENGL_ES3_BIT_KHR, since we don't have corresponding header files for EGL 1.4
            #endif

            // Use a magic number which comes from the spec of OGL ES 3.0
            static const unsigned int EGL_OPENGL_ES3_BIT_KHR = 0x0040;
            OGLESVersionToken = EGL_OPENGL_ES3_BIT_KHR;

        #elif defined(USE_GLES2)
            OGLESVersionToken = EGL_OPENGL_ES2_BIT;
        #elif defined(USE_GLES1)
            OGLESVersionToken = EGL_OPENGL_ES_API;
        #else
            OGLESVersionToken = EGL_OPENGL_ES2_BIT;
        #endif

		const EGLint RGBX_8888_ATTRIBS[]=
		{
				EGL_RENDERABLE_TYPE, OGLESVersionToken,
				EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
				EGL_RED_SIZE,	8,
				EGL_GREEN_SIZE, 8,
				EGL_BLUE_SIZE,  8,
				EGL_DEPTH_SIZE,	8,
				EGL_NONE
		};
		const EGLint RGB_565_ATTRIBS[]=
		{
				EGL_RENDERABLE_TYPE, OGLESVersionToken,
				EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
				EGL_RED_SIZE, 5,
				EGL_GREEN_SIZE, 6,
				EGL_BLUE_SIZE, 5,
				EGL_DEPTH_SIZE, 8,
				EGL_NONE
		};

		const EGLint* attribList;

		int windowFormat = ANativeWindow_getFormat(m_pState->window);
		if ((windowFormat == WINDOW_FORMAT_RGBA_8888) || (windowFormat == WINDOW_FORMAT_RGBX_8888))
		{
			attribList = RGBX_8888_ATTRIBS;
		}
		else
		{
			attribList = RGB_565_ATTRIBS;
		}

		EGLConfig config;
		EGLint numConfigs;
		res = eglChooseConfig(m_display, attribList, &config, 1, &numConfigs);
		assert(res);

		EGLint format;
		res = eglGetConfigAttrib(m_display, config, EGL_NATIVE_VISUAL_ID, &format);
		assert(res);

        EGLint max_swap_interval;
        res = eglGetConfigAttrib(m_display, config, EGL_MAX_SWAP_INTERVAL, &max_swap_interval);
        assert(res);

        EGLint min_swap_interval;
        res = eglGetConfigAttrib(m_display, config, EGL_MIN_SWAP_INTERVAL, &min_swap_interval);
        assert(res);

        LOGD("EGL Max Swap Interval is %d", max_swap_interval);
        LOGD("EGL Min Swap Interval is %d", min_swap_interval);

		int32_t setBufRes = ANativeWindow_setBuffersGeometry(m_pState->window, 0, 0, format);
		assert(setBufRes == 0);

		EGLNativeWindowType windowType;
		m_renderSurface = eglCreateWindowSurface(m_display, config, m_pState->window, NULL);
		assert(m_renderSurface != EGL_NO_SURFACE);
		LOGD("EGLRenderer eglCreateWindowSurface() success");

        EGLint OGLESVersion;

        #if defined(USE_GLES3)
            OGLESVersion = 3;
        #elif defined(USE_GLES2)
            OGLESVersion = 2;
        #elif defined(USE_GLES1)
            OGLESVersion = 1;
        #else
            OGLESVersion = 2;
        #endif

		EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, OGLESVersion, EGL_NONE };
		m_context = eglCreateContext(m_display, config, EGL_NO_CONTEXT, contextAttribs);
		assert(m_context != EGL_NO_CONTEXT);
		LOGD("EGLRenderer eglCreateContext() success");

		res = eglMakeCurrent(m_display, m_renderSurface, m_renderSurface, m_context);
		assert(res);
		LOGD("EGLRenderer eglMakeCurrent() success");

        const GLubyte* glVendor;
        const GLubyte* glRenderer;
        const GLubyte* glVersion;

        glVendor = glGetString(GL_VENDOR);
        glRenderer = glGetString(GL_RENDERER);
        glVersion = glGetString(GL_VERSION);

        LOGD("The current GL_VENDOR: %s", glVendor);
        LOGD("The current GL_RENDERER: %s", glRenderer);
        LOGD("The current GL_VERSION: %s", glVersion);

        #if defined(USE_GLES3)
            GLint glMajorVersion, glMinorVersion;
            glGetIntegerv(GL_MAJOR_VERSION, &glMajorVersion);
            glGetIntegerv(GL_MINOR_VERSION, &glMinorVersion);
            LOGD("These query methods only available in OGL ES 3:");
            LOGD("    - The current OGL Context support OGL Major_Version: %d", glMajorVersion);
            LOGD("    - The current OGL Context support OGL Minor_Version: %d", glMinorVersion);
        #endif

        res = eglQuerySurface(m_display, m_renderSurface, EGL_WIDTH, &m_width);
        assert(res);
        LOGD("EGLRenderer eglQuerySurface() success, m_width is %d", m_width);

        res = eglQuerySurface(m_display, m_renderSurface, EGL_HEIGHT, &m_height);
        assert(res);
        LOGD("EGLRenderer eglQuerySurface() success, m_height is %d", m_height);

        // try to disable vsync
        res = eglSwapInterval(m_display, 0);
        assert(res);
        LOGD("EGLRenderer eglSwapInterval to disable vsync success");
	}
    LOGD("Init EGL end");

    LOGD("super class Renderer::Init() begin");
    Renderer::Init();
    LOGD("super class Renderer::Init() end");

	LOGD("EGLRenderer Init() end");
}