summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/SourceWin32.cxx301
1 files changed, 43 insertions, 258 deletions
diff --git a/src/SourceWin32.cxx b/src/SourceWin32.cxx
index 620bb01..1007e35 100644
--- a/src/SourceWin32.cxx
+++ b/src/SourceWin32.cxx
@@ -199,138 +199,46 @@ class SourceWin32 extends Source, Runnable
DeleteObject( m_bitmap2 );
}
- private void addRect( const RECT &rect ) {
- if (rect.left >= rect.right)
- return;
-
- if (rect.top >= rect.bottom)
- return;
-
- DFBRegion region( rect.left,
- rect.top,
- rect.right - 1,
- rect.bottom - 1 );
-
- m_updates.addRegion( region );
- }
-
private void run() {
- if (m_using_driver) {
- D_ASSERT( m_driver.mypchangebuf != NULL );
-
- unsigned int counter = m_driver.mypchangebuf->counter;
- unsigned int i;
-
- long long last_time = direct_clock_get_abs_millis();
-
- D_DEBUG_AT( PluggIt_SourceWin32, "%s()\n", __FUNCTION__ );
-
- while (!m_thread->isInterrupted()) {
- if (m_driver.mypchangebuf->counter < 1 ||
- m_driver.mypchangebuf->counter >= MAXCHANGES_BUF ||
- counter == m_driver.mypchangebuf->counter)
- usleep( 10000 );
-
- if (counter != m_driver.mypchangebuf->counter) {
- D_DEBUG_AT( PluggIt_SourceWin32, " -> counter: %d -> %d\n", counter, m_driver.mypchangebuf->counter );
-
- if (counter < m_driver.mypchangebuf->counter) {
- for (i=counter+1; i<=m_driver.mypchangebuf->counter; i++) {
- addRect( m_driver.mypchangebuf->pointrect[i].rect );
- }
- }
- else if (counter > m_driver.mypchangebuf->counter) {
- for (i=counter+1; i<MAXCHANGES_BUF; i++) {
- addRect( m_driver.mypchangebuf->pointrect[i].rect );
- }
- for (i=1; i<=m_driver.mypchangebuf->counter; i++) {
- addRect( m_driver.mypchangebuf->pointrect[i].rect );
- }
- }
-
- counter = m_driver.mypchangebuf->counter;
- }
-
- if (direct_clock_get_abs_millis() - last_time > 2000) {
- DFBRegion region( 0,
- 0,
- m_size.w - 1,
- m_size.h - 1 );
-
- m_updates.addRegion( region );
-
- last_time = direct_clock_get_abs_millis();
- }
-
- if (m_updates.num_regions() > 0) {
- vector<DFBRectangle_C> rects;
-
- m_updates.GetRectangles( rects );
-
-
- const DFBRegion &bounding = m_updates.bounding();
-
- D_DEBUG_AT( PluggIt_SourceWin32, " -> %4d,%4d-%4dx%4d (%d regions, %d rectangles)\n",
- DFB_RECTANGLE_VALS_FROM_REGION( &bounding ), m_updates.num_regions(), rects.size() );
-
- m_updates.reset();
-
- flushUpdates( rects );
- }
- }
- }
- else {
- D_DEBUG_AT( PluggIt_SourceWin32, "%s()\n", __FUNCTION__ );
-
- long long last_time = direct_clock_get_abs_millis();
-
- while (!m_thread->isInterrupted()) {
-/* if (((const Config&)m_config).m_updating) {
- usleep( 100000 );
+ D_DEBUG_AT( PluggIt_SourceWin32, "%s()\n", __FUNCTION__ );
- queueUpdate( 0, 0, m_size.w - 1, m_size.h - 1 );
+ while (!m_thread->isInterrupted()) {
+ pthread_mutex_lock( &m_lock );
- pthread_mutex_lock( &m_lock );
- }
- else*/ {
- pthread_mutex_lock( &m_lock );
+ while (m_updates.num_regions() == 0)
+ pthread_cond_wait( &m_cond, &m_lock );
- if (m_updates.num_regions() == 0)
- //usleep( 10000 );
- pthread_cond_wait( &m_cond, &m_lock );
- }
- if (direct_clock_get_abs_millis() - last_time > 2000) {
- DFBRegion region( 0,
- 0,
- m_size.w - 1,
- m_size.h - 1 );
+ vector<DFBRectangle_C> rects;
- //m_updates.addRegion( region );
+ m_updates.GetRectangles( rects );
- last_time = direct_clock_get_abs_millis();
- }
+ const DFBRegion &bounding = m_updates.bounding();
- vector<DFBRectangle_C> rects;
+ D_DEBUG_AT( PluggIt_SourceWin32, " -> %4d,%4d-%4dx%4d (%d regions, %d rectangles)\n",
+ DFB_RECTANGLE_VALS_FROM_REGION( &bounding ), m_updates.num_regions(), rects.size() );
- if (m_updates.num_regions() > 0) {
- m_updates.GetRectangles( rects );
+ m_updates.reset();
- const DFBRegion &bounding = m_updates.bounding();
+ pthread_mutex_unlock( &m_lock );
- D_DEBUG_AT( PluggIt_SourceWin32, " -> %4d,%4d-%4dx%4d (%d regions, %d rectangles)\n",
- DFB_RECTANGLE_VALS_FROM_REGION( &bounding ), m_updates.num_regions(), rects.size() );
- m_updates.reset();
- }
+ for (unsigned int i=0; i<rects.size(); i++) {
+ BitBlt( m_bitmap_dc,
+ rects[i].x,
+ rects[i].y,
+ rects[i].w,
+ rects[i].h,
+ m_window_dc,
+ rects[i].x,
+ rects[i].y,
+ SRCCOPY );
+ }
- pthread_mutex_unlock( &m_lock );
- if (!rects.empty())
- flushUpdates( rects );
- }
+ m_view->update( rects, (void*)((char*) m_pixels + m_pitch * (m_size.h - 1)), - m_pitch );
}
}
@@ -350,35 +258,6 @@ class SourceWin32 extends Source, Runnable
pthread_mutex_unlock( &m_lock );
}
- private bool flushUpdates( vector<DFBRectangle_C> &rects ) {
- D_DEBUG_AT( PluggIt_SourceWin32, "%s()\n", __FUNCTION__ );
-
- if (m_using_driver) {
- m_view->update( rects, m_driver.myframebuffer, m_pitch );
- }
- else {
- for (unsigned int i=0; i<rects.size(); i++) {
- BitBlt( m_bitmap_dc,
- rects[i].x,
- rects[i].y,
- rects[i].w,
- rects[i].h,
- m_window_dc,
- rects[i].x,
- rects[i].y,
- SRCCOPY );
- }
-
- m_view->update( rects, (void*)((char*) m_pixels + m_pitch * (m_size.h - 1)), - m_pitch );
- }
-
- D_DEBUG_AT( PluggIt_SourceWin32, " -> flush done\n" );
-
- return true;
- }
-
-
-
/**********************************************************************************************************************/
private static std::string getWindowTitle( HWND window ) {
@@ -567,126 +446,32 @@ class SourceWin32 extends Source, Runnable
/**********************************************************************************************************************/
- static LRESULT CALLBACK DesktopWndProc( HWND hwnd, // handle to window
- UINT uMsg, // message identifier
- WPARAM wParam, // first message parameter
- LPARAM lParam ) // second message parameter
- {
- PCOPYDATASTRUCT CDS;
- SourceWin32 *thiz = (SourceWin32*)GetWindowLong(hwnd, GWL_USERDATA);
-
- switch (uMsg) {
- case WM_DESTROY:
- PostQuitMessage( 0 );
- break;
-
- case WM_COPYDATA:
- CDS = (PCOPYDATASTRUCT) lParam;
-
- if (CDS->dwData==112233) {
- DWORD mysize = CDS->cbData;
- char mytext[1024];
- char *myptr;
- char split[4][6];
-
- strcpy( mytext, (LPCSTR) CDS->lpData );
-
- myptr = mytext;
-
- for (int j =0; j<(mysize/20);j++) {
- for (int i=0;i<4;i++) {
- strcpy(split[i]," ");
- strncpy(split[i],myptr,4);
- myptr = myptr+5;
- }
-
- thiz->queueUpdate( atoi(split[0]),
- atoi(split[1]),
- atoi(split[2]) - 1,
- atoi(split[3]) - 1 );
- }
-
- }
- break;
-
- default:
- return DefWindowProc( hwnd, uMsg, wParam, lParam );
- }
-
- return 0;
- }
-
public virtual int MainLoop() {
- if (!m_using_driver) {
- HMODULE hModule;
- char szCurrentDir[MAX_PATH];
-
- if (GetModuleFileName(NULL, szCurrentDir, MAX_PATH)) {
- char* p = strrchr(szCurrentDir, '\\');
- if (p == NULL) return 0;
- *p = '\0';
- strcat (szCurrentDir,"\\vnchooks.dll");
- }
-
- hModule = LoadLibrary( szCurrentDir );
- if (!hModule)
- throw new Exception( "Failed to load vnchooks.dll!" );
-
- SetHooks = (SetHooksFn) GetProcAddress( hModule, "SetHooks" );
-
-
-
-
+ HMODULE hModule;
+ char szCurrentDir[MAX_PATH];
- HWND w;
-
- WNDCLASSEX wndClass;
-
- ZeroMemory( &wndClass, sizeof(wndClass) );
-
- wndClass.cbSize = sizeof(wndClass);
- wndClass.style = 0;
- wndClass.lpfnWndProc = DesktopWndProc;
- wndClass.cbClsExtra = 0;
- wndClass.cbWndExtra = 0;
- wndClass.hInstance = GetModuleHandle(NULL);
- wndClass.hIcon = NULL;
- wndClass.hIconSm = NULL;
- wndClass.hCursor = NULL;
- wndClass.hbrBackground = (HBRUSH) GetStockObject( WHITE_BRUSH );
- wndClass.lpszMenuName = NULL;
- wndClass.lpszClassName = szDesktopSink;
-
- if (!RegisterClassEx( &wndClass ))
- throw new Exception( "RegisterClassEx() failed!" );
+ if (GetModuleFileName(NULL, szCurrentDir, MAX_PATH)) {
+ char* p = strrchr(szCurrentDir, '\\');
+ if (p == NULL) return 0;
+ *p = '\0';
+ strcat (szCurrentDir,"\\vnchooks.dll");
+ }
+ hModule = LoadLibrary( szCurrentDir );
+ if (!hModule)
+ throw new Exception( "Failed to load vnchooks.dll!" );
- w = CreateWindowEx( 0,
- szDesktopSink,
- "WinVNC",
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- 400, 200,
- NULL,
- NULL,
- GetModuleHandle(NULL),
- NULL );
- if (!w)
- throw new Exception( "Failed to create hook window!" );
+ SetHooks = (SetHooksFn) GetProcAddress( hModule, "SetHooks" );
- // Set the "this" pointer for the window
- SetWindowLong( w, GWL_USERDATA, (long)this);
- if (!SetHooks(
- GetCurrentThreadId(),
- RFB_SCREEN_UPDATE,
- RFB_COPYRECT_UPDATE,
- RFB_MOUSE_UPDATE, false
- ))
- throw new Exception( "Failed to set hooks!" );
- }
+ if (!SetHooks(
+ GetCurrentThreadId(),
+ RFB_SCREEN_UPDATE,
+ RFB_COPYRECT_UPDATE,
+ RFB_MOUSE_UPDATE, false
+ ))
+ throw new Exception( "Failed to set hooks!" );
MSG msg;