am f5c108a8: Merge "opengl renderer: create rendering subwindow"

* commit 'f5c108a877b4396d86e9117c8273a72df6d8bf26':
  opengl renderer: create rendering subwindow
This commit is contained in:
David Turner
2011-07-06 07:30:46 -07:00
committed by Android Git Automerger
10 changed files with 223 additions and 5 deletions

View File

@@ -31,6 +31,10 @@ typedef HWND FBNativeWindowType;
typedef Window FBNativeWindowType; typedef Window FBNativeWindowType;
#elif defined(__APPLE__)
typedef void* FBNativeWindowType;
#else #else
#warning "Unsupported platform" #warning "Unsupported platform"
#endif #endif

View File

@@ -7,7 +7,24 @@ $(call emugl-begin-host-shared-library,libOpenglRender)
$(call emugl-import,libGLESv1_dec libGLESv2_dec lib_renderControl_dec libOpenglCodecCommon libOpenglOsUtils) $(call emugl-import,libGLESv1_dec libGLESv2_dec lib_renderControl_dec libOpenglCodecCommon libOpenglOsUtils)
OS_SRCS:=
ifeq ($(HOST_OS),linux)
OS_SRCS = NativeLinuxSubWindow.cpp
LOCAL_LDLIBS += -lX11
endif
ifeq ($(HOST_OS),darwin)
OS_SRCS = NativeMacSubWindow.m
LOCAL_LDLIBS += -Wl,-framework,AppKit
endif
ifeq ($(HOST_OS),windows)
OS_SRCS = NativeWindowsSubWindow.cpp
endif
LOCAL_SRC_FILES := \ LOCAL_SRC_FILES := \
$(OS_SRCS) \
render_api.cpp \ render_api.cpp \
ColorBuffer.cpp \ ColorBuffer.cpp \
EGLDispatch.cpp \ EGLDispatch.cpp \

View File

@@ -14,6 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include "FrameBuffer.h" #include "FrameBuffer.h"
#include "NativeSubWindow.h"
#include "FBConfig.h" #include "FBConfig.h"
#include "EGLDispatch.h" #include "EGLDispatch.h"
#include "GLDispatch.h" #include "GLDispatch.h"
@@ -84,6 +85,16 @@ static const char *getGLES2ExtensionString(EGLDisplay p_dpy,
} }
#endif #endif
void FrameBuffer::finalize(){
if(s_theFrameBuffer){
s_egl.eglMakeCurrent(s_theFrameBuffer->m_eglDisplay, NULL, NULL, NULL);
s_egl.eglDestroySurface(s_theFrameBuffer->m_eglDisplay,s_theFrameBuffer->m_eglSurface);
s_egl.eglDestroyContext(s_theFrameBuffer->m_eglDisplay,s_theFrameBuffer->m_eglContext);
delete s_theFrameBuffer;
s_theFrameBuffer = NULL;
}
}
bool FrameBuffer::initialize(FBNativeWindowType p_window, bool FrameBuffer::initialize(FBNativeWindowType p_window,
int p_x, int p_y, int p_x, int p_y,
int p_width, int p_height) int p_width, int p_height)
@@ -197,16 +208,16 @@ bool FrameBuffer::initialize(FBNativeWindowType p_window,
return false; return false;
} }
#if defined(__linux__) || defined(_WIN32) || defined(__VC32__) && !defined(__CYGWIN__) EGLNativeDisplayType dpy;
fb->m_subWin = createSubWindow(p_window,&fb->m_subWinDisplay,p_x,p_y,p_width,p_height);
fb->m_eglSurface = s_egl.eglCreateWindowSurface(fb->m_eglDisplay, eglConfig, fb->m_eglSurface = s_egl.eglCreateWindowSurface(fb->m_eglDisplay, eglConfig,
(EGLNativeWindowType)p_window, fb->m_subWin,
NULL); NULL);
if (fb->m_eglSurface == EGL_NO_SURFACE) { if (fb->m_eglSurface == EGL_NO_SURFACE) {
ERR("Failed to create surface\n"); ERR("Failed to create surface\n");
delete fb; delete fb;
return false; return false;
} }
#endif
GLint glContextAttribs[] = { GLint glContextAttribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 1, EGL_CONTEXT_CLIENT_VERSION, 1,
@@ -333,7 +344,9 @@ FrameBuffer::FrameBuffer(int p_x, int p_y, int p_width, int p_height) :
m_eglContext(EGL_NO_CONTEXT), m_eglContext(EGL_NO_CONTEXT),
m_prevContext(EGL_NO_CONTEXT), m_prevContext(EGL_NO_CONTEXT),
m_prevReadSurf(EGL_NO_SURFACE), m_prevReadSurf(EGL_NO_SURFACE),
m_prevDrawSurf(EGL_NO_SURFACE) m_prevDrawSurf(EGL_NO_SURFACE),
m_subWin(NULL),
m_subWinDisplay(NULL)
{ {
} }

View File

@@ -51,6 +51,7 @@ public:
static bool initialize(FBNativeWindowType p_window, static bool initialize(FBNativeWindowType p_window,
int x, int y, int x, int y,
int width, int height); int width, int height);
static void finalize();
static FrameBuffer *getFB() { return s_theFrameBuffer; } static FrameBuffer *getFB() { return s_theFrameBuffer; }
const FrameBufferCaps &getCaps() const { return m_caps; } const FrameBufferCaps &getCaps() const { return m_caps; }
@@ -107,5 +108,7 @@ private:
EGLContext m_prevContext; EGLContext m_prevContext;
EGLSurface m_prevReadSurf; EGLSurface m_prevReadSurf;
EGLSurface m_prevDrawSurf; EGLSurface m_prevDrawSurf;
EGLNativeWindowType m_subWin;
EGLNativeDisplayType m_subWinDisplay;
}; };
#endif #endif

