Disabled external gits
This commit is contained in:
86
cs440-acg/ext/tbb/examples/common/gui/Makefile.gmake
Normal file
86
cs440-acg/ext/tbb/examples/common/gui/Makefile.gmake
Normal file
@@ -0,0 +1,86 @@
|
||||
# Copyright (c) 2005-2020 Intel Corporation
|
||||
#
|
||||
# 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.
|
||||
|
||||
# The C++ compiler
|
||||
#CXX=g++
|
||||
|
||||
# detecting MS Windows (for MinGW support)
|
||||
ifeq ($(OS), Windows_NT)
|
||||
RM = cmd /C del /Q /F
|
||||
RD = cmd /C rmdir
|
||||
UI = con
|
||||
EXE = $(NAME)$(SUFFIX).exe
|
||||
|
||||
else
|
||||
RM = rm -f
|
||||
RD = rmdir -r
|
||||
|
||||
# detecting 64-bit platform
|
||||
arch ?= $(shell uname -m)
|
||||
# Possible values of interest: intel64 x86_64 amd64 ia64 ppc64 sparc sparc64
|
||||
x64 ?= $(findstring 64,$(subst sparc,sparc64,$(arch)))
|
||||
|
||||
# see https://wiki.debian.org/Multiarch/Tuples
|
||||
MULTIARCH = $(arch)
|
||||
ifeq ($(arch),ia32)
|
||||
MULTIARCH = i386
|
||||
endif
|
||||
ifeq ($(arch),intel64)
|
||||
MULTIARCH = x86_64
|
||||
endif
|
||||
ifeq ($(arch),ppc32)
|
||||
MULTIARCH = powerpc
|
||||
endif
|
||||
ifeq ($(arch),sparc)
|
||||
MULTIARCH = sparc64
|
||||
endif
|
||||
MULTIARCHTUPLE ?= $(MULTIARCH)-linux-gnu
|
||||
|
||||
# detecting UI ("mac", "x" or "con")
|
||||
ifeq ($(shell uname),Darwin)
|
||||
UI ?= mac
|
||||
else
|
||||
UI ?= $(shell sh -c "[ -f /usr/X11R6/lib$(x64)/libX11.so -o -f /usr/lib$(x64)/libX11.so -o -f /usr/lib/$(MULTIARCHTUPLE)/libX11.so ] && echo x")
|
||||
endif
|
||||
|
||||
ifeq ($(UI),x)
|
||||
EXE = $(NAME)$(SUFFIX)
|
||||
UI_CXXFLAGS += -I/usr/X11R6/include
|
||||
LIBS += -lpthread -L/usr/X11R6/lib$(x64) -lX11
|
||||
# detect if libXext can be found
|
||||
ifeq ($(shell sh -c "[ -f /usr/X11R6/lib$(x64)/libXext.so -o -f /usr/lib$(x64)/libXext.so -o -f /usr/lib/$(MULTIARCHTUPLE)/libXext.so ] && echo 0"),0)
|
||||
LIBS += -lXext
|
||||
else # no libXext
|
||||
UI_CXXFLAGS += -DX_NOSHMEM
|
||||
endif # libXext
|
||||
|
||||
else # ! X
|
||||
ifeq ($(UI),mac)
|
||||
CXX_UI?=g++
|
||||
LIBS += -framework OpenGL -framework Foundation -framework Cocoa
|
||||
MACUISOURCES = ../../common/gui/xcode/tbbExample/OpenGLView.m ../../common/gui/xcode/tbbExample/main.m ../../common/gui/xcode/tbbExample/tbbAppDelegate.m
|
||||
MACUIOBJS = OpenGLView.o main.o tbbAppDelegate.o
|
||||
APPRES = $(NAME)$(SUFFIX).app/Contents/Resources
|
||||
EXE = $(NAME)$(SUFFIX).app/Contents/MacOS/$(NAME)$(SUFFIX)
|
||||
|
||||
else # ! macOS*
|
||||
|
||||
EXE = $(NAME)$(SUFFIX)
|
||||
ifeq (,$(strip $(UI)))
|
||||
UI = con
|
||||
$(warning Note: no graphics output capability detected, building for console output.)
|
||||
endif
|
||||
endif # macOS
|
||||
endif # X
|
||||
endif # Windows vs. other
|
70
cs440-acg/ext/tbb/examples/common/gui/Makefile.win
Normal file
70
cs440-acg/ext/tbb/examples/common/gui/Makefile.win
Normal file
@@ -0,0 +1,70 @@
|
||||
# Copyright (c) 2005-2020 Intel Corporation
|
||||
#
|
||||
# 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.
|
||||
|
||||
# Per-build Makefile rules (for recursive $(MAKE) calls from Makefile)
|
||||
|
||||
# Base compile/link options
|
||||
MYCXXFLAGS = /nologo /EHsc /Zc:forScope /D WIN32 /D _MBCS /D _CRT_SECURE_NO_DEPRECATE /MP $(CXXFLAGS)
|
||||
MYLFLAGS = /link /incremental:no /fixed:no $(LFLAGS)
|
||||
CXXFLAGS_NDEBUG = /MD /O2 /Ot /Gy /D NDEBUG
|
||||
CXXFLAGS_DEBUG = /MDd /Od /Zi /D _DEBUG
|
||||
|
||||
# Specify library directory for Direct X SDK
|
||||
DDLIB_DIR=$(DXSDK_DIR)\lib\$(XARCH:AMD64=x64)
|
||||
|
||||
# Input and output files
|
||||
#SOURCE = v
|
||||
#RCNAME = specified externaly
|
||||
#EXE = ^
|
||||
# defaults on XARCH = x86
|
||||
UISRC = ../../common/gui/$(UI)video.cpp
|
||||
|
||||
default:
|
||||
|
||||
build_echo:
|
||||
-@echo Building$(DEBUG) $(EXE) with UI=$(UI) XARCH=$(XARCH)
|
||||
|
||||
build_one: build_echo build_$(UI)$(DEBUG)
|
||||
|
||||
build_con: $(SOURCE) $(UISRC) compiler_check
|
||||
$(CXX) $(CXXFLAGS_NDEBUG) $(MYCXXFLAGS) $(SOURCE) $(UISRC) $(MYLFLAGS) /subsystem:console /OUT:$(EXE)
|
||||
@cmd.exe /C del *.obj
|
||||
|
||||
build_con_debug: $(SOURCE) $(UISRC) compiler_check
|
||||
$(CXX) $(CXXFLAGS_DEBUG) $(MYCXXFLAGS) $(SOURCE) $(UISRC) $(MYLFLAGS) /debug /subsystem:console /OUT:$(EXE)
|
||||
@cmd.exe /C del *.obj
|
||||
|
||||
build_gdi: $(SOURCE) $(UISRC) msvs/$(RCNAME).res compiler_check
|
||||
$(CXX) $(CXXFLAGS_NDEBUG) /D _WINDOWS $(MYCXXFLAGS) $(SOURCE) $(UISRC) $(MYLFLAGS) msvs/$(RCNAME).res /subsystem:windows /machine:$(XARCH) /OUT:$(EXE)
|
||||
@cmd.exe /C del *.obj
|
||||
|
||||
build_gdi_debug: $(SOURCE) $(UISRC) msvs/$(RCNAME).res compiler_check
|
||||
$(CXX) $(CXXFLAGS_DEBUG) /D _WINDOWS $(MYCXXFLAGS) $(SOURCE) $(UISRC) $(MYLFLAGS) msvs/$(RCNAME).res /debug /subsystem:windows /machine:$(XARCH) /OUT:$(EXE)
|
||||
@cmd.exe /C del *.obj
|
||||
|
||||
build_d2d: $(SOURCE) $(UISRC) msvs/$(RCNAME).res compiler_check
|
||||
-@echo Using DirectX SDK from "$(DDLIB_DIR)"
|
||||
$(CXX) $(CXXFLAGS_NDEBUG) /D _WINDOWS $(MYCXXFLAGS) /I "$(DXSDK_DIR)\include" $(SOURCE) $(UISRC) $(MYLFLAGS) /LIBPATH:"$(DDLIB_DIR)" msvs/$(RCNAME).res /subsystem:windows /machine:$(XARCH) /OUT:$(EXE)
|
||||
@cmd.exe /C del *.obj
|
||||
|
||||
build_d2d_debug: $(SOURCE) $(UISRC) msvs/$(RCNAME).res compiler_check
|
||||
-@echo Using DirectX SDK from "$(DDLIB_DIR)"
|
||||
$(CXX) $(CXXFLAGS_DEBUG) /D _WINDOWS $(MYCXXFLAGS) /I "$(DXSDK_DIR)\include" $(SOURCE) $(UISRC) $(MYLFLAGS) /LIBPATH:"$(DDLIB_DIR)" msvs/$(RCNAME).res /debug /subsystem:windows /machine:$(XARCH) /OUT:$(EXE)
|
||||
@cmd.exe /C del *.obj
|
||||
|
||||
msvs/$(RCNAME).res:
|
||||
rc /r msvs/$(RCNAME)
|
||||
compiler_check:
|
||||
@echo compiler_test>compiler_test && @$(CXX) /E compiler_test >nul 2>&1 || echo "$(CXX) command not found. Check if CXX=$(CXX) is set properly"
|
||||
@cmd.exe /C del compiler_test
|
132
cs440-acg/ext/tbb/examples/common/gui/convideo.cpp
Normal file
132
cs440-acg/ext/tbb/examples/common/gui/convideo.cpp
Normal file
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
Copyright (c) 2005-2020 Intel Corporation
|
||||
|
||||
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 "video.h"
|
||||
#include <cassert>
|
||||
#include <stdio.h>
|
||||
|
||||
unsigned int * g_pImg = 0;
|
||||
int g_sizex, g_sizey;
|
||||
static video *g_video = 0;
|
||||
static int g_fps = 0;
|
||||
|
||||
#if _WIN32 || _WIN64
|
||||
|
||||
static DWORD g_msec = 0;
|
||||
|
||||
#ifdef _WINDOWS
|
||||
HINSTANCE video::win_hInstance = 0;
|
||||
int video::win_iCmdShow = 0;
|
||||
void video::win_set_class(WNDCLASSEX &wcex) { }
|
||||
void video::win_load_accelerators(int idc) { }
|
||||
#endif //_WINDOWS
|
||||
|
||||
#else
|
||||
#include <sched.h>
|
||||
#include <sys/time.h>
|
||||
struct timeval g_time;
|
||||
#endif //_WIN32||_WIN64
|
||||
|
||||
#define CALC_FPS_ENABLED ((WINAPI_FAMILY != WINAPI_FAMILY_APP) && (!__ANDROID__))
|
||||
|
||||
video::video()
|
||||
// OpenGL* RGBA byte order for little-endian CPU
|
||||
: depth(24), red_shift(0), green_shift(8), blue_shift(16),
|
||||
red_mask(0xff), green_mask(0xff00), blue_mask(0xff0000)
|
||||
{
|
||||
assert(g_video == 0);
|
||||
g_video = this; title = "Video"; updating = calc_fps = false;
|
||||
}
|
||||
|
||||
bool video::init_window(int x, int y)
|
||||
{
|
||||
g_sizex = x; g_sizey = y;
|
||||
g_pImg = new unsigned int[x*y];
|
||||
running = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool video::init_console()
|
||||
{
|
||||
running = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void video::terminate()
|
||||
{
|
||||
#if CALC_FPS_ENABLED
|
||||
if(calc_fps) {
|
||||
double fps = g_fps;
|
||||
#if _WIN32 || _WIN64
|
||||
fps /= (GetTickCount()-g_msec)/1000.0;
|
||||
#else
|
||||
struct timezone tz; struct timeval end_time; gettimeofday(&end_time, &tz);
|
||||
fps /= (end_time.tv_sec+1.0*end_time.tv_usec/1000000.0) - (g_time.tv_sec+1.0*g_time.tv_usec/1000000.0);
|
||||
#endif
|
||||
printf("%s: %.1f fps\n", title, fps);
|
||||
}
|
||||
#endif
|
||||
g_video = 0; running = false;
|
||||
if(g_pImg) { delete[] g_pImg; g_pImg = 0; }
|
||||
}
|
||||
|
||||
video::~video()
|
||||
{
|
||||
if(g_video) terminate();
|
||||
}
|
||||
|
||||
//! Count and display FPS count in titlebar
|
||||
bool video::next_frame()
|
||||
{
|
||||
#if CALC_FPS_ENABLED
|
||||
if(calc_fps){
|
||||
if(!g_fps) {
|
||||
#if _WIN32 || _WIN64
|
||||
g_msec = GetTickCount();
|
||||
#else
|
||||
struct timezone tz; gettimeofday(&g_time, &tz);
|
||||
#endif
|
||||
}
|
||||
g_fps++;
|
||||
}
|
||||
#endif
|
||||
return running;
|
||||
}
|
||||
|
||||
//! Do standard loop
|
||||
void video::main_loop()
|
||||
{
|
||||
on_process();
|
||||
}
|
||||
|
||||
//! Change window title
|
||||
void video::show_title()
|
||||
{
|
||||
}
|
||||
|
||||
///////////////////////////////////////////// public methods of video class ///////////////////////
|
||||
|
||||
drawing_area::drawing_area(int x, int y, int sizex, int sizey)
|
||||
: base_index(y*g_sizex + x), max_index(g_sizex*g_sizey), index_stride(g_sizex),
|
||||
pixel_depth(24), ptr32(g_pImg), start_x(x), start_y(y), size_x(sizex), size_y(sizey)
|
||||
{
|
||||
assert(x < g_sizex); assert(y < g_sizey);
|
||||
assert(x+sizex <= g_sizex); assert(y+sizey <= g_sizey);
|
||||
|
||||
index = base_index; // current index
|
||||
}
|
||||
|
||||
void drawing_area::update() {}
|
197
cs440-acg/ext/tbb/examples/common/gui/d2dvideo.cpp
Normal file
197
cs440-acg/ext/tbb/examples/common/gui/d2dvideo.cpp
Normal file
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
Copyright (c) 2005-2020 Intel Corporation
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
// common Windows parts
|
||||
#include "winvideo.h"
|
||||
|
||||
// and another headers
|
||||
#include <cassert>
|
||||
#include <stdio.h>
|
||||
#include <dxsdkver.h>
|
||||
#if _DXSDK_PRODUCT_MAJOR < 9
|
||||
#error DXSDK Version 9 and above required.
|
||||
#endif
|
||||
#include <d2d1.h>
|
||||
#include <d2d1helper.h>
|
||||
#pragma comment(lib, "d2d1.lib")
|
||||
|
||||
ID2D1Factory *m_pD2DFactory;
|
||||
ID2D1HwndRenderTarget *m_pRenderTarget;
|
||||
ID2D1Bitmap *m_pBitmap;
|
||||
D2D1_SIZE_U bitmapSize;
|
||||
|
||||
HANDLE g_hVSync;
|
||||
|
||||
#include <DXErr.h>
|
||||
#pragma comment(lib, "DxErr.lib")
|
||||
|
||||
//! Create a dialog box and tell the user what went wrong
|
||||
bool DisplayError(LPSTR lpstrErr, HRESULT hres)
|
||||
{
|
||||
if(hres != S_OK){
|
||||
static bool InError = false;
|
||||
int retval = 0;
|
||||
if (!InError)
|
||||
{
|
||||
InError = true;
|
||||
const char *message = hres?DXGetErrorString(hres):0;
|
||||
retval = MessageBoxA(g_hAppWnd, lpstrErr, hres?message:"Error!", MB_OK|MB_ICONERROR);
|
||||
InError = false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void DrawBitmap()
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
if (m_pRenderTarget) {
|
||||
m_pRenderTarget->BeginDraw();
|
||||
if (m_pBitmap)
|
||||
hr = m_pBitmap->CopyFromMemory(NULL,(BYTE*)g_pImg, 4*g_sizex);
|
||||
DisplayError( "DrawBitmap error", hr );
|
||||
m_pRenderTarget->DrawBitmap(m_pBitmap);
|
||||
m_pRenderTarget->EndDraw();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
inline void mouse(int k, LPARAM lParam)
|
||||
{
|
||||
int x = (int)LOWORD(lParam);
|
||||
int y = (int)HIWORD(lParam);
|
||||
RECT rc;
|
||||
GetClientRect(g_hAppWnd, &rc);
|
||||
g_video->on_mouse( x*g_sizex/(rc.right - rc.left), y*g_sizey/(rc.bottom - rc.top), k );
|
||||
}
|
||||
|
||||
//! Win event processing function
|
||||
LRESULT CALLBACK InternalWndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (iMsg)
|
||||
{
|
||||
case WM_MOVE:
|
||||
// Check to make sure our window exists before we tell it to repaint.
|
||||
// This will fail the first time (while the window is being created).
|
||||
if (hwnd) {
|
||||
InvalidateRect(hwnd, NULL, FALSE);
|
||||
UpdateWindow(hwnd);
|
||||
}
|
||||
return 0L;
|
||||
|
||||
case WM_SIZE:
|
||||
case WM_PAINT:
|
||||
if( g_video->running && g_video->updating ) {
|
||||
DrawBitmap();
|
||||
Sleep(0);
|
||||
}
|
||||
break;
|
||||
// Process all mouse and keyboard events
|
||||
case WM_LBUTTONDOWN: mouse( 1, lParam ); break;
|
||||
case WM_LBUTTONUP: mouse(-1, lParam ); break;
|
||||
case WM_RBUTTONDOWN: mouse( 2, lParam ); break;
|
||||
case WM_RBUTTONUP: mouse(-2, lParam ); break;
|
||||
case WM_MBUTTONDOWN: mouse( 3, lParam ); break;
|
||||
case WM_MBUTTONUP: mouse(-3, lParam ); break;
|
||||
case WM_CHAR: g_video->on_key( (int)wParam); break;
|
||||
|
||||
// some useless stuff
|
||||
case WM_ERASEBKGND: return 1; // keeps erase-background events from happening, reduces chop
|
||||
case WM_DISPLAYCHANGE: return 0;
|
||||
|
||||
// Now, shut down the window...
|
||||
case WM_DESTROY: PostQuitMessage(0); return 0;
|
||||
}
|
||||
// call user defined proc, if exists
|
||||
return g_pUserProc? g_pUserProc(hwnd, iMsg, wParam, lParam) : DefWindowProc(hwnd, iMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
bool video::init_window(int sizex, int sizey)
|
||||
{
|
||||
assert(win_hInstance != 0);
|
||||
g_sizex = sizex; g_sizey = sizey;
|
||||
if (!WinInit(win_hInstance, win_iCmdShow, gWndClass, title, false)) {
|
||||
DisplayError("Unable to initialize the program's window.");
|
||||
return false;
|
||||
}
|
||||
ShowWindow(g_hAppWnd, SW_SHOW);
|
||||
g_pImg = new unsigned int[sizex*sizey];
|
||||
|
||||
HRESULT hr = S_OK;
|
||||
|
||||
hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &m_pD2DFactory);
|
||||
// Create a Direct2D render target.
|
||||
if (SUCCEEDED(hr) && !m_pRenderTarget){
|
||||
RECT rc;
|
||||
GetClientRect(g_hAppWnd, &rc);
|
||||
|
||||
bitmapSize = D2D1::SizeU(
|
||||
rc.right - rc.left,
|
||||
rc.bottom - rc.top
|
||||
);
|
||||
|
||||
hr = m_pD2DFactory->CreateHwndRenderTarget(
|
||||
D2D1::RenderTargetProperties(),
|
||||
D2D1::HwndRenderTargetProperties(g_hAppWnd, bitmapSize),
|
||||
&m_pRenderTarget
|
||||
);
|
||||
if (SUCCEEDED(hr) && !m_pBitmap){
|
||||
D2D1_PIXEL_FORMAT pixelFormat = D2D1::PixelFormat(
|
||||
DXGI_FORMAT_B8G8R8A8_UNORM,
|
||||
D2D1_ALPHA_MODE_IGNORE
|
||||
);
|
||||
D2D1_BITMAP_PROPERTIES bitmapProperties;
|
||||
bitmapProperties.pixelFormat = pixelFormat;
|
||||
m_pRenderTarget->GetDpi( &bitmapProperties.dpiX, &bitmapProperties.dpiY );
|
||||
m_pRenderTarget->CreateBitmap(bitmapSize,bitmapProperties,&m_pBitmap);
|
||||
m_pRenderTarget->DrawBitmap(m_pBitmap);
|
||||
}
|
||||
}
|
||||
|
||||
running = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void video::terminate()
|
||||
{
|
||||
if (m_pBitmap) m_pBitmap->Release();
|
||||
if (m_pRenderTarget) m_pRenderTarget->Release();
|
||||
if (m_pD2DFactory) m_pD2DFactory->Release();
|
||||
g_video = 0; running = false;
|
||||
if(g_pImg) { delete[] g_pImg; g_pImg = 0; }
|
||||
}
|
||||
|
||||
//////////// drawing area constructor & destructor /////////////
|
||||
|
||||
drawing_area::drawing_area(int x, int y, int sizex, int sizey)
|
||||
: base_index(y*g_sizex + x), max_index(g_sizex*g_sizey), index_stride(g_sizex),
|
||||
pixel_depth(24), ptr32(g_pImg), start_x(x), start_y(y), size_x(sizex), size_y(sizey)
|
||||
{
|
||||
assert(x < g_sizex); assert(y < g_sizey);
|
||||
assert(x+sizex <= g_sizex); assert(y+sizey <= g_sizey);
|
||||
|
||||
index = base_index; // current index
|
||||
}
|
||||
|
||||
void drawing_area::update()
|
||||
{
|
||||
if(g_video->updating) {
|
||||
RECT r;
|
||||
r.left = start_x; r.right = start_x + size_x;
|
||||
r.top = start_y; r.bottom = start_y + size_y;
|
||||
InvalidateRect(g_hAppWnd, &r, false);
|
||||
}
|
||||
}
|
24
cs440-acg/ext/tbb/examples/common/gui/dxcheck.bat
Normal file
24
cs440-acg/ext/tbb/examples/common/gui/dxcheck.bat
Normal file
@@ -0,0 +1,24 @@
|
||||
@echo off
|
||||
REM
|
||||
REM Copyright (c) 2005-2020 Intel Corporation
|
||||
REM
|
||||
REM Licensed under the Apache License, Version 2.0 (the "License");
|
||||
REM you may not use this file except in compliance with the License.
|
||||
REM You may obtain a copy of the License at
|
||||
REM
|
||||
REM http://www.apache.org/licenses/LICENSE-2.0
|
||||
REM
|
||||
REM Unless required by applicable law or agreed to in writing, software
|
||||
REM distributed under the License is distributed on an "AS IS" BASIS,
|
||||
REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
REM See the License for the specific language governing permissions and
|
||||
REM limitations under the License.
|
||||
REM
|
||||
if "%DXSDK_DIR%"=="" goto error_no_DXSDK
|
||||
goto end
|
||||
|
||||
:error_no_DXSDK
|
||||
echo DirectX SDK Check : error : This example requires the DirectX SDK. Either (re)-install the DirectX SDK, or set the DXSDK_DIR environment variable to indicate where it is installed.
|
||||
|
||||
:end
|
||||
|
142
cs440-acg/ext/tbb/examples/common/gui/gdivideo.cpp
Normal file
142
cs440-acg/ext/tbb/examples/common/gui/gdivideo.cpp
Normal file
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
Copyright (c) 2005-2020 Intel Corporation
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
// common Windows parts
|
||||
#include "winvideo.h"
|
||||
// include GDI+ headers
|
||||
#include <gdiplus.h>
|
||||
// and another headers
|
||||
#include <stdio.h>
|
||||
|
||||
// tag linking library
|
||||
#pragma comment(lib, "gdiplus.lib")
|
||||
|
||||
// global specific variables
|
||||
Gdiplus::Bitmap * g_pBitmap; // main drawing bitmap
|
||||
ULONG_PTR gdiplusToken;
|
||||
Gdiplus::GdiplusStartupInput gdiplusStartupInput;// GDI+
|
||||
|
||||
//! display system error
|
||||
bool DisplayError(LPSTR lpstrErr, HRESULT hres)
|
||||
{
|
||||
static bool InError = false;
|
||||
int retval = 0;
|
||||
if (!InError)
|
||||
{
|
||||
InError = true;
|
||||
LPCSTR lpMsgBuf;
|
||||
if(!hres) hres = GetLastError();
|
||||
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, hres, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL );
|
||||
retval = MessageBox(g_hAppWnd, lpstrErr, lpMsgBuf, MB_OK|MB_ICONERROR);
|
||||
LocalFree( (HLOCAL)lpMsgBuf );
|
||||
InError = false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//! Win event processing function
|
||||
LRESULT CALLBACK InternalWndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (iMsg)
|
||||
{
|
||||
case WM_MOVE:
|
||||
// Check to make sure our window exists before we tell it to repaint.
|
||||
// This will fail the first time (while the window is being created).
|
||||
if (hwnd) {
|
||||
InvalidateRect(hwnd, NULL, FALSE);
|
||||
UpdateWindow(hwnd);
|
||||
}
|
||||
return 0L;
|
||||
|
||||
case WM_PAINT:
|
||||
{
|
||||
PAINTSTRUCT ps;
|
||||
Gdiplus::Graphics graphics( BeginPaint(hwnd, &ps) );
|
||||
// redraw just requested area. This call is as fast as simple DrawImage() call.
|
||||
if(g_video->updating) graphics.DrawImage(g_pBitmap, ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.left, ps.rcPaint.top,
|
||||
ps.rcPaint.right, ps.rcPaint.bottom, Gdiplus::UnitPixel);
|
||||
EndPaint(hwnd, &ps);
|
||||
}
|
||||
return 0L;
|
||||
|
||||
// Process all mouse and keyboard events
|
||||
case WM_LBUTTONDOWN: g_video->on_mouse( (int)LOWORD(lParam), (int)HIWORD(lParam), 1); break;
|
||||
case WM_LBUTTONUP: g_video->on_mouse( (int)LOWORD(lParam), (int)HIWORD(lParam), -1); break;
|
||||
case WM_RBUTTONDOWN: g_video->on_mouse( (int)LOWORD(lParam), (int)HIWORD(lParam), 2); break;
|
||||
case WM_RBUTTONUP: g_video->on_mouse( (int)LOWORD(lParam), (int)HIWORD(lParam), -2); break;
|
||||
case WM_MBUTTONDOWN: g_video->on_mouse( (int)LOWORD(lParam), (int)HIWORD(lParam), 3); break;
|
||||
case WM_MBUTTONUP: g_video->on_mouse( (int)LOWORD(lParam), (int)HIWORD(lParam), -3); break;
|
||||
case WM_CHAR: g_video->on_key( (int)wParam); break;
|
||||
|
||||
// some useless stuff
|
||||
case WM_ERASEBKGND: return 1; // keeps erase-background events from happening, reduces chop
|
||||
case WM_DISPLAYCHANGE: return 0;
|
||||
|
||||
// Now, shut down the window...
|
||||
case WM_DESTROY: PostQuitMessage(0); return 0;
|
||||
}
|
||||
// call user defined proc, if exists
|
||||
return g_pUserProc? g_pUserProc(hwnd, iMsg, wParam, lParam) : DefWindowProc(hwnd, iMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
///////////// video functions ////////////////
|
||||
|
||||
bool video::init_window(int sizex, int sizey)
|
||||
{
|
||||
assert(win_hInstance != 0);
|
||||
g_sizex = sizex; g_sizey = sizey;
|
||||
if (!WinInit(win_hInstance, win_iCmdShow, gWndClass, title, true)) {
|
||||
DisplayError("Unable to initialize the program's window.");
|
||||
return false;
|
||||
}
|
||||
ShowWindow(g_hAppWnd, SW_SHOW);
|
||||
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
|
||||
g_pImg = new unsigned int[sizex*sizey];
|
||||
g_pBitmap = new Gdiplus::Bitmap(g_sizex, g_sizey, 4*g_sizex, PixelFormat32bppRGB, (BYTE*)g_pImg );
|
||||
running = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void video::terminate()
|
||||
{
|
||||
if(g_pBitmap) { delete g_pBitmap; g_pBitmap = 0; }
|
||||
Gdiplus::GdiplusShutdown(gdiplusToken);
|
||||
g_video = 0; running = false;
|
||||
if(g_pImg) { delete[] g_pImg; g_pImg = 0; }
|
||||
}
|
||||
|
||||
//////////// drawing area constructor & destructor /////////////
|
||||
|
||||
drawing_area::drawing_area(int x, int y, int sizex, int sizey)
|
||||
: base_index(y*g_sizex + x), max_index(g_sizex*g_sizey), index_stride(g_sizex),
|
||||
pixel_depth(24), ptr32(g_pImg), start_x(x), start_y(y), size_x(sizex), size_y(sizey)
|
||||
{
|
||||
assert(x < g_sizex); assert(y < g_sizey);
|
||||
assert(x+sizex <= g_sizex); assert(y+sizey <= g_sizey);
|
||||
|
||||
index = base_index; // current index
|
||||
}
|
||||
|
||||
void drawing_area::update()
|
||||
{
|
||||
if(g_video->updating) {
|
||||
RECT r;
|
||||
r.left = start_x; r.right = start_x + size_x;
|
||||
r.top = start_y; r.bottom = start_y + size_y;
|
||||
InvalidateRect(g_hAppWnd, &r, false);
|
||||
}
|
||||
}
|
160
cs440-acg/ext/tbb/examples/common/gui/macvideo.cpp
Normal file
160
cs440-acg/ext/tbb/examples/common/gui/macvideo.cpp
Normal file
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
Copyright (c) 2005-2020 Intel Corporation
|
||||
|
||||
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 "video.h"
|
||||
#include <cassert>
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <pthread.h>
|
||||
|
||||
unsigned int* g_pImg = 0;
|
||||
int g_sizex=0, g_sizey=0;
|
||||
static video *g_video = 0;
|
||||
static int g_fps = 0;
|
||||
char *window_title=NULL;
|
||||
#define WINDOW_TITLE_SIZE 256
|
||||
int cocoa_update=0;
|
||||
|
||||
#include <sched.h>
|
||||
#include <sys/time.h>
|
||||
struct timeval g_time;
|
||||
|
||||
video::video()
|
||||
#if __TBB_IOS
|
||||
: depth(24), red_shift(0), green_shift(8), blue_shift(16),
|
||||
red_mask(0xff), green_mask(0xff00), blue_mask(0xff0000)
|
||||
#else
|
||||
: depth(24), red_shift(16), green_shift(8), blue_shift(0),
|
||||
red_mask(0xff0000), green_mask(0xff00), blue_mask(0xff)
|
||||
#endif
|
||||
{
|
||||
assert(g_video == 0);
|
||||
g_video = this; title = "Video"; cocoa_update=1; updating = true; calc_fps = false;
|
||||
}
|
||||
|
||||
bool video::init_window(int x, int y)
|
||||
{
|
||||
g_sizex = x; g_sizey = y;
|
||||
g_pImg = new unsigned int[x*y];
|
||||
if( window_title==NULL )
|
||||
window_title = (char*)malloc(WINDOW_TITLE_SIZE);
|
||||
strncpy( window_title, title, WINDOW_TITLE_SIZE-1 );
|
||||
running = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool video::init_console()
|
||||
{
|
||||
running = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void video::terminate()
|
||||
{
|
||||
if(calc_fps) {
|
||||
double fps = g_fps;
|
||||
struct timezone tz; struct timeval end_time; gettimeofday(&end_time, &tz);
|
||||
fps /= (end_time.tv_sec+1.0*end_time.tv_usec/1000000.0) - (g_time.tv_sec+1.0*g_time.tv_usec/1000000.0);
|
||||
printf("%s: %.1f fps\n", title, fps);
|
||||
}
|
||||
g_video = 0; running = false;
|
||||
if(g_pImg) { delete[] g_pImg; g_pImg = 0; }
|
||||
}
|
||||
|
||||
video::~video()
|
||||
{
|
||||
if(g_video) terminate();
|
||||
}
|
||||
|
||||
//! Count and display FPS count in titlebar
|
||||
bool video::next_frame()
|
||||
{
|
||||
if(calc_fps){
|
||||
if(!g_fps) {
|
||||
struct timezone tz; gettimeofday(&g_time, &tz);
|
||||
}
|
||||
g_fps++;
|
||||
}
|
||||
struct timezone tz; struct timeval now_time; gettimeofday(&now_time, &tz);
|
||||
double sec=((now_time.tv_sec+1.0*now_time.tv_usec/1000000.0) - (g_time.tv_sec+1.0*g_time.tv_usec/1000000.0));
|
||||
if( sec>1 ){
|
||||
if(calc_fps) {
|
||||
memcpy(&g_time, &now_time, sizeof(g_time));
|
||||
int fps;
|
||||
fps = g_fps/sec;
|
||||
cocoa_update = (int)updating;
|
||||
snprintf(window_title,WINDOW_TITLE_SIZE, "%s%s: %d fps", title, updating?"":" (no updating)", int(fps));
|
||||
g_fps=0;
|
||||
}
|
||||
}
|
||||
return running;
|
||||
}
|
||||
|
||||
|
||||
void* thread_func(void*)
|
||||
{
|
||||
g_video->on_process();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
extern "C" void on_mouse_func(int x, int y, int k)
|
||||
{
|
||||
g_video->on_mouse(x, y, k);
|
||||
return;
|
||||
}
|
||||
|
||||
extern "C" void on_key_func(int x)
|
||||
{
|
||||
g_video->on_key(x);
|
||||
return;
|
||||
}
|
||||
|
||||
extern "C" int cocoa_main( int argc, char *argv[] );
|
||||
//! Do standard loop
|
||||
void video::main_loop()
|
||||
{
|
||||
pthread_t handle;
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_create(&handle,&attr,&thread_func,(void*)NULL);
|
||||
pthread_detach(handle);
|
||||
cocoa_main( 0, NULL );
|
||||
}
|
||||
|
||||
//! Change window title
|
||||
void video::show_title()
|
||||
{
|
||||
if(title)
|
||||
strncpy( window_title, title, WINDOW_TITLE_SIZE );
|
||||
return;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////// public methods of video class ///////////////////////
|
||||
|
||||
drawing_area::drawing_area(int x, int y, int sizex, int sizey)
|
||||
: base_index(y*g_sizex + x), max_index(g_sizex*g_sizey), index_stride(g_sizex),
|
||||
pixel_depth(24), ptr32(g_pImg), start_x(x), start_y(y), size_x(sizex), size_y(sizey)
|
||||
{
|
||||
assert(x < g_sizex); assert(y < g_sizey);
|
||||
assert(x+sizex <= g_sizex); assert(y+sizey <= g_sizey);
|
||||
|
||||
index = base_index; // current index
|
||||
}
|
||||
|
||||
void drawing_area::update()
|
||||
{
|
||||
//nothing to do, updating via timer in cocoa part.
|
||||
}
|
237
cs440-acg/ext/tbb/examples/common/gui/video.h
Normal file
237
cs440-acg/ext/tbb/examples/common/gui/video.h
Normal file
@@ -0,0 +1,237 @@
|
||||
/*
|
||||
Copyright (c) 2005-2020 Intel Corporation
|
||||
|
||||
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 __VIDEO_H__
|
||||
#define __VIDEO_H__
|
||||
|
||||
#include <cassert>
|
||||
#if _MSC_VER
|
||||
#include <stddef.h> // for uintptr_t
|
||||
#else
|
||||
#include <stdint.h> // for uintptr_t
|
||||
#endif
|
||||
#if _WIN32 || _WIN64
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
typedef unsigned int color_t;
|
||||
typedef unsigned char colorcomp_t;
|
||||
typedef signed char depth_t;
|
||||
|
||||
//! Class for getting access to drawing memory
|
||||
class drawing_memory
|
||||
{
|
||||
#ifdef __TBB_MIC_OFFLOAD
|
||||
// The address is kept as uintptr_t since
|
||||
// the compiler could not offload a pointer
|
||||
#endif
|
||||
uintptr_t my_address;
|
||||
public:
|
||||
depth_t pixel_depth;
|
||||
int sizex, sizey;
|
||||
//! Get drawing memory
|
||||
inline char* get_address() const { return reinterpret_cast<char*>(my_address); }
|
||||
//! Get drawing memory size
|
||||
inline int get_size() const { return ((pixel_depth>16) ? 4:2) * sizex * sizey; }
|
||||
//! Set drawing memory
|
||||
inline void set_address(char *mem) { my_address = reinterpret_cast<uintptr_t>(mem); }
|
||||
|
||||
friend class drawing_area;
|
||||
friend class video;
|
||||
};
|
||||
|
||||
//! Simple proxy class for managing of different video systems
|
||||
class video
|
||||
{
|
||||
//! colorspace information
|
||||
depth_t depth, red_shift, green_shift, blue_shift;
|
||||
color_t red_mask, green_mask, blue_mask;
|
||||
friend class drawing_area;
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
video();
|
||||
//! Destructor
|
||||
~video();
|
||||
//! member to set window name
|
||||
const char *title;
|
||||
//! true is enable to show fps
|
||||
bool calc_fps;
|
||||
//! if true: on windows fork processing thread for on_process(), on non-windows note that next_frame() is called concurrently.
|
||||
bool threaded;
|
||||
//! true while running within main_loop()
|
||||
bool running;
|
||||
//! if true, do gui updating
|
||||
bool updating;
|
||||
//! initialize graphical video system
|
||||
bool init_window(int sizex, int sizey);
|
||||
//! initialize console. returns true if console is available
|
||||
bool init_console();
|
||||
//! terminate video system
|
||||
void terminate();
|
||||
//! Do standard event & processing loop. Use threaded = true to separate event/updating loop from frame processing
|
||||
void main_loop();
|
||||
//! Process next frame
|
||||
bool next_frame();
|
||||
//! Change window title
|
||||
void show_title();
|
||||
//! translate RGB components into packed type
|
||||
inline color_t get_color(colorcomp_t red, colorcomp_t green, colorcomp_t blue) const;
|
||||
//! Get drawing memory descriptor
|
||||
inline drawing_memory get_drawing_memory() const;
|
||||
|
||||
//! code of the ESCape key
|
||||
static const int esc_key = 27;
|
||||
//! Mouse events handler.
|
||||
virtual void on_mouse(int x, int y, int key) { }
|
||||
//! Mouse events handler.
|
||||
virtual void on_key(int key) { }
|
||||
//! Main processing loop. Redefine with your own
|
||||
virtual void on_process() { while(next_frame()); }
|
||||
|
||||
#ifdef _WINDOWS
|
||||
//! Windows specific members
|
||||
//! if VIDEO_WINMAIN isn't defined then set this just before init() by arguments of WinMain
|
||||
static HINSTANCE win_hInstance; static int win_iCmdShow;
|
||||
//! optionally call it just before init() to set own. Use ascii strings convention
|
||||
void win_set_class(WNDCLASSEX &);
|
||||
//! load and set accelerator table from resources
|
||||
void win_load_accelerators(int idc);
|
||||
#endif
|
||||
};
|
||||
|
||||
//! Drawing class
|
||||
class drawing_area
|
||||
{
|
||||
const size_t base_index, max_index, index_stride;
|
||||
const depth_t pixel_depth;
|
||||
unsigned int * const ptr32;
|
||||
size_t index;
|
||||
public:
|
||||
const int start_x, start_y, size_x, size_y;
|
||||
//! constructors
|
||||
drawing_area(int x, int y, int sizex, int sizey);
|
||||
inline drawing_area(int x, int y, int sizex, int sizey, const drawing_memory &dmem);
|
||||
//! destructor
|
||||
inline ~drawing_area();
|
||||
//! update the image
|
||||
void update();
|
||||
//! set current position. local_x could be bigger then size_x
|
||||
inline void set_pos(int local_x, int local_y);
|
||||
//! put pixel in current position with incremental address calculating to next right pixel
|
||||
inline void put_pixel(color_t color);
|
||||
//! draw pixel at position by packed color
|
||||
void set_pixel(int localx, int localy, color_t color)
|
||||
{ set_pos(localx, localy); put_pixel(color); }
|
||||
};
|
||||
|
||||
extern int g_sizex;
|
||||
extern int g_sizey;
|
||||
extern unsigned int *g_pImg;
|
||||
|
||||
inline drawing_memory video::get_drawing_memory() const
|
||||
{
|
||||
drawing_memory dmem;
|
||||
dmem.pixel_depth = depth;
|
||||
dmem.my_address = reinterpret_cast<uintptr_t>(g_pImg);
|
||||
dmem.sizex = g_sizex;
|
||||
dmem.sizey = g_sizey;
|
||||
return dmem;
|
||||
}
|
||||
|
||||
inline color_t video::get_color(colorcomp_t red, colorcomp_t green, colorcomp_t blue) const
|
||||
{
|
||||
if(red_shift == 16) // only for depth == 24 && red_shift > blue_shift
|
||||
return (red<<16) | (green<<8) | blue;
|
||||
else if(depth >= 24)
|
||||
return
|
||||
#if __ANDROID__
|
||||
// Setting Alpha to 0xFF
|
||||
0xFF000000 |
|
||||
#endif
|
||||
(red<<red_shift) | (green<<green_shift) | (blue<<blue_shift);
|
||||
else if(depth > 0) {
|
||||
depth_t bs = blue_shift, rs = red_shift;
|
||||
if(blue_shift < 0) blue >>= -bs, bs = 0;
|
||||
else /*red_shift < 0*/ red >>= -rs, rs = 0;
|
||||
return ((red<<rs)&red_mask) | ((green<<green_shift)&green_mask) | ((blue<<bs)&blue_mask);
|
||||
} else { // UYVY colorspace
|
||||
unsigned y, u, v;
|
||||
y = red * 77 + green * 150 + blue * 29; // sum(77+150+29=256) * max(=255): limit->2^16
|
||||
u = (2048 + (blue << 3) - (y >> 5)) >> 4; // (limit->2^12)>>4
|
||||
v = (2048 + (red << 3) - (y >> 5)) >> 4;
|
||||
y = y >> 8;
|
||||
return u | (y << 8) | (v << 16) | (y << 24);
|
||||
}
|
||||
}
|
||||
|
||||
inline drawing_area::drawing_area(int x, int y, int sizex, int sizey, const drawing_memory &dmem)
|
||||
: base_index(y*dmem.sizex + x), max_index(dmem.sizex*dmem.sizey), index_stride(dmem.sizex),
|
||||
pixel_depth(dmem.pixel_depth), ptr32(reinterpret_cast<unsigned int*>(dmem.my_address)),
|
||||
start_x(x), start_y(y), size_x(sizex), size_y(sizey)
|
||||
{
|
||||
assert(x < dmem.sizex); assert(y < dmem.sizey);
|
||||
assert(x+sizex <= dmem.sizex); assert(y+sizey <= dmem.sizey);
|
||||
|
||||
index = base_index; // current index
|
||||
}
|
||||
|
||||
inline void drawing_area::set_pos(int local_x, int local_y)
|
||||
{
|
||||
index = base_index + local_x + local_y*index_stride;
|
||||
}
|
||||
|
||||
inline void drawing_area::put_pixel(color_t color)
|
||||
{
|
||||
assert(index < max_index);
|
||||
if(pixel_depth > 16) ptr32[index++] = color;
|
||||
else if(pixel_depth > 0)
|
||||
((unsigned short*)ptr32)[index++] = (unsigned short)color;
|
||||
else { // UYVY colorspace
|
||||
if(index&1) color >>= 16;
|
||||
((unsigned short*)ptr32)[index++] = (unsigned short)color;
|
||||
}
|
||||
}
|
||||
|
||||
inline drawing_area::~drawing_area()
|
||||
{
|
||||
#if ! __TBB_DEFINE_MIC
|
||||
update();
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(_WINDOWS) && (defined(VIDEO_WINMAIN) || defined(VIDEO_WINMAIN_ARGS) )
|
||||
#include <cstdlib>
|
||||
//! define WinMain for subsystem:windows.
|
||||
#ifdef VIDEO_WINMAIN_ARGS
|
||||
int main(int, char *[]);
|
||||
#else
|
||||
int main();
|
||||
#endif
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR szCmdLine, int iCmdShow)
|
||||
{
|
||||
video::win_hInstance = hInstance; video::win_iCmdShow = iCmdShow;
|
||||
#ifdef VIDEO_WINMAIN_ARGS
|
||||
return main(__argc, __argv);
|
||||
#else
|
||||
return main();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif// __VIDEO_H__
|
279
cs440-acg/ext/tbb/examples/common/gui/winvideo.h
Normal file
279
cs440-acg/ext/tbb/examples/common/gui/winvideo.h
Normal file
@@ -0,0 +1,279 @@
|
||||
/*
|
||||
Copyright (c) 2005-2020 Intel Corporation
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/////// Common internal implementation of Windows-specific stuff //////////////
|
||||
/////// Must be the first included header //////////////
|
||||
|
||||
#ifndef __WINVIDEO_H__
|
||||
#define __WINVIDEO_H__
|
||||
|
||||
#ifndef _CRT_SECURE_NO_DEPRECATE
|
||||
#define _CRT_SECURE_NO_DEPRECATE
|
||||
#endif
|
||||
// Check that the target Windows version has all API calls required.
|
||||
#ifndef _WIN32_WINNT
|
||||
# define _WIN32_WINNT 0x0400
|
||||
#endif
|
||||
#if _WIN32_WINNT<0x0400
|
||||
# define YIELD_TO_THREAD() Sleep(0)
|
||||
#else
|
||||
# define YIELD_TO_THREAD() SwitchToThread()
|
||||
#endif
|
||||
#include "video.h"
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#pragma comment(lib, "gdi32.lib")
|
||||
#pragma comment(lib, "user32.lib")
|
||||
|
||||
// maximum number of lines the output console should have
|
||||
static const WORD MAX_CONSOLE_LINES = 500;
|
||||
const COLORREF RGBKEY = RGB(8, 8, 16); // at least 8 for 16-bit palette
|
||||
HWND g_hAppWnd; // The program's window handle
|
||||
HANDLE g_handles[2] = {0,0};// thread and wake up event
|
||||
unsigned int * g_pImg = 0; // drawing memory
|
||||
int g_sizex, g_sizey;
|
||||
static video * g_video = 0;
|
||||
WNDPROC g_pUserProc = 0;
|
||||
HINSTANCE video::win_hInstance = 0;
|
||||
int video::win_iCmdShow = 0;
|
||||
static WNDCLASSEX * gWndClass = 0;
|
||||
static HACCEL hAccelTable = 0;
|
||||
static DWORD g_msec = 0;
|
||||
static int g_fps = 0, g_updates = 0, g_skips = 0;
|
||||
|
||||
bool DisplayError(LPSTR lpstrErr, HRESULT hres = 0); // always returns false
|
||||
LRESULT CALLBACK InternalWndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
//! Create window
|
||||
bool WinInit(HINSTANCE hInstance, int nCmdShow, WNDCLASSEX *uwc, const char *title, bool fixedsize)
|
||||
{
|
||||
WNDCLASSEX wndclass; // Our app's windows class
|
||||
if(uwc) {
|
||||
memcpy(&wndclass, uwc, sizeof(wndclass));
|
||||
g_pUserProc = uwc->lpfnWndProc;
|
||||
} else {
|
||||
memset(&wndclass, 0, sizeof(wndclass));
|
||||
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
wndclass.lpszClassName = title;
|
||||
}
|
||||
wndclass.cbSize = sizeof(wndclass);
|
||||
wndclass.hInstance = hInstance;
|
||||
wndclass.lpfnWndProc = InternalWndProc;
|
||||
wndclass.style |= CS_HREDRAW | CS_VREDRAW;
|
||||
wndclass.hbrBackground = CreateSolidBrush(RGBKEY);
|
||||
|
||||
if( !RegisterClassExA(&wndclass) ) return false;
|
||||
int xaddend = GetSystemMetrics(fixedsize?SM_CXFIXEDFRAME:SM_CXFRAME)*2;
|
||||
int yaddend = GetSystemMetrics(fixedsize?SM_CYFIXEDFRAME:SM_CYFRAME)*2 + GetSystemMetrics(SM_CYCAPTION);
|
||||
if(wndclass.lpszMenuName) yaddend += GetSystemMetrics(SM_CYMENU);
|
||||
|
||||
// Setup the new window's physical parameters - and tell Windows to create it
|
||||
g_hAppWnd = CreateWindowA(wndclass.lpszClassName, // Window class name
|
||||
title, // Window caption
|
||||
!fixedsize ? WS_OVERLAPPEDWINDOW : // Window style
|
||||
WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX,
|
||||
CW_USEDEFAULT, // Initial x pos: use default placement
|
||||
0, // Initial y pos: not used here
|
||||
g_sizex+xaddend,// Initial x size
|
||||
g_sizey+yaddend,// Initial y size
|
||||
NULL, // parent window handle
|
||||
NULL, // window menu handle
|
||||
hInstance, // program instance handle
|
||||
NULL); // Creation parameters
|
||||
return g_hAppWnd != NULL;
|
||||
}
|
||||
|
||||
//! create console window with redirection
|
||||
static bool RedirectIOToConsole(void)
|
||||
{
|
||||
int hConHandle; size_t lStdHandle;
|
||||
CONSOLE_SCREEN_BUFFER_INFO coninfo;
|
||||
FILE *fp;
|
||||
// allocate a console for this app
|
||||
AllocConsole();
|
||||
|
||||
// set the screen buffer to be big enough to let us scroll text
|
||||
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
|
||||
coninfo.dwSize.Y = MAX_CONSOLE_LINES;
|
||||
SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize);
|
||||
|
||||
// redirect unbuffered STDOUT to the console
|
||||
lStdHandle = (size_t)GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
|
||||
if(hConHandle <= 0) return false;
|
||||
fp = _fdopen( hConHandle, "w" );
|
||||
*stdout = *fp;
|
||||
setvbuf( stdout, NULL, _IONBF, 0 );
|
||||
|
||||
// redirect unbuffered STDERR to the console
|
||||
lStdHandle = (size_t)GetStdHandle(STD_ERROR_HANDLE);
|
||||
hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
|
||||
if(hConHandle > 0) {
|
||||
fp = _fdopen( hConHandle, "w" );
|
||||
*stderr = *fp;
|
||||
setvbuf( stderr, NULL, _IONBF, 0 );
|
||||
}
|
||||
|
||||
// redirect unbuffered STDIN to the console
|
||||
lStdHandle = (size_t)GetStdHandle(STD_INPUT_HANDLE);
|
||||
hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
|
||||
if(hConHandle > 0) {
|
||||
fp = _fdopen( hConHandle, "r" );
|
||||
*stdin = *fp;
|
||||
setvbuf( stdin, NULL, _IONBF, 0 );
|
||||
}
|
||||
|
||||
// make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog
|
||||
// point to console as well
|
||||
std::ios::sync_with_stdio();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
video::video()
|
||||
: depth(24), red_shift(16), green_shift(8), blue_shift(0),
|
||||
red_mask(0xff0000), green_mask(0xff00), blue_mask(0xff)
|
||||
{
|
||||
assert(g_video == 0);
|
||||
g_video = this; title = "Video"; running = threaded = calc_fps = false; updating = true;
|
||||
}
|
||||
|
||||
//! optionally call it just before init() to set own
|
||||
void video::win_set_class(WNDCLASSEX &wcex)
|
||||
{
|
||||
gWndClass = &wcex;
|
||||
}
|
||||
|
||||
void video::win_load_accelerators(int idc)
|
||||
{
|
||||
hAccelTable = LoadAccelerators(win_hInstance, MAKEINTRESOURCE(idc));
|
||||
}
|
||||
|
||||
bool video::init_console()
|
||||
{
|
||||
if(RedirectIOToConsole()) {
|
||||
if(!g_pImg && g_sizex && g_sizey)
|
||||
g_pImg = new unsigned int[g_sizex * g_sizey];
|
||||
if(g_pImg) running = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
video::~video()
|
||||
{
|
||||
if(g_video) terminate();
|
||||
}
|
||||
|
||||
DWORD WINAPI thread_video(LPVOID lpParameter)
|
||||
{
|
||||
video *v = (video*)lpParameter;
|
||||
v->on_process();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool loop_once(video *v)
|
||||
{
|
||||
// screen update notify
|
||||
if(int updates = g_updates) {
|
||||
g_updates = 0;
|
||||
if(g_video->updating) { g_skips += updates-1; g_fps++; }
|
||||
else g_skips += updates;
|
||||
UpdateWindow(g_hAppWnd);
|
||||
}
|
||||
// update fps
|
||||
DWORD msec = GetTickCount();
|
||||
if(v->calc_fps && msec >= g_msec+1000) {
|
||||
double sec = (msec - g_msec)/1000.0;
|
||||
char buffer[256], n = _snprintf(buffer, 128, "%s: %d fps", v->title, int(double(g_fps + g_skips)/sec));
|
||||
if(g_skips) _snprintf(buffer+n, 128, " - %d skipped = %d updates", int(g_skips/sec), int(g_fps/sec));
|
||||
SetWindowTextA(g_hAppWnd, buffer);
|
||||
g_msec = msec; g_skips = g_fps = 0;
|
||||
}
|
||||
// event processing, including painting
|
||||
MSG msg;
|
||||
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){
|
||||
if( msg.message == WM_QUIT ) { v->running = false; return false; }
|
||||
if( !hAccelTable || !TranslateAccelerator(msg.hwnd, hAccelTable, &msg) ){
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
return true; // try again
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//! Do standard event loop
|
||||
void video::main_loop()
|
||||
{
|
||||
// let Windows draw and unroll the window
|
||||
InvalidateRect(g_hAppWnd, 0, false);
|
||||
g_msec = GetTickCount(); // let's stay for 0,5 sec
|
||||
while(g_msec + 500 > GetTickCount()) { loop_once(this); Sleep(1); }
|
||||
g_msec = GetTickCount();
|
||||
// now, start main process
|
||||
if(threaded) {
|
||||
g_handles[0] = CreateThread (
|
||||
NULL, // LPSECURITY_ATTRIBUTES security_attrs
|
||||
0, // SIZE_T stacksize
|
||||
(LPTHREAD_START_ROUTINE) thread_video,
|
||||
this, // argument
|
||||
0, 0);
|
||||
if(!g_handles[0]) { DisplayError("Can't create thread"); return; }
|
||||
else // harmless race is possible here
|
||||
g_handles[1] = CreateEvent(NULL, false, false, NULL);
|
||||
while(running) {
|
||||
while(loop_once(this));
|
||||
YIELD_TO_THREAD(); // give time for processing when running on single CPU
|
||||
DWORD r = MsgWaitForMultipleObjects(2, g_handles, false, INFINITE, QS_ALLINPUT^QS_MOUSEMOVE);
|
||||
if(r == WAIT_OBJECT_0) break; // thread terminated
|
||||
}
|
||||
running = false;
|
||||
if(WaitForSingleObject(g_handles[0], 3000) == WAIT_TIMEOUT){
|
||||
// there was not enough time for graceful shutdown, killing the example with code 1.
|
||||
exit(1);
|
||||
}
|
||||
if(g_handles[0]) CloseHandle(g_handles[0]);
|
||||
if(g_handles[1]) CloseHandle(g_handles[1]);
|
||||
g_handles[0] = g_handles[1] = 0;
|
||||
}
|
||||
else on_process();
|
||||
}
|
||||
|
||||
//! Refresh screen picture
|
||||
bool video::next_frame()
|
||||
{
|
||||
if(!running) return false;
|
||||
g_updates++; // Fast but inaccurate counter. The data race here is benign.
|
||||
if(!threaded) while(loop_once(this));
|
||||
else if(g_handles[1]) {
|
||||
SetEvent(g_handles[1]);
|
||||
YIELD_TO_THREAD();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//! Change window title
|
||||
void video::show_title()
|
||||
{
|
||||
if(g_hAppWnd)
|
||||
SetWindowTextA(g_hAppWnd, title);
|
||||
}
|
||||
|
||||
#endif //__WINVIDEO_H__
|
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
Copyright (c) 2005-2020 Intel Corporation
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "OpenGLES/ES2/gl.h"
|
||||
|
||||
@interface OpenGLView : UIView {
|
||||
NSTimer *timer;
|
||||
CGRect imageRect;
|
||||
}
|
||||
|
||||
@property (nonatomic, retain) NSTimer *timer;
|
||||
@property (nonatomic) CGRect imageRect;
|
||||
|
||||
- (void) drawRect:(CGRect)rect;
|
||||
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
|
||||
|
||||
@end
|
||||
|
||||
#elif TARGET_OS_MAC
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@interface OpenGLView : NSOpenGLView{
|
||||
NSTimer *timer;
|
||||
}
|
||||
|
||||
@property (nonatomic,retain) NSTimer *timer;
|
||||
|
||||
- (void) drawRect:(NSRect)start;
|
||||
- (void) mouseDown:(NSEvent *)theEvent;
|
||||
- (void) keyDown:(NSEvent *)theEvent;
|
||||
- (BOOL) acceptsFirstResponder;
|
||||
- (void) viewDidEndLiveResize;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
Copyright (c) 2005-2020 Intel Corporation
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "OpenGLView.h"
|
||||
|
||||
// defined in macvideo.cpp
|
||||
extern char* window_title;
|
||||
extern int cocoa_update;
|
||||
extern int g_sizex, g_sizey;
|
||||
extern unsigned int *g_pImg;
|
||||
void on_mouse_func(int x, int y, int k);
|
||||
void on_key_func(int x);
|
||||
|
||||
bool initialized = false;
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
#import "OpenGLES/ES2/gl.h"
|
||||
|
||||
@implementation OpenGLView
|
||||
|
||||
@synthesize timer;
|
||||
@synthesize imageRect;
|
||||
|
||||
- (void)drawRect:(CGRect)start
|
||||
{
|
||||
if (initialized == false) {
|
||||
NSLog(@"INITIALIZE");
|
||||
timer = [NSTimer scheduledTimerWithTimeInterval:0.03 target:self selector:@selector(update_window) userInfo:nil repeats:YES];
|
||||
imageRect = [[UIScreen mainScreen] bounds];
|
||||
CGFloat full_height = imageRect.size.height;
|
||||
const float ratio=(float)g_sizex/g_sizey;
|
||||
imageRect.size.height=imageRect.size.width/ratio;
|
||||
imageRect.origin.y=(full_height-imageRect.size.height)/2;
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
|
||||
CGDataProviderRef dataProvider = CGDataProviderCreateWithData(NULL, g_pImg, 4*g_sizex*g_sizey, NULL);
|
||||
|
||||
CGImageRef inputImage = CGImageCreate(g_sizex, g_sizey, 8, 32, g_sizex * 4, colourSpace,(CGBitmapInfo)kCGImageAlphaNoneSkipLast, dataProvider, NULL, NO, kCGRenderingIntentDefault);
|
||||
UIImage *image = [UIImage imageWithCGImage:inputImage];
|
||||
|
||||
CGDataProviderRelease(dataProvider);
|
||||
CGColorSpaceRelease(colourSpace);
|
||||
CGImageRelease(inputImage);
|
||||
|
||||
[image drawInRect:imageRect];
|
||||
|
||||
}
|
||||
|
||||
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
|
||||
{
|
||||
CGPoint point = [[touches anyObject] locationInView:self];
|
||||
const int x = point.x;
|
||||
const int y = point.y;
|
||||
if ( (y-imageRect.origin.y) > 0 && y < (imageRect.origin.y + imageRect.size.height ))
|
||||
on_mouse_func( x*g_sizex/(imageRect.size.width), (y-imageRect.origin.y)*g_sizey/imageRect.size.height,1);
|
||||
[self setNeedsDisplay];
|
||||
}
|
||||
|
||||
-(void) update_window{
|
||||
if( cocoa_update ) [self setNeedsDisplay];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#elif TARGET_OS_MAC
|
||||
|
||||
#import <OpenGL/gl.h>
|
||||
|
||||
@implementation OpenGLView
|
||||
|
||||
@synthesize timer;
|
||||
|
||||
- (void) drawRect:(NSRect)start
|
||||
{
|
||||
if (initialized == false) {
|
||||
NSLog(@"INITIALIZE");
|
||||
timer = [NSTimer scheduledTimerWithTimeInterval:0.03 target:self selector:@selector(update_window) userInfo:nil repeats:YES];
|
||||
initialized = true;
|
||||
}
|
||||
glWindowPos2i(0, (int)self.visibleRect.size.height);
|
||||
glPixelZoom( (float)self.visibleRect.size.width /(float)g_sizex,
|
||||
-(float)self.visibleRect.size.height/(float)g_sizey);
|
||||
glDrawPixels(g_sizex, g_sizey, GL_BGRA_EXT, GL_UNSIGNED_INT_8_8_8_8_REV, g_pImg);
|
||||
glFlush();
|
||||
}
|
||||
|
||||
-(void) update_window{
|
||||
if( cocoa_update ) [self setNeedsDisplay:YES];
|
||||
if( window_title ) [self.window setTitle:[NSString stringWithFormat:@"%s", window_title]];
|
||||
}
|
||||
|
||||
-(void) keyDown:(NSEvent *)theEvent{
|
||||
on_key_func([theEvent.characters characterAtIndex:0]);
|
||||
}
|
||||
|
||||
-(void) mouseDown:(NSEvent *)theEvent{
|
||||
// mouse event for seismic and fractal
|
||||
NSPoint point= theEvent.locationInWindow;
|
||||
const int x = (int)point.x;
|
||||
const int y = (int)point.y;
|
||||
NSRect rect = self.visibleRect;
|
||||
on_mouse_func(x*g_sizex/(int)rect.size.width,((int)rect.size.height-y)*g_sizey/(int)rect.size.height,1);
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
- (BOOL) acceptsFirstResponder
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void) rightMouseDown:(NSEvent *)theEvent
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
-(void) viewDidEndLiveResize
|
||||
{
|
||||
NSRect rect = self.visibleRect;
|
||||
const int x=(int)rect.size.width;
|
||||
const int y=(int)rect.size.height;
|
||||
[self.window setTitle:[NSString stringWithFormat:@"X=%d Y=%d", x,y]];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
@@ -0,0 +1 @@
|
||||
APPL????
|
@@ -0,0 +1,2 @@
|
||||
/* Localized versions of Info.plist keys */
|
||||
|
BIN
cs440-acg/ext/tbb/examples/common/gui/xcode/tbbExample/en.lproj/MainMenu.nib
generated
Normal file
BIN
cs440-acg/ext/tbb/examples/common/gui/xcode/tbbExample/en.lproj/MainMenu.nib
generated
Normal file
Binary file not shown.
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9060" systemVersion="15B42" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9060"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
|
||||
<connections>
|
||||
<outlet property="delegate" destination="494" id="495"/>
|
||||
</connections>
|
||||
</customObject>
|
||||
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
|
||||
<customObject id="-3" userLabel="Application"/>
|
||||
<menu title="AMainMenu" systemMenu="main" id="29">
|
||||
<items>
|
||||
<menuItem title="tbbExample" id="56">
|
||||
<menu key="submenu" title="tbbExample" systemMenu="apple" id="57">
|
||||
<items>
|
||||
<menuItem title="Quit tbbExample" keyEquivalent="q" id="136">
|
||||
<connections>
|
||||
<action selector="terminate:" target="-3" id="449"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
<window title="tbbExample" allowsToolTipsWhenApplicationIsInactive="NO" deferred="NO" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" animationBehavior="default" id="371">
|
||||
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
|
||||
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
|
||||
<rect key="contentRect" x="100" y="100" width="480" height="360"/>
|
||||
<rect key="screenRect" x="0.0" y="0.0" width="1280" height="1002"/>
|
||||
<view key="contentView" focusRingType="none" horizontalHuggingPriority="1" verticalHuggingPriority="9" horizontalCompressionResistancePriority="1" verticalCompressionResistancePriority="1" id="372" customClass="OpenGLView">
|
||||
<rect key="frame" x="0.0" y="0.0" width="480" height="360"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<animations/>
|
||||
</view>
|
||||
</window>
|
||||
<customObject id="494" customClass="tbbAppDelegate">
|
||||
<connections>
|
||||
<outlet property="window" destination="371" id="532"/>
|
||||
</connections>
|
||||
</customObject>
|
||||
<customObject id="420" customClass="NSFontManager"/>
|
||||
</objects>
|
||||
</document>
|
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9060" systemVersion="15B42" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="AKo-RD-jUr">
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9051"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--View Controller-->
|
||||
<scene sceneID="aF8-QV-POo">
|
||||
<objects>
|
||||
<viewController id="AKo-RD-jUr" sceneMemberID="viewController">
|
||||
<layoutGuides>
|
||||
<viewControllerLayoutGuide type="top" id="SEe-ff-xUc"/>
|
||||
<viewControllerLayoutGuide type="bottom" id="Cp9-IV-SKb"/>
|
||||
</layoutGuides>
|
||||
<view key="view" contentMode="scaleToFill" id="1aY-my-944" customClass="OpenGLView">
|
||||
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<animations/>
|
||||
<color key="backgroundColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
|
||||
</view>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="wcZ-9q-FxX" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="90" y="88"/>
|
||||
</scene>
|
||||
</scenes>
|
||||
</document>
|
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
Copyright (c) 2005-2020 Intel Corporation
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#import <Availability.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "tbbAppDelegate.h"
|
||||
|
||||
void get_screen_resolution(int *x, int *y) {
|
||||
// Getting landscape screen resolution in any case
|
||||
CGRect imageRect = [[UIScreen mainScreen] bounds];
|
||||
*x=imageRect.size.width>imageRect.size.height?imageRect.size.width:imageRect.size.height;
|
||||
*y=imageRect.size.width<imageRect.size.height?imageRect.size.width:imageRect.size.height;
|
||||
return;
|
||||
}
|
||||
|
||||
int cocoa_main(int argc, char * argv[]) {
|
||||
@autoreleasepool {
|
||||
return UIApplicationMain(argc, argv, nil, NSStringFromClass([tbbAppDelegate class]));
|
||||
}
|
||||
}
|
||||
|
||||
#elif TARGET_OS_MAC
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
int cocoa_main(int argc, char *argv[])
|
||||
{
|
||||
return NSApplicationMain(argc, (const char **)argv);
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
Copyright (c) 2005-2020 Intel Corporation
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
//
|
||||
// Created by Xcode* 4.3.2
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface tbbAppDelegate : UIResponder <UIApplicationDelegate>
|
||||
|
||||
@property (strong, nonatomic) UIWindow *window;
|
||||
|
||||
@end
|
||||
|
||||
#elif TARGET_OS_MAC
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@interface tbbAppDelegate : NSObject <NSApplicationDelegate>{
|
||||
__unsafe_unretained NSWindow *_window;
|
||||
}
|
||||
|
||||
@property (assign) IBOutlet NSWindow *window;
|
||||
|
||||
- (BOOL) applicationShouldTerminateAfterLastWindowClosed:(NSApplication *) sender;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
Copyright (c) 2005-2020 Intel Corporation
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#import "tbbAppDelegate.h"
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
@implementation tbbAppDelegate
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)applicationDidEnterBackground:(UIApplication *)application
|
||||
{
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#elif TARGET_OS_MAC
|
||||
|
||||
@implementation tbbAppDelegate
|
||||
|
||||
@synthesize window = _window;
|
||||
|
||||
//declared in macvideo.cpp file
|
||||
extern int g_sizex, g_sizey;
|
||||
|
||||
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
|
||||
{
|
||||
// Insert code here to initialize your application
|
||||
NSRect windowSize;
|
||||
windowSize.size.height = g_sizey;
|
||||
windowSize.size.width = g_sizex;
|
||||
windowSize.origin=_window.frame.origin;
|
||||
[_window setFrame:windowSize display:YES];
|
||||
|
||||
}
|
||||
|
||||
- (BOOL) applicationShouldTerminateAfterLastWindowClosed:(NSApplication *) sender
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>iOS</string>
|
||||
<key>UIMainStoryboardFile</key>
|
||||
<string>iOS</string>
|
||||
<key>UIRequiredDeviceCapabilities</key>
|
||||
<array>
|
||||
<string>armv7</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations~ipad</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleDisplayName</key>
|
||||
<string></string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>${EXECUTABLE_NAME}</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string></string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>${PRODUCT_NAME}</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
<string>public.app-category.business</string>
|
||||
<key>LSEnvironment</key>
|
||||
<dict>
|
||||
<key>DYLD_LIBRARY_PATH</key>
|
||||
<string>Contents/Resources:.:../Resources:/tmp:$DYLD_LIBRARY_PATH</string>
|
||||
<key>LIBRARY_PATH</key>
|
||||
<string>Contents/Resources:.:../:/tmp:$DYLD_LIBRARY_PATH</string>
|
||||
</dict>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright 2005-2020 Intel Corporation. All Rights Reserved.</string>
|
||||
<key>NSMainNibFile</key>
|
||||
<string>MainMenu</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
</dict>
|
||||
</plist>
|
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
Copyright (c) 2005-2020 Intel Corporation
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
//
|
||||
// Prefix header for all source files of the 'tbbExample' target in the 'tbbExample' project
|
||||
//
|
||||
|
||||
#import <Availability.h>
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
#ifdef __OBJC__
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
#endif
|
||||
#elif TARGET_OS_MAC
|
||||
#ifdef __OBJC__
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#endif
|
||||
#endif
|
382
cs440-acg/ext/tbb/examples/common/gui/xvideo.cpp
Normal file
382
cs440-acg/ext/tbb/examples/common/gui/xvideo.cpp
Normal file
@@ -0,0 +1,382 @@
|
||||
/*
|
||||
Copyright (c) 2005-2020 Intel Corporation
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
// Uncomment next line to disable shared memory features if you do not have libXext
|
||||
// (http://www.xfree86.org/current/mit-shm.html)
|
||||
//#define X_NOSHMEM
|
||||
|
||||
// Note that it may happen that the build environment supports the shared-memory extension
|
||||
// (so there's no build-time reason to disable the relevant code by defining X_NOSHMEM),
|
||||
// but that using shared memory still fails at run time.
|
||||
// This situation will (ultimately) cause the error handler set by XSetErrorHandler()
|
||||
// to be invoked with XErrorEvent::minor_code==X_ShmAttach. The code below tries to make
|
||||
// such a determination at XShmAttach() time, which seems plausible, but unfortunately
|
||||
// it has also been observed in a specific environment that the error may be reported
|
||||
// at a later time instead, even after video::init_window() has returned.
|
||||
// It is not clear whether this may happen in that way in any environment where it might
|
||||
// depend on the kind of display, e.g., local vs. over "ssh -X", so #define'ing X_NOSHMEM
|
||||
// may not always be the appropriate solution, therefore an environment variable
|
||||
// has been introduced to disable shared memory at run time.
|
||||
// A diagnostic has been added to advise the user about possible workarounds.
|
||||
// X_ShmAttach macro was changed to 1 due to recent changes to X11/extensions/XShm.h header.
|
||||
|
||||
#include "video.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/keysym.h>
|
||||
#include <sys/time.h>
|
||||
#include <signal.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#ifndef X_NOSHMEM
|
||||
#include <errno.h>
|
||||
#include <X11/extensions/XShm.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
|
||||
static XShmSegmentInfo shmseginfo;
|
||||
static Pixmap pixmap = 0;
|
||||
static bool already_called_X_ShmAttach = false;
|
||||
static bool already_advised_about_NOSHMEM_workarounds = false;
|
||||
static const char* NOSHMEM_env_var_name = "TBB_EXAMPLES_X_NOSHMEM";
|
||||
#endif
|
||||
static char *display_name = NULL;
|
||||
static Display *dpy = NULL;
|
||||
static Screen *scrn;
|
||||
static Visual *vis;
|
||||
static Colormap cmap;
|
||||
static GC gc;
|
||||
static Window win, rootW;
|
||||
static int dispdepth = 0;
|
||||
static XGCValues xgcv;
|
||||
static XImage *ximage;
|
||||
static int x_error = 0;
|
||||
static int vidtype = 3;
|
||||
int g_sizex, g_sizey;
|
||||
static video *g_video = 0;
|
||||
unsigned int *g_pImg = 0;
|
||||
static int g_fps = 0;
|
||||
struct timeval g_time;
|
||||
static pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
Atom _XA_WM_DELETE_WINDOW = 0;// like in Xatom.h
|
||||
|
||||
///////////////////////////////////////////// public methods of video class ///////////////////////
|
||||
|
||||
video::video()
|
||||
{
|
||||
assert(g_video == 0);
|
||||
g_video = this; title = "Video"; calc_fps = running = false; updating = true;
|
||||
}
|
||||
|
||||
inline void mask2bits(unsigned int mask, unsigned int &save, depth_t &shift)
|
||||
{
|
||||
save = mask; if(!mask) { shift = dispdepth/3; return; }
|
||||
shift = 0; while(!(mask&1)) ++shift, mask >>= 1;
|
||||
int bits = 0; while(mask&1) ++bits, mask >>= 1;
|
||||
shift += bits - 8;
|
||||
}
|
||||
|
||||
int xerr_handler(Display* dpy_, XErrorEvent *error)
|
||||
{
|
||||
x_error = error->error_code;
|
||||
if(g_video) g_video->running = false;
|
||||
#ifndef X_NOSHMEM
|
||||
if (error->minor_code==1/*X_ShmAttach*/ && already_called_X_ShmAttach && !already_advised_about_NOSHMEM_workarounds)
|
||||
{
|
||||
char err[256]; XGetErrorText(dpy_, x_error, err, 255);
|
||||
fprintf(stderr, "Warning: Can't attach shared memory to display: %s (%d)\n", err, x_error);
|
||||
fprintf(stderr, "If you are seeing a black output window, try setting %s environment variable to 1"
|
||||
" to disable shared memory extensions (0 to re-enable, other values undefined),"
|
||||
" or rebuilding with X_NOSHMEM defined in " __FILE__ "\n", NOSHMEM_env_var_name);
|
||||
already_advised_about_NOSHMEM_workarounds = true;
|
||||
}
|
||||
#else
|
||||
(void) dpy_; // warning prevention
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool video::init_window(int xsize, int ysize)
|
||||
{
|
||||
{ //enclose local variables before fail label
|
||||
g_sizex = xsize; g_sizey = ysize;
|
||||
|
||||
// Open the display
|
||||
if (!dpy) {
|
||||
dpy = XOpenDisplay(display_name);
|
||||
if (!dpy) {
|
||||
fprintf(stderr, "Can't open X11 display %s\n", XDisplayName(display_name));
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
int theScreen = DefaultScreen(dpy);
|
||||
scrn = ScreenOfDisplay(dpy, theScreen);
|
||||
dispdepth = DefaultDepth(dpy, theScreen);
|
||||
XVisualInfo vinfo;
|
||||
if (!( (dispdepth >= 15 && dispdepth <= 32 && XMatchVisualInfo(dpy, theScreen, dispdepth, TrueColor, &vinfo) )
|
||||
|| XMatchVisualInfo(dpy, theScreen, 24, TrueColor, &vinfo)
|
||||
|| XMatchVisualInfo(dpy, theScreen, 32, TrueColor, &vinfo)
|
||||
|| XMatchVisualInfo(dpy, theScreen, 16, TrueColor, &vinfo)
|
||||
|| XMatchVisualInfo(dpy, theScreen, 15, TrueColor, &vinfo)
|
||||
)) {
|
||||
fprintf(stderr, "Display has no appropriate True Color visual\n");
|
||||
goto fail;
|
||||
}
|
||||
vis = vinfo.visual;
|
||||
depth = dispdepth = vinfo.depth;
|
||||
mask2bits(vinfo.red_mask, red_mask, red_shift);
|
||||
mask2bits(vinfo.green_mask, green_mask, green_shift);
|
||||
mask2bits(vinfo.blue_mask, blue_mask, blue_shift);
|
||||
rootW = RootWindow(dpy, theScreen);
|
||||
cmap = XCreateColormap(dpy, rootW, vis, AllocNone);
|
||||
XSetWindowAttributes attrs;
|
||||
attrs.backing_store = Always;
|
||||
attrs.colormap = cmap;
|
||||
attrs.event_mask = StructureNotifyMask|KeyPressMask|ButtonPressMask|ButtonReleaseMask;
|
||||
attrs.background_pixel = BlackPixelOfScreen(scrn);
|
||||
attrs.border_pixel = WhitePixelOfScreen(scrn);
|
||||
win = XCreateWindow(dpy, rootW,
|
||||
0, 0, xsize, ysize, 2,
|
||||
dispdepth, InputOutput, vis,
|
||||
CWBackingStore | CWColormap | CWEventMask |
|
||||
CWBackPixel | CWBorderPixel,
|
||||
&attrs);
|
||||
if(!win) {
|
||||
fprintf(stderr, "Can't create the window\n");
|
||||
goto fail;
|
||||
}
|
||||
XSizeHints sh;
|
||||
sh.flags = PSize | PMinSize | PMaxSize;
|
||||
sh.width = sh.min_width = sh.max_width = xsize;
|
||||
sh.height = sh.min_height = sh.max_height = ysize;
|
||||
XSetStandardProperties( dpy, win, g_video->title, g_video->title, None, NULL, 0, &sh );
|
||||
_XA_WM_DELETE_WINDOW = XInternAtom(dpy, "WM_DELETE_WINDOW", false);
|
||||
XSetWMProtocols(dpy, win, &_XA_WM_DELETE_WINDOW, 1);
|
||||
gc = XCreateGC(dpy, win, 0L, &xgcv);
|
||||
XMapRaised(dpy, win);
|
||||
XFlush(dpy);
|
||||
#ifdef X_FULLSYNC
|
||||
XSynchronize(dpy, true);
|
||||
#endif
|
||||
XSetErrorHandler(xerr_handler);
|
||||
|
||||
int imgbytes = xsize*ysize*(dispdepth<=16?2:4);
|
||||
const char *vidstr;
|
||||
#ifndef X_NOSHMEM
|
||||
int major, minor, pixmaps;
|
||||
if(XShmQueryExtension(dpy) &&
|
||||
XShmQueryVersion(dpy, &major, &minor, &pixmaps))
|
||||
{ // Shared memory
|
||||
if(NULL!=getenv(NOSHMEM_env_var_name) && 0!=strcmp("0",getenv(NOSHMEM_env_var_name))) {
|
||||
goto generic;
|
||||
}
|
||||
shmseginfo.shmid = shmget(IPC_PRIVATE, imgbytes, IPC_CREAT|0777);
|
||||
if(shmseginfo.shmid < 0) {
|
||||
fprintf(stderr, "Warning: Can't get shared memory: %s\n", strerror(errno));
|
||||
goto generic;
|
||||
}
|
||||
g_pImg = (unsigned int*)(shmseginfo.shmaddr = (char*)shmat(shmseginfo.shmid, 0, 0));
|
||||
if(g_pImg == (unsigned int*)-1) {
|
||||
fprintf(stderr, "Warning: Can't attach to shared memory: %s\n", strerror(errno));
|
||||
shmctl(shmseginfo.shmid, IPC_RMID, NULL);
|
||||
goto generic;
|
||||
}
|
||||
shmseginfo.readOnly = false;
|
||||
if(!XShmAttach(dpy, &shmseginfo) || x_error) {
|
||||
char err[256]; XGetErrorText(dpy, x_error, err, 255);
|
||||
fprintf(stderr, "Warning: Can't attach shared memory to display: %s (%d)\n", err, x_error);
|
||||
shmdt(shmseginfo.shmaddr); shmctl(shmseginfo.shmid, IPC_RMID, NULL);
|
||||
goto generic;
|
||||
}
|
||||
already_called_X_ShmAttach = true;
|
||||
|
||||
#ifndef X_NOSHMPIX
|
||||
if(pixmaps && XShmPixmapFormat(dpy) == ZPixmap)
|
||||
{ // Pixmaps
|
||||
vidtype = 2; vidstr = "X11 shared memory pixmap";
|
||||
pixmap = XShmCreatePixmap(dpy, win, (char*)g_pImg, &shmseginfo, xsize, ysize, dispdepth);
|
||||
XSetWindowBackgroundPixmap(dpy, win, pixmap);
|
||||
} else
|
||||
#endif//!X_NOSHMPIX
|
||||
{ // Standard
|
||||
vidtype = 1; vidstr = "X11 shared memory";
|
||||
ximage = XShmCreateImage(dpy, vis, dispdepth,
|
||||
ZPixmap, 0, &shmseginfo, xsize, ysize);
|
||||
if(!ximage) {
|
||||
fprintf(stderr, "Can't create the shared image\n");
|
||||
goto fail;
|
||||
}
|
||||
assert(ximage->bytes_per_line == xsize*(dispdepth<=16?2:4));
|
||||
ximage->data = shmseginfo.shmaddr;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
#ifndef X_NOSHMEM
|
||||
generic:
|
||||
#endif
|
||||
vidtype = 0; vidstr = "generic X11";
|
||||
g_pImg = new unsigned int[imgbytes/sizeof(int)];
|
||||
ximage = XCreateImage(dpy, vis, dispdepth, ZPixmap, 0, (char*)g_pImg, xsize, ysize, 32, imgbytes/ysize);
|
||||
if(!ximage) {
|
||||
fprintf(stderr, "Can't create the image\n");
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
if( ximage ) {
|
||||
// Note: It may be more efficient to adopt the server's byte order
|
||||
// and swap once per get_color() call instead of once per pixel.
|
||||
const uint32_t probe = 0x03020100;
|
||||
const bool big_endian = (((const char*)(&probe))[0]==0x03);
|
||||
ximage->byte_order = big_endian ? MSBFirst : LSBFirst;
|
||||
}
|
||||
printf("Note: using %s with %s visual for %d-bit color depth\n", vidstr, vis==DefaultVisual(dpy, theScreen)?"default":"non-default", dispdepth);
|
||||
running = true;
|
||||
return true;
|
||||
} // end of enclosing local variables
|
||||
fail:
|
||||
terminate(); init_console();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool video::init_console()
|
||||
{
|
||||
if(!g_pImg && g_sizex && g_sizey) {
|
||||
dispdepth = 24; red_shift = 16; vidtype = 3; // fake video
|
||||
g_pImg = new unsigned int[g_sizex*g_sizey];
|
||||
running = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void video::terminate()
|
||||
{
|
||||
running = false;
|
||||
if(dpy) {
|
||||
vidtype = 3; // stop video
|
||||
if(threaded) { pthread_mutex_lock(&g_mutex); pthread_mutex_unlock(&g_mutex); }
|
||||
if(ximage) { XDestroyImage(ximage); ximage = 0; g_pImg = 0; } // it frees g_pImg for vidtype == 0
|
||||
#ifndef X_NOSHMEM
|
||||
if(pixmap) XFreePixmap(dpy, pixmap);
|
||||
if(shmseginfo.shmaddr) { XShmDetach(dpy, &shmseginfo); shmdt(shmseginfo.shmaddr); g_pImg = 0; }
|
||||
if(shmseginfo.shmid >= 0) shmctl(shmseginfo.shmid, IPC_RMID, NULL);
|
||||
#endif
|
||||
if(gc) XFreeGC(dpy, gc);
|
||||
if(win) XDestroyWindow(dpy, win);
|
||||
XCloseDisplay(dpy); dpy = 0;
|
||||
}
|
||||
if(g_pImg) { delete[] g_pImg; g_pImg = 0; } // if was allocated for console mode
|
||||
}
|
||||
|
||||
video::~video()
|
||||
{
|
||||
if(g_video) terminate();
|
||||
g_video = 0;
|
||||
}
|
||||
|
||||
//! Do standard event loop
|
||||
void video::main_loop()
|
||||
{
|
||||
struct timezone tz; gettimeofday(&g_time, &tz);
|
||||
on_process();
|
||||
}
|
||||
|
||||
//! Check for pending events once
|
||||
bool video::next_frame()
|
||||
{
|
||||
if(!running) return false;
|
||||
//! try acquire mutex if threaded code, returns on failure
|
||||
if(vidtype == 3 || threaded && pthread_mutex_trylock(&g_mutex))
|
||||
return running;
|
||||
//! Refresh screen picture
|
||||
g_fps++;
|
||||
#ifndef X_NOSHMPIX
|
||||
if(vidtype == 2 && updating) XClearWindow(dpy, win);
|
||||
#endif
|
||||
while( XPending(dpy) ) {
|
||||
XEvent report; XNextEvent(dpy, &report);
|
||||
switch( report.type ) {
|
||||
case ClientMessage:
|
||||
if(report.xclient.format != 32 || report.xclient.data.l[0] != _XA_WM_DELETE_WINDOW) break;
|
||||
case DestroyNotify:
|
||||
running = false;
|
||||
case KeyPress:
|
||||
on_key( XLookupKeysym(&report.xkey, 0) ); break;
|
||||
case ButtonPress:
|
||||
on_mouse( report.xbutton.x, report.xbutton.y, report.xbutton.button ); break;
|
||||
case ButtonRelease:
|
||||
on_mouse( report.xbutton.x, report.xbutton.y, -report.xbutton.button ); break;
|
||||
}
|
||||
}
|
||||
struct timezone tz; struct timeval now_time; gettimeofday(&now_time, &tz);
|
||||
double sec = (now_time.tv_sec+1.0*now_time.tv_usec/1000000.0) - (g_time.tv_sec+1.0*g_time.tv_usec/1000000.0);
|
||||
if(sec > 1) {
|
||||
memcpy(&g_time, &now_time, sizeof(g_time));
|
||||
if(calc_fps) {
|
||||
double fps = g_fps; g_fps = 0;
|
||||
char buffer[256]; snprintf(buffer, 256, "%s%s: %d fps", title, updating?"":" (no updating)", int(fps/sec));
|
||||
XStoreName(dpy, win, buffer);
|
||||
}
|
||||
#ifndef X_FULLSYNC
|
||||
XSync(dpy, false); // It is often better then using XSynchronize(dpy, true)
|
||||
#endif//X_FULLSYNC
|
||||
}
|
||||
if(threaded) pthread_mutex_unlock(&g_mutex);
|
||||
return true;
|
||||
}
|
||||
|
||||
//! Change window title
|
||||
void video::show_title()
|
||||
{
|
||||
if(vidtype < 3)
|
||||
XStoreName(dpy, win, title);
|
||||
}
|
||||
|
||||
drawing_area::drawing_area(int x, int y, int sizex, int sizey)
|
||||
: base_index(y*g_sizex + x), max_index(g_sizex*g_sizey), index_stride(g_sizex),
|
||||
pixel_depth(dispdepth), ptr32(g_pImg), start_x(x), start_y(y), size_x(sizex), size_y(sizey)
|
||||
{
|
||||
assert(x < g_sizex); assert(y < g_sizey);
|
||||
assert(x+sizex <= g_sizex); assert(y+sizey <= g_sizey);
|
||||
|
||||
index = base_index; // current index
|
||||
}
|
||||
|
||||
void drawing_area::update()
|
||||
{
|
||||
if(!g_video->updating) return;
|
||||
#ifndef X_NOSHMEM
|
||||
switch(vidtype) {
|
||||
case 0:
|
||||
#endif
|
||||
pthread_mutex_lock(&g_mutex);
|
||||
if(vidtype == 0) XPutImage(dpy, win, gc, ximage, start_x, start_y, start_x, start_y, size_x, size_y);
|
||||
pthread_mutex_unlock(&g_mutex);
|
||||
#ifndef X_NOSHMEM
|
||||
break;
|
||||
case 1:
|
||||
pthread_mutex_lock(&g_mutex);
|
||||
if(vidtype == 1) XShmPutImage(dpy, win, gc, ximage, start_x, start_y, start_x, start_y, size_x, size_y, false);
|
||||
pthread_mutex_unlock(&g_mutex);
|
||||
break;
|
||||
/*case 2: make it in next_frame(); break;*/
|
||||
}
|
||||
#endif
|
||||
}
|
Reference in New Issue
Block a user