Changeset 3997

Show
Ignore:
Timestamp:
2005年12月13日 22時48分17秒 (3 years ago)
Author:
horiguti
Message:

Update for changing HDC handling.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/ChangeLog.Meadow

    r3996 r3997  
     12005-12-13  Kyotaro HORIGUCHI  <horiguti@meadowy.org> 
     2 
     3        * dispnew.c (adjust_glyphs): Remove W32_BLOCK_INPUT, 
     4        W32_UNBLOCK_INPUT. 
     5        (free_glyphs): Ditto. 
     6        (update_single_window): Ditto. 
     7        (change_frame_size_1): Ditto. 
     8        (update_frame): Ditto. Do GET_FRAME_HDC(), RELEASE_FRAME_HDC(). 
     9 
     10        * mw32term.c (main_thread_hdc): New variable. 
     11        (main_thread_hdc_nestlevel): Ditto. 
     12        (main_thread_hdc_hwnd): Ditto. 
     13        (mw32_destroy_frame_hdc): Release main thread DC on destroying the 
     14        owner frame. 
     15        (mw32_set_caret): Remove W32_BLOCK_INPUT/W32_UNBLOCK_INPUT. Avoid 
     16        unnecessary call to message thread. 
     17        (MW32_update_begin): Changed. Do blocking of caret. 
     18        (MW32_update_end): Changed. Do unblocking of caret. 
     19        (MW32_frame_up_to_date): Remove W32_BLOCK_INPUT/W32_UNBLOCK_INPUT. 
     20        (mw32_get_ime_font_property): Remove treatment for 
     21        W32_BLOCK_INPUT. 
     22        (mw32_process_main_thread_message<WM_EMACS_EXPOSE_FRAME>): 
     23        Removed. 
     24        (unwind_get_device_capability): Alter RELEASE_TEMP_HDC with 
     25        RELEASE_FRAME_HDC. 
     26        (mw32-get-device-capability): Alter GET_TEMP_HDC with 
     27        GET_FRAME_HDC. 
     28 
     29        * mw32term.h (main_thread_hdc): New extern. 
     30        (main_thread_hdc_nestlevel): Ditto. 
     31        (main_thread_hdc_hwnd): Ditto. 
     32        (struct mw32_output): Rename member hdc_refcount to hdc_nestlevel, 
     33        message_thread_hdc to hdc. Removed members message_thread_hdc and 
     34        message_thread_hdc_refcount. 
     35        (FRAME_HDC): Changed. 
     36        (GET_FRAME_HDC): Changed. 
     37        (RELEASE_FRAME_HDC): Ditto. 
     38        (GET_TEMP_HDC): Removed. 
     39        (RELEASE_TEMP_HDC): Ditto. 
     40        (CLEANUP_FRAME_HDC): New macro. 
     41        (FRAME_HDC_VALID_P): Changed. 
     42        (update_begin_hook): New extern. 
     43        (update_end_hook): Ditto. 
     44 
     45        * mw32sync.h (main_thread_id): New extern. 
     46        (W32_BLOCK_INPUT): Removed. 
     47        (W32_UNBLOCK_INPUT): Removed. 
     48 
     49        * mw32fns.c (mw32m_new_focus_frame): Variable name for hdc is 
     50        changed. Remove W32_BLOCK_INPUT/W32_UNBLOCK_INPUT. 
     51        (mw32_WndProc<WM_ERASEBKGND>): Variable names for hdc are changed. 
     52        (mw32_WndProc<WM_PAINT>): Variable name for hdc is changed. Remove 
     53        W32_BLOCK_INPUT/W32_UNBLOCK_INPUT. 
     54        (mw32_WndProc<WM_SETFOCUS>): Synchronizing caret state. 
     55        (mw32_WndProc<WM_KILLFOCUS>): Ditto. 
     56        (mw32_WndProc<WM_EMACS_SETCARET>): Changed. 
     57        (x-create-frame): Variable names for hdc are changed. Replace 
     58        GET_TEMP_HDC with GET_FRAME_HDC. Also for RELEASE_*. 
     59        (mw32_create_tip_frame)Variable names for hdc are changed. 
     60 
     61        * mw32font.c (mw32_load_lf): Replace GET_TEMP_HDC with 
     62        GET_FRAME_HDC. Also for RELEASE_*. 
     63 
     64        * image.c (get_image_data_from_icon): Ditto. 
     65 
     66        * xdisp.c (redisplay_internal): Cleanup main thread hdc. 
     67 
     68        * frame.c (delete-frame): Use GET_FRAME_HDC to block message 
     69        thread as alternative of W32_BLOCK_INPUT. 
     70 
     71        * window.c (delete_window): Remove 
     72        W32_BLOCK_INPUT/W32_UNBLOCK_INPUT. 
     73        (set-window-configuration): Ditto. 
     74 
    1752005-12-01  MIYOSHI Masanori  <miyoshi@meadowy.org> 
    276 
  • trunk/src/dispnew.c

    r3978 r3997  
    20812081  /* Block input so that expose events and other events that access 
    20822082     glyph matrices are not processed while we are changing them.  */ 
    2083 #ifdef MEADOW 
    2084   W32_BLOCK_INPUT; 
    2085 #endif 
    20862083  BLOCK_INPUT; 
    20872084 
     
    20972094 
    20982095  UNBLOCK_INPUT; 
    2099 #ifdef MEADOW 
    2100   W32_UNBLOCK_INPUT; 
    2101 #endif 
    21022096} 
    21032097 
     
    24942488      /* Block interrupt input so that we don't get surprised by an X 
    24952489         event while we're in an inconsistent state.  */ 
    2496 #ifdef MEADOW 
    2497       W32_BLOCK_INPUT; 
    2498 #endif 
    24992490      BLOCK_INPUT; 
    25002491      f->glyphs_initialized_p = 0; 
     
    25432534 
    25442535      UNBLOCK_INPUT; 
    2545 #ifdef MEADOW 
    2546       W32_UNBLOCK_INPUT; 
    2547 #endif 
    25482536    } 
    25492537} 
     
    38483836 
    38493837#ifdef MEADOW 
    3850   W32_BLOCK_INPUT
     3838  GET_FRAME_HDC (f)
    38513839#endif 
    38523840  if (FRAME_WINDOW_P (f)) 
     
    39283916    } 
    39293917#ifdef MEADOW 
    3930   W32_UNBLOCK_INPUT
     3918  RELEASE_FRAME_HDC (f)
    39313919#endif 
    39323920 
     
    39873975      /* Update W.  */ 
    39883976      update_begin (f); 
    3989 #ifdef MEADOW 
    3990       W32_BLOCK_INPUT; 
    3991 #endif 
    39923977      update_window (w, force_p); 
    3993 #ifdef MEADOW 
    3994       W32_UNBLOCK_INPUT; 
    3995 #endif 
    39963978      update_end (f); 
    39973979 
     
    62116193    return; 
    62126194 
    6213 #ifdef MEADOW 
    6214   W32_BLOCK_INPUT; 
    6215 #endif 
    62166195  BLOCK_INPUT; 
    62176196 
     
    62826261 
    62836262  UNBLOCK_INPUT; 
    6284 #ifdef MEADOW 
    6285   W32_UNBLOCK_INPUT; 
    6286 #endif 
    62876263 
    62886264  record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); 
  • trunk/src/eval.c

    r3945 r3997  
    16011601  if (gc_in_progress || waiting_for_input) 
    16021602    abort (); 
    1603  
    1604 #ifdef MEADOW 
    1605   if (W32_SELF_INPUT_BLOCKED_P) 
    1606     W32_UNBLOCK_INPUT; 
    1607 #endif /* MEADOW */ 
    16081603 
    16091604  if (NILP (error_symbol)) 
  • trunk/src/frame.c

    r3982 r3997  
    12771277  /* during destroying the windows, 
    12781278     we must block the message loop.  */ 
    1279   W32_BLOCK_INPUT; 
     1279  GET_FRAME_HDC (f); /* Use only side effect */ 
    12801280#endif 
    12811281  /* Free glyphs. 
     
    12901290  f->root_window = Qnil; 
    12911291#ifdef MEADOW 
    1292   W32_UNBLOCK_INPUT
     1292  RELEASE_FRAME_HDC (f)
    12931293#endif 
    12941294 
  • trunk/src/image.c

    r3990 r3997  
    1010510105  unsigned char *bmpdata; 
    1010610106  struct frame *f = SELECTED_FRAME (); 
    10107   HDC hdc = GET_TEMP_HDC (f); 
     10107  HDC hdc = GET_FRAME_HDC (f); 
    1010810108  HDC cdc = CreateCompatibleDC (hdc); 
    1010910109 
     
    1013510135  DeleteDC (cdc); 
    1013610136 
    10137   RELEASE_TEMP_HDC (f); 
     10137  RELEASE_FRAME_HDC (f); 
    1013810138} 
    1013910139 
  • trunk/src/mw32fns.c

    r3996 r3997  
    16981698      hdc1 = GetDC (FRAME_MW32_WINDOW (f)); 
    16991699      mw32_setup_default_hdc (hdc1); 
    1700       f->output_data.mw32->message_thread_hdc = hdc1; 
     1700      f->output_data.mw32->hdc = hdc1; 
    17011701    } 
    17021702  else 
     
    17071707      hdc2 = GetDC (FRAME_MW32_WINDOW (fold)); 
    17081708      mw32_setup_default_hdc (hdc2); 
    1709       fold->output_data.mw32->message_thread_hdc = hdc2; 
     1709      fold->output_data.mw32->hdc = hdc2; 
    17101710    } 
    17111711  else 
    17121712    hdc2 = INVALID_HANDLE_VALUE; 
    17131713 
    1714   W32_BLOCK_INPUT; 
    17151714  mw32_new_focus_frame (dpyinfo, f); 
    1716   W32_UNBLOCK_INPUT; 
    17171715 
    17181716  if (hdc1 != INVALID_HANDLE_VALUE) 
    17191717    { 
    1720       f->output_data.mw32->message_thread_hdc = INVALID_HANDLE_VALUE; 
     1718      f->output_data.mw32->hdc = INVALID_HANDLE_VALUE; 
    17211719      ReleaseDC (FRAME_MW32_WINDOW (f), hdc1); 
    17221720    } 
    17231721  if (hdc2 != INVALID_HANDLE_VALUE) 
    17241722    { 
    1725       fold->output_data.mw32->message_thread_hdc = INVALID_HANDLE_VALUE; 
     1723      fold->output_data.mw32->hdc = INVALID_HANDLE_VALUE; 
    17261724      ReleaseDC (FRAME_MW32_WINDOW (fold), hdc2); 
    17271725    } 
     
    19401938      HDC ohdc; 
    19411939 
    1942       orefcount = f->output_data.mw32->message_thread_hdc_refcount
    1943       ohdc = f->output_data.mw32->message_thread_hdc; 
    1944  
    1945       f->output_data.mw32->message_thread_hdc = (HDC) wParam; 
    1946       f->output_data.mw32->message_thread_hdc_refcount = 1; 
     1940      orefcount = f->output_data.mw32->hdc_nestlevel
     1941      ohdc = f->output_data.mw32->hdc; 
     1942 
     1943      f->output_data.mw32->hdc = (HDC) wParam; 
     1944      f->output_data.mw32->hdc_nestlevel = 1; 
    19471945 
    19481946      GetClientRect (FRAME_MW32_WINDOW (f), &rect); 
     
    19501948                                    rect.right, rect.bottom); 
    19511949 
    1952       f->output_data.mw32->message_thread_hdc = ohdc; 
    1953       f->output_data.mw32->message_thread_hdc_refcount = orefcount; 
     1950      f->output_data.mw32->hdc = ohdc; 
     1951      f->output_data.mw32->hdc_nestlevel = orefcount; 
    19541952 
    19551953      return 0; 
     
    19751973          /* Avoid conflicting with drawing in main thread. */ 
    19761974          EnterCriticalSection (&(f->output_data.mw32->hdc_critsec)); 
    1977           if (f->output_data.mw32->hdc == INVALID_HANDLE_VALUE) 
     1975          if (main_thread_hdc == INVALID_HANDLE_VALUE) 
    19781976            { 
    19791977              BeginPaint (FRAME_MW32_WINDOW (f), &ps); 
     
    19831981              GetClientRect (FRAME_MW32_WINDOW (f), &rc); 
    19841982 
    1985               W32_BLOCK_INPUT; 
    1986  
    19871983              expose_frame (f, 
    19881984                            rc.left, rc.top, 
    19891985                            rc.right - rc.left, 
    19901986                            rc.bottom - rc.top); 
    1991               W32_UNBLOCK_INPUT; 
     1987 
    19921988              RELEASE_FRAME_HDC (f); 
    19931989              EndPaint (FRAME_MW32_WINDOW (f), &ps); 
     
    20172013 
    20182014    mw32_update_frame_alpha (f); 
     2015 
     2016    /* Synchronize caret state */ 
     2017    if (CARET_CURSOR_P (XWINDOW (f->selected_window)->phys_cursor_type) 
     2018        && MW32_FRAME_CARET_SHOWN (f)) 
     2019      { 
     2020        DestroyCaret (); 
     2021        MW32_FRAME_CARET_STATE (f) = NO_CARET; 
     2022        MW32_FRAME_CARET_BLOCKED (f) = FALSE; 
     2023        PostMessage (hwnd, WM_EMACS_SETCARET, (WPARAM)SHOWN_CARET, (LPARAM)0); 
     2024      }  
    20192025    return 0; 
    20202026 
     
    20252031        DestroyCaret (); 
    20262032        MW32_FRAME_CARET_STATE (f) = NO_CARET; 
     2033        MW32_FRAME_CARET_BLOCKED (f) = FALSE; 
    20272034      } 
    20282035 
     
    20312038 
    20322039    /* reset mouse face and help echo.  */ 
     2040    mw32_update_frame_alpha (f); 
     2041     
    20332042    PostMessage (hwnd, WM_EMACS_CLEAR_MOUSE_FACE, 
    20342043                 (WPARAM) 1, (LPARAM) 0); 
    20352044 
    2036     mw32_update_frame_alpha (f); 
    20372045    return 0; 
    20382046 
     
    25522560          DestroyCaret (); 
    25532561          MW32_FRAME_CARET_STATE (last_cursor_frame) = NO_CARET; 
     2562          MW32_FRAME_CARET_BLOCKED (last_cursor_frame) = FALSE; 
    25542563        } 
    25552564      last_cursor_frame = f; 
     
    25792588      if (wParam == BLOCK_CARET) 
    25802589        { 
     2590          if (MW32_FRAME_CARET_BLOCKED (f)) 
     2591            goto setcaret_end; 
     2592             
    25812593          MW32_FRAME_CARET_BLOCKED (f) = TRUE; 
    25822594 
     
    25902602      if (wParam == UNBLOCK_CARET) 
    25912603        { 
     2604          if (!MW32_FRAME_CARET_BLOCKED (f)) 
     2605            goto setcaret_end; 
     2606 
    25922607          MW32_FRAME_CARET_BLOCKED (f) = FALSE; 
    2593  
    2594           if (MW32_FRAME_CARET_SHOWN (f) 
    2595               || MW32_FRAME_CARET_STATE (f) == TOBESHOWN_CARET) 
    2596             { 
    2597               if (ShowCaret (hwnd) == 0) 
    2598                 MW32_FRAME_CARET_STATE (f) = TOBESHOWN_CARET; 
    2599               else 
    2600                 MW32_FRAME_CARET_STATE (f) = SHOWN_CARET; 
    2601             } 
    2602           goto setcaret_end; 
     2608          wParam = MW32_FRAME_CARET_SHOWN (f) ? SHOWN_CARET : HIDDEN_CARET; 
     2609          MW32_FRAME_CARET_STATE (f) = HIDDEN_CARET; 
    26032610        } 
    26042611 
     
    26122619            WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y) 
    26132620            + w->phys_cursor_height - caret_height; 
    2614  
    2615           if (caret_spec_changed) 
    2616             { 
    2617               if (MW32_FRAME_CARET_STATE (f) > NO_CARET) 
    2618                 { 
    2619                   DestroyCaret (); 
    2620                   MW32_FRAME_CARET_STATE (f) = NO_CARET; 
    2621                 } 
    2622             } 
    2623  
    2624           if (MW32_FRAME_CARET_STATE (f) == NO_CARET) 
    2625             { 
    2626               CreateCaret (hwnd, 
    2627                            MW32_FRAME_CARET_BITMAP (f), 
    2628                            FRAME_CURSOR_WIDTH (f), 
    2629                            caret_height); 
    2630               MW32_FRAME_CARET_STATE (f) = HIDDEN_CARET; 
    2631               MW32_FRAME_CARET_BLOCKED (f) = FALSE; 
    2632               last_phys_cursor_height = w->phys_cursor_height; 
    2633               last_cursor_width = FRAME_CURSOR_WIDTH (f); 
    2634               last_cursor_height = MW32_FRAME_CARET_HEIGHT (f); 
    2635               last_bitmap = MW32_FRAME_CARET_BITMAP (f); 
    2636             } 
    2637  
    2638           SetCaretPos (caret_xpos, caret_ypos); 
    2639  
    2640           if (MW32_FRAME_CARET_SHOWN (f)) 
    2641             goto setcaret_end; 
    2642           MW32_FRAME_CARET_STATE (f) = SHOWN_CARET; 
    2643           if (! MW32_FRAME_CARET_BLOCKED (f)) 
    2644             { 
    2645               if (ShowCaret (hwnd) == 0) 
    2646                 MW32_FRAME_CARET_STATE (f) = TOBESHOWN_CARET; 
    2647             } 
     2621          int retry_count = 2;  /* Magic number */ 
     2622 
     2623          do { 
     2624            if (caret_spec_changed) 
     2625              { 
     2626                if (MW32_FRAME_CARET_STATE (f) > NO_CARET) 
     2627                  { 
     2628                    DestroyCaret (); 
     2629                    MW32_FRAME_CARET_STATE (f) = NO_CARET; 
     2630                    /* Caret is immediately re-created, so it should not 
     2631                       unblock caret. */ 
     2632                  } 
     2633                caret_spec_changed = FALSE; 
     2634              } 
     2635             
     2636            if (MW32_FRAME_CARET_STATE (f) == NO_CARET) 
     2637              { 
     2638                CreateCaret (hwnd, 
     2639                             MW32_FRAME_CARET_BITMAP (f), 
     2640                             FRAME_CURSOR_WIDTH (f), 
     2641                             caret_height); 
     2642                MW32_FRAME_CARET_STATE (f) = HIDDEN_CARET; 
     2643                MW32_FRAME_CARET_BLOCKED (f) = FALSE; 
     2644                last_phys_cursor_height = w->phys_cursor_height; 
     2645                last_cursor_width = FRAME_CURSOR_WIDTH (f); 
     2646                last_cursor_height = MW32_FRAME_CARET_HEIGHT (f); 
     2647                last_bitmap = MW32_FRAME_CARET_BITMAP (f); 
     2648              } 
     2649             
     2650            SetCaretPos (caret_xpos, caret_ypos); 
     2651 
     2652            if (MW32_FRAME_CARET_SHOWN (f)) 
     2653              goto setcaret_end; 
     2654            MW32_FRAME_CARET_STATE (f) = SHOWN_CARET; 
     2655            if (! MW32_FRAME_CARET_BLOCKED (f) && ShowCaret (hwnd) == 0) 
     2656              { 
     2657                if (GetLastError () == ERROR_ACCESS_DENIED) 
     2658                  caret_spec_changed = TRUE;    /* Retry showcaret */ 
     2659                else 
     2660                  MW32_FRAME_CARET_STATE (f) = TOBESHOWN_CARET; 
     2661              } 
     2662          } while (caret_spec_changed && retry_count-- > 0); 
    26482663        } 
    26492664      else 
     
    29212936  f->output_data.mw32->menubar_handle = INVALID_HANDLE_VALUE; 
    29222937  f->output_data.mw32->hdc = INVALID_HANDLE_VALUE; 
    2923   f->output_data.mw32->hdc_refcount = 0; 
    2924   f->output_data.mw32->message_thread_hdc = INVALID_HANDLE_VALUE; 
    2925   f->output_data.mw32->message_thread_hdc_refcount = 0; 
     2938  f->output_data.mw32->hdc_nestlevel = 0; 
    29262939  f->output_data.mw32->frame_moving_or_sizing = 0; 
    29272940  f->output_data.mw32->setcaret_event = CreateEvent (NULL, TRUE, FALSE, NULL); 
     
    30433056    } 
    30443057 
    3045   GET_TEMP_HDC (f); 
     3058  GET_FRAME_HDC (f); 
    30463059 
    30473060  /* Extract the window parameters from the supplied values 
     
    32513264  Vwindow_list = Qnil; 
    32523265 
    3253   RELEASE_TEMP_HDC (f); 
     3266  RELEASE_FRAME_HDC (f); 
    32543267  return unbind_to (count, frame); 
    32553268} 
     
    39994012  f->output_data.mw32->menubar_handle = INVALID_HANDLE_VALUE; 
    40004013  f->output_data.mw32->hdc = INVALID_HANDLE_VALUE; 
    4001   f->output_data.mw32->hdc_refcount = 0; 
    4002   f->output_data.mw32->message_thread_hdc = INVALID_HANDLE_VALUE; 
    4003   f->output_data.mw32->message_thread_hdc_refcount = 0; 
     4014  f->output_data.mw32->hdc_nestlevel = 0; 
    40044015  InitializeCriticalSection (&(f->output_data.mw32->hdc_critsec)); 
    40054016 
  • trunk/src/mw32font.c

    r3990 r3997  
    14671467  MW32LogicalFont *plf = NULL;; 
    14681468 
    1469   GET_TEMP_HDC (f); 
     1469  GET_FRAME_HDC (f); 
    14701470 
    14711471  for (i = 0; i < mw32_lf_loader_num; i++) 
     
    14831483    } 
    14841484 
    1485   RELEASE_TEMP_HDC (f); 
     1485  RELEASE_FRAME_HDC (f); 
    14861486  return plf; 
    14871487} 
  • trunk/src/mw32sync.h

    r3421 r3997  
    88extern HANDLE keyboard_handle; 
    99extern HANDLE interrupt_handle; 
    10  
    11 #define W32_BLOCK_INPUT                         \ 
    12 do {                                            \ 
    13   EnterCriticalSection(&critsec_message);       \ 
    14   block_input_ownthread = GetCurrentThreadId ();\ 
    15 } while (0); 
    16 #define W32_UNBLOCK_INPUT                       \ 
    17 do {                                            \ 
    18   block_input_ownthread = 0;                    \ 
    19   LeaveCriticalSection(&critsec_message);       \ 
    20 } while (0); 
    21 #define W32_SELF_INPUT_BLOCKED_P \ 
    22 (block_input_ownthread == GetCurrentThreadId ()) 
     10extern DWORD main_thread_id; 
    2311 
    2412#define W32_BLOCK_EVENT EnterCriticalSection(&critsec_access_event) 
  • trunk/src/mw32term.c

    r3996 r3997  
    194194HWND mw32_frame_window; 
    195195 
     196/* Window's DC that is used by main thread. */ 
     197HDC main_thread_hdc = INVALID_HANDLE_VALUE; 
     198 
     199/* Nesting level of main_thread_hdc. */ 
     200int main_thread_hdc_nestlevel = 0; 
     201 
     202/* hwnd for main_thread_hdc to use on release. */ 
     203HWND main_thread_hdc_hwnd = INVALID_HANDLE_VALUE; 
    196204  
    197205/* The scroll bar in which the last X motion event occurred. 
     
    393401mw32_destroy_frame_hdc (struct frame *f) 
    394402{ 
     403  if (main_thread_hdc != INVALID_HANDLE_VALUE) 
     404    ReleaseDC (FRAME_MW32_WINDOW (f), main_thread_hdc); 
    395405  if (f->output_data.mw32->hdc != INVALID_HANDLE_VALUE) 
    396406    ReleaseDC (FRAME_MW32_WINDOW (f), f->output_data.mw32->hdc); 
     407  main_thread_hdc = INVALID_HANDLE_VALUE; 
    397408  f->output_data.mw32->hdc = INVALID_HANDLE_VALUE; 
    398409} 
     
    461472mw32_set_caret (struct frame *f, int state) 
    462473{ 
    463   MSG msg; 
    464   int unblock = FALSE; 
    465   enum frame_caret_state current_state; 
    466  
    467   current_state  = MW32_FRAME_CARET_STATE (f); 
    468   if (current_state == NO_CARET 
     474  int blocked = FALSE; 
     475 
     476  if (MW32_FRAME_CARET_STATE (f) == NO_CARET 
    469477      && (state == BLOCK_CARET || state == UNBLOCK_CARET)) return; 
    470478 
     479  if (MW32_FRAME_CARET_BLOCKED (f)) 
     480    { 
     481      if (state == BLOCK_CARET) 
     482        return; 
     483 
     484      if (state == SHOWN_CARET || state == HIDDEN_CARET) 
     485        { 
     486          MW32_FRAME_CARET_STATE (f) = state; 
     487          return; 
     488        } 
     489    } 
    471490  if (state == BLOCK_CARET || state == HIDDEN_CARET) 
    472491    ResetEvent (f->output_data.mw32->setcaret_event); 
    473  
    474   if (W32_SELF_INPUT_BLOCKED_P) 
    475     { 
    476       W32_UNBLOCK_INPUT; 
    477       unblock = TRUE; 
    478     } 
    479492 
    480493  SEND_INFORM_MESSAGE (FRAME_MW32_WINDOW (f), 
     
    485498  if (state == BLOCK_CARET || state == HIDDEN_CARET) 
    486499    WaitForSingleObject (f->output_data.mw32->setcaret_event, 10); 
    487  
    488   if (unblock) 
    489     W32_BLOCK_INPUT; 
    490500} 
    491501 
     
    526536  if (FRAME_MW32_P (f)) 
    527537    { 
    528       HDC *phdc; 
    529       int *pcount; 
    530  
    531  
     538      MW32_BLOCK_CARET (f); 
    532539      if (MW32_MAIN_THREAD_P ()) 
    533540        { 
    534           int block = FALSE; 
    535  
    536           if (W32_SELF_INPUT_BLOCKED_P) 
     541          if (main_thread_hdc != INVALID_HANDLE_VALUE) 
    537542            { 
    538               W32_UNBLOCK_INPUT; 
    539               block = TRUE; 
     543              if (main_thread_hdc_nestlevel > GET_FRAME_HDC_LEVEL_LIMIT) 
     544                abort(); 
     545              main_thread_hdc_nestlevel++; 
     546              return; 
    540547            } 
    541  
     548           
     549          main_thread_hdc_hwnd = FRAME_MW32_WINDOW (f); 
    542550          EnterCriticalSection (&(f->output_data.mw32->hdc_critsec)); 
    543           phdc = &f->output_data.mw32->hdc
     551          main_thread_hdc = GetDC (main_thread_hdc_hwnd)
    544552          LeaveCriticalSection (&(f->output_data.mw32->hdc_critsec)); 
    545553 
    546           if (block) 
    547             W32_BLOCK_INPUT; 
    548  
    549           pcount = &f->output_data.mw32->hdc_refcount; 
     554          main_thread_hdc_nestlevel = 1; 
     555          mw32_setup_default_hdc (main_thread_hdc); 
    550556        } 
    551557      else 
    552558        { 
    553           phdc = &f->output_data.mw32->message_thread_hdc; 
    554           pcount = &f->output_data.mw32->message_thread_hdc_refcount; 
     559          if (f->output_data.mw32->hdc != INVALID_HANDLE_VALUE) 
     560            { 
     561              if (f->output_data.mw32->hdc_nestlevel 
     562                  > GET_FRAME_HDC_LEVEL_LIMIT) 
     563                abort (); 
     564              f->output_data.mw32->hdc_nestlevel++; 
     565              return; 
     566            } 
     567 
     568          f->output_data.mw32->hdc = GetDC (FRAME_MW32_WINDOW (f)); 
     569          f->output_data.mw32->hdc_nestlevel = 1; 
     570          mw32_setup_default_hdc (f->output_data.mw32->hdc); 
    555571        } 
    556  
    557       if (*phdc != INVALID_HANDLE_VALUE) 
    558         { 
    559           if (*pcount > GET_FRAME_HDC_LEVEL_LIMIT) 
    560             abort (); 
    561           (*pcount)++; 
    562           return; 
    563         } 
    564  
    565       *phdc = GetDC (FRAME_MW32_WINDOW (f)); 
    566       *pcount = 1; 
    567       mw32_setup_default_hdc (*phdc); 
    568  
    569       MW32_BLOCK_CARET (f); 
    570572    } 
    571573} 
     
    632634      Lisp_Object window; 
    633635      HDC *phdc; 
     636      HWND hwnd; 
    634637      int *pcount; 
    635638 
     
    638641      if (MW32_MAIN_THREAD_P ()) 
    639642        { 
    640           phdc = &f->output_data.mw32->hdc; 
    641           pcount = &f->output_data.mw32->hdc_refcount; 
     643          phdc = &main_thread_hdc; 
     644          pcount = &main_thread_hdc_nestlevel; 
     645          hwnd = main_thread_hdc_hwnd; 
    642646        } 
    643647      else 
    644648        { 
    645           phdc = &f->output_data.mw32->message_thread_hdc; 
    646           pcount = &f->output_data.mw32->message_thread_hdc_refcount; 
     649          phdc = &(f->output_data.mw32->hdc); 
     650          pcount = &(f->output_data.mw32->hdc_nestlevel); 
     651          hwnd = FRAME_MW32_WINDOW (f); 
    647652        } 
    648  
    649       if (*phdc != INVALID_HANDLE_VALUE
     653           
     654      if (*pcount > 1
    650655        { 
    651           if (*pcount > 1) 
    652             { 
    653               (*pcount)--; 
    654               return; 
    655             } 
    656  
    657           MW32_UNBLOCK_CARET (f); 
     656          (*pcount)--; 
     657          return; 
    658658        } 
     659 
     660      MW32_UNBLOCK_CARET (f); 
     661      ReleaseDC (hwnd, *phdc); 
     662      *phdc = INVALID_HANDLE_VALUE; 
    659663 
    660664      /* Synchronize selected_window's caret state */ 
     
    668672            mw32_set_caret (f, SHOWN_CARET); 
    669673        } 
    670  
    671       if (*phdc == INVALID_HANDLE_VALUE || *pcount > 1) 
    672         abort(); 
    673  
    674       ReleaseDC (FRAME_MW32_WINDOW (f), *phdc); 
    675       *phdc = INVALID_HANDLE_VALUE; 
    676       *pcount = 0; 
    677674    } 
    678675} 
     
    814811        { 
    815812          BLOCK_INPUT; 
    816           W32_BLOCK_INPUT; 
     813 
    817814          if (dpyinfo->mouse_face_mouse_frame) 
    818815            note_mouse_highlight (dpyinfo->mouse_face_mouse_frame, 
     
    820817                                  dpyinfo->mouse_face_mouse_y); 
    821818          dpyinfo->mouse_face_deferred_gc = 0; 
    822           W32_UNBLOCK_INPUT; 
     819 
    823820          UNBLOCK_INPUT; 
    824821        } 
     
    41304127        lf.lfHeight = (int) (XFLOATINT (height) * FRAME_LINE_HEIGHT (f)); 
    41314128    } 
    4132   if (W32_SELF_INPUT_BLOCKED_P) 
    4133     { 
    4134       W32_UNBLOCK_INPUT; 
    4135       SEND_MSGTHREAD_INFORM_MESSAGE (WM_EMACS_MODIFY_IME_FONT_PROP, 
    4136                                      (WPARAM) lf.lfHeight, 0); 
    4137       W32_BLOCK_INPUT; 
    4138     } 
    4139   else 
    4140     { 
    4141       SEND_MSGTHREAD_INFORM_MESSAGE (WM_EMACS_MODIFY_IME_FONT_PROP, 
    4142                                      (WPARAM) lf.lfHeight, 0); 
    4143     } 
     4129 
     4130  SEND_MSGTHREAD_INFORM_MESSAGE (WM_EMACS_MODIFY_IME_FONT_PROP, 
     4131                                 (WPARAM) lf.lfHeight, 0); 
    41444132} 
    41454133 
     
    41884176            break; 
    41894177          } 
    4190  
    4191         case WM_EMACS_EXPOSE_FRAME: 
    4192           { 
    4193             HDC hdc; 
    4194             RECT rc; 
    4195             struct frame *f = (struct frame *)msg.wParam; 
    4196  
    4197             hdc = GET_FRAME_HDC (f); 
    4198             mw32_setup_default_hdc (hdc); 
    4199  
    4200             GetClientRect (FRAME_MW32_WINDOW (f), &rc); 
    4201  
    4202             W32_BLOCK_INPUT; 
    4203             expose_frame (f, 
    4204                           rc.left, rc.top, 
    4205                           rc.right - rc.left, 
    4206                           rc.bottom - rc.top); 
    4207             W32_UNBLOCK_INPUT; 
    4208             RELEASE_FRAME_HDC (f); 
    4209           } 
    4210           break; 
    42114178        } 
    42124179      if (pwait_msg && (pwait_msg->message == msg.message)) 
     
    65326499     Lisp_Object data; 
    65336500{ 
    6534   RELEASE_TEMP_HDC (XFRAME (data)); 
     6501  RELEASE_FRAME_HDC (XFRAME (data)); 
    65356502 
    65366503  return Qnil; 
     
    65596526  record_unwind_protect (unwind_get_device_capability, frame); 
    65606527 
    6561   hdc = GET_TEMP_HDC (XFRAME (frame)); 
     6528  hdc = GET_FRAME_HDC (XFRAME (frame)); 
    65626529 
    65636530  if (EQ (item, intern ("width-in-mm"))) 
  • trunk/src/mw32term.h

    r3985 r3997  
    319319extern int unibyte_display_via_language_environment; 
    320320 
     321/* Window's DC that is used by main thread. */ 
     322extern HDC main_thread_hdc; 
     323 
     324/* Nesting level of main_thread_hdc. */ 
     325extern int main_thread_hdc_nestlevel; 
     326 
     327/* hwnd for main_thread_hdc to use on release. */ 
     328extern HWND main_thread_hdc_hwnd; 
     329 
    321330#define GET_MW32_DISPLAY_INFO(arg) (mw32_display_list) 
    322331 
     
    379388  HDC hdc; 
    380389 
    381   /* Refernce count of hdc. */ 
    382   int hdc_refcount; 
    383  
    384   /* Window's DC that is used for message thread. */ 
    385   HDC message_thread_hdc; 
    386  
    387   /* Reference count of message_thread_hdc. */ 
    388   int message_thread_hdc_refcount; 
     390  /* Nesting level of hdc. */ 
     391  int hdc_nestlevel; 
    389392 
    390393  /* Critical section to synchronize processces using hdc for this 
     
    525528 (! FRAME_WINDOW_P (f)? INVALID_HANDLE_VALUE:                           \ 
    526529  (MW32_MAIN_THREAD_P() ?                                               \ 
    527    (((f)->output_data.mw32->hdc != INVALID_HANDLE_VALUE)              \ 
    528     ? (f)->output_data.mw32->hdc                                      \ 
     530   (main_thread_hdc != INVALID_HANDLE_VALUE                           \ 
     531    ? main_thread_hdc                                                 \ 
    529532    : (abort (), INVALID_HANDLE_VALUE))                                 \ 
    530    : (((f)->output_data.mw32->message_thread_hdc                      \ 
     533   : (((f)->output_data.mw32->hdc                                     \ 
    531534       != INVALID_HANDLE_VALUE)                                         \ 
    532       ? (f)->output_data.mw32->message_thread_hdc                     \ 
     535      ? (f)->output_data.mw32->hdc                                    \ 
    533536      : (abort(), INVALID_HANDLE_VALUE)))) 
    534537 
     
    538541 (! FRAME_WINDOW_P (f)? INVALID_HANDLE_VALUE:                           \ 
    539542  (MW32_MAIN_THREAD_P()                                                 \ 
    540    ?(((f)->output_data.mw32->hdc != INVALID_HANDLE_VALUE)               \ 
    541      ?(((f)->output_data.mw32->hdc_refcount++>GET_FRAME_HDC_LEVEL_LIMIT) \ 
     543   ?(main_thread_hdc != INVALID_HANDLE_VALUE                            \ 
     544     ?((main_thread_hdc_nestlevel++ > GET_FRAME_HDC_LEVEL_LIMIT)        \ 
     545       ?(abort(), INVALID_HANDLE_VALUE)                                 \ 
     546       :main_thread_hdc)                                                \ 
     547     :(update_begin_hook (f), main_thread_hdc))                         \ 
     548   :(((f)->output_data.mw32->hdc != INVALID_HANDLE_VALUE)               \ 
     549     ?(((f)->output_data.mw32->hdc_nestlevel++                          \ 
     550        > GET_FRAME_HDC_LEVEL_LIMIT)                                    \ 
    542551       ?(abort(), INVALID_HANDLE_VALUE)                                 \ 
    543552       :(f)->output_data.mw32->hdc)                                     \ 
    544      :(update_begin_hook (f), (f)->output_data.mw32->hdc))              \ 
    545    :(((f)->output_data.mw32->message_thread_hdc != INVALID_HANDLE_VALUE) \ 
    546      ?(((f)->output_data.mw32->message_thread_hdc_refcount++            \ 
    547         > GET_FRAME_HDC_LEVEL_LIMIT)                                    \ 
    548        ?(abort(), INVALID_HANDLE_VALUE)                                 \ 
    549        :(f)->output_data.mw32->message_thread_hdc)                      \ 
    550      :(update_begin_hook (f), (f)->output_data.mw32->message_thread_hdc)))) 
    551  
    552 #define GET_TEMP_HDC(f)                                                 \ 
    553  (! FRAME_WINDOW_P (f)? INVALID_HANDLE_VALUE:                           \ 
    554   (MW32_MAIN_THREAD_P() ?                                               \ 
    555    (((f)->output_data.mw32->hdc != INVALID_HANDLE_VALUE)                \ 
    556     ? ((f)->output_data.mw32->hdc_refcount++,(f)->output_data.mw32->hdc) \ 
    557     : ((f)->output_data.mw32->hdc_refcount = 1,                         \ 
    558        (f)->output_data.mw32->hdc = GetDC (FRAME_MW32_WINDOW (f))))     \ 
    559    : (((f)->output_data.mw32->message_thread_hdc != INVALID_HANDLE_VALUE) \ 
    560       ? ((f)->output_data.mw32->message_thread_hdc_refcount++,          \ 
    561          (f)->output_data.mw32->message_thread_hdc)                     \ 
    562       : ((f)->output_data.mw32->message_thread_hdc_refcount = 1,        \ 
    563          (f)->output_data.mw32->message_thread_hdc                      \ 
    564          = GetDC (FRAME_MW32_WINDOW (f)))))) 
     553     :(update_begin_hook (f), (f)->output_data.mw32->hdc)))) 
     554 
    565555 
    566556#define RELEASE_FRAME_HDC(f)                                            \ 
     
    571561    if (MW32_MAIN_THREAD_P ())                                          \ 
    572562      {                                                                 \ 
    573         phdc = &((f)->output_data.mw32->hdc);                         \ 
    574         pcount = &((f)->output_data.mw32->hdc_refcount);              \ 
     563        phdc = &main_thread_hdc;                                      \ 
     564        pcount = &main_thread_hdc_nestlevel;                          \ 
    575565      }                                                                 \ 
    576566    else                                                                \ 
    577567      {                                                                 \ 
    578         phdc = &((f)->output_data.mw32->message_thread_hdc);          \ 
    579         pcount = &((f)->output_data.mw32->message_thread_hdc_refcount);       \ 
     568        phdc = &((f)->output_data.mw32->hdc);                         \ 
     569        pcount = &((f)->output_data.mw32->hdc_nestlevel);             \ 
    580570      }                                                                 \ 
    581571    if (*phdc == INVALID_HANDLE_VALUE)                                  \ 
     
    590580  } 
    591581 
    592 #define RELEASE_TEMP_HDC(f)                                             \ 
     582/* GET/RELEASE_FRAME_HDC is sometimes used asymmetrical becaulse of 
     583   signalling. This macro does force release of hdc. */ 
     584#define CLEANUP_FRAME_HDC(f)                                            \ 
    593585 if (FRAME_WINDOW_P (f))                                                \ 
    594586  {                                                                     \ 
    595     int *pcount;                                                        \ 
    596     HDC *phdc;                                                          \ 
    597587    if (MW32_MAIN_THREAD_P ())                                          \ 
    598588      {                                                                 \ 
    599         phdc = &((f)->output_data.mw32->hdc);                           \ 
    600         pcount = &((f)->output_data.mw32->hdc_refcount);                \ 
     589        if (main_thread_hdc != INVALID_HANDLE_VALUE)                    \ 
     590          {                                                             \ 
     591            main_thread_hdc_nestlevel = 1;              &n