View File

@@ -0,0 +1,31 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "NativeSubWindow.h"
EGLNativeWindowType createSubWindow(FBNativeWindowType p_window,
EGLNativeDisplayType* display_out,
int x, int y,int width, int height){
*display_out = XOpenDisplay(NULL);
Window win = XCreateWindow(*display_out,p_window,x,y, width,height,0,CopyFromParent,CopyFromParent,CopyFromParent,0,NULL);
XMapWindow(*display_out,win);
XSync(*display_out,False);
return win;
}
void destroySubWindow(EGLNativeDisplayType dis,EGLNativeWindowType win){
XCloseDisplay(dis);
}

View File

@@ -0,0 +1,37 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "NativeSubWindow.h"
#include <Cocoa/Cocoa.h>
EGLNativeWindowType createSubWindow(FBNativeWindowType p_window,
EGLNativeDisplayType* display_out,
int x, int y,int width, int height){
NSRect contentRect = NSMakeRect(x, y, width, height);
NSView *glView = [[NSView alloc] initWithFrame:contentRect];
if (glView) {
NSWindow *win = (NSWindow *)p_window;
[[win contentView] addSubview:glView];
[win makeKeyAndOrderFront:nil];
}
return (EGLNativeWindowType)glView;
}
void destroySubWindow(EGLNativeDisplayType dis,EGLNativeWindowType win){
if(win){
delete win;
}
}

View File

@@ -0,0 +1,29 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef NATIVE_SUB_WINDOW_H
#define NATIVE_SUB_WINDOW_H
#include <EGL/egl.h>
#include "libOpenglRender/render_api.h"
EGLNativeWindowType createSubWindow(FBNativeWindowType p_window,
EGLNativeDisplayType* display_out,
int x, int y,int width, int height);
void destroySubWindow(EGLNativeDisplayType dis,EGLNativeWindowType win);
#endif

View File

@@ -0,0 +1,55 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "NativeSubWindow.h"
#include <stdio.h>
LRESULT CALLBACK myWndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
EGLNativeWindowType createSubWindow(FBNativeWindowType p_window,
EGLNativeDisplayType* display_out,
int x, int y,int width, int height){
WNDCLASS wc;
wc.style = CS_OWNDC |CS_HREDRAW |CS_VREDRAW; // redraw if size changes
wc.lpfnWndProc = myWndProc; // points to window procedure
wc.cbClsExtra = 0; // no extra class memory
wc.cbWndExtra = sizeof(void*); // save extra window memory, to store VasWindow instance
wc.hInstance = NULL; // handle to instance
wc.hIcon = NULL; // predefined app. icon
wc.hCursor = NULL;
wc.hbrBackground = NULL; // no background brush
wc.lpszMenuName = NULL; // name of menu resource
wc.lpszClassName = "subWin"; // name of window class
RegisterClass(&wc);
printf("creating window %d %d %d %d\n",x,y,width,height);
EGLNativeWindowType ret = CreateWindow("subWin",
"sub",
WS_CHILD,
x,y,width,height,
p_window,
NULL,
NULL,
NULL);
ShowWindow(ret,SW_SHOW);
return ret;
}
void destroySubWindow(EGLNativeDisplayType dis,EGLNativeWindowType win){
DestroyWindow(win);
}

View File

@@ -23,6 +23,10 @@ static osUtils::childProcess *s_renderProc = NULL;
static RenderServer *s_renderThread = NULL; static RenderServer *s_renderThread = NULL;
static int s_renderPort = 0; static int s_renderPort = 0;
#ifdef __APPLE__
#define RENDER_API_USE_THREAD
#endif
bool initOpenGLRenderer(FBNativeWindowType window, bool initOpenGLRenderer(FBNativeWindowType window,
int x, int y, int width, int height, int x, int y, int width, int height,
int portNum) int portNum)
@@ -75,7 +79,32 @@ bool initOpenGLRenderer(FBNativeWindowType window,
IOStream *dummy = NULL; IOStream *dummy = NULL;
do { do {
++nTrys; ++nTrys;
//
// Wait a bit to make the renderer process a chance to be
// initialized.
// On Windows we need during this time to handle windows
// events since the renderer generates a subwindow of this
// process's window, we need to be responsive for windows
// during this time to let the renderer generates this subwindow.
//
#ifndef _WIN32
TimeSleepMS(300); TimeSleepMS(300);
#else
long long t0 = GetCurrentTimeMS();
while( (GetCurrentTimeMS() - t0) < 300 ) {
MSG msg;
int n = 0;
while( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) )
{
n++;
TranslateMessage( &msg );
DispatchMessage( &msg );
}
if (n == 0) TimeSleepMS(10);
}
#endif
dummy = createRenderThread(8); dummy = createRenderThread(8);
if (!dummy) { if (!dummy) {

View File

@@ -32,7 +32,7 @@ $(call emugl-begin-host-static-library,libOpenglOsUtils)
osProcessWin.cpp \ osProcessWin.cpp \
osThreadWin.cpp osThreadWin.cpp
$(call emugl-export,LDLIBS,-lws2_32) $(call emugl-export,LDLIBS,-lws2_32 -lpsapi)
else else
LOCAL_SRC_FILES += \ LOCAL_SRC_FILES += \
osProcessUnix.cpp \ osProcessUnix.cpp \