Subversion Repositories Kolibri OS

Rev

Rev 9926 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2023. All rights reserved. ;;
  4. ;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa      ;;
  5. ;; Distributed under terms of the GNU General Public License    ;;
  6. ;;                                                              ;;
  7. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8.  
  9. $Revision: 9930 $
  10.  
  11. ; Background graphics implementation
  12.  
  13. uglobal
  14. ;  bgrchanged  dd  0x0
  15. align 4
  16. bgrlockpid dd 0
  17. bgrlock db 0
  18. endg
  19. ;--------------------------------------
  20. align 4
  21. sys_background:
  22.         cmp     ebx, 1                     ; BACKGROUND SIZE
  23.         jnz     .nosb1
  24.         test    ecx, ecx
  25.         jz      .sbgrr
  26.  
  27.         test    edx, edx
  28.         jz      .sbgrr
  29. ;--------------------------------------
  30. align 4
  31. @@:
  32. ;;Maxis use atomic bts for mutexes  4.4.2009
  33.         bts     dword [bgrlock], 0
  34.         jnc     @f
  35.         call    change_task
  36.         jmp     @b
  37. ;--------------------------------------
  38. align 4
  39. @@:
  40.         mov     [BgrDataWidth], ecx
  41.         mov     [BgrDataHeight], edx
  42. ;    mov   [bgrchanged],1
  43.  
  44.         pushad
  45. ; return memory for old background
  46.         mov     eax, [img_background]
  47.         cmp     eax, static_background_data
  48.         jz      @f
  49.         stdcall kernel_free, eax
  50. ;--------------------------------------
  51. align 4
  52. @@:
  53. ; calculate RAW size
  54.         xor     eax, eax
  55.         inc     eax
  56.         cmp     [BgrDataWidth], eax
  57.         jae     @f
  58.         mov     [BgrDataWidth], eax
  59. ;--------------------------------------
  60. align 4
  61. @@:
  62.         cmp     [BgrDataHeight], eax
  63.         jae     @f
  64.         mov     [BgrDataHeight], eax
  65. ;--------------------------------------
  66. align 4
  67. @@:
  68.         mov     eax, [BgrDataWidth]
  69.         imul    eax, [BgrDataHeight]
  70.         lea     eax, [eax*3]
  71. ; it is reserved with aligned to the boundary of 4 KB pages,
  72. ; otherwise there may be exceptions a page fault for vesa20_drawbackground_tiled
  73. ; because the 32 bit read is used for  high performance: "mov eax,[esi]"
  74.         shr     eax, 12
  75.         inc     eax
  76.         shl     eax, 12
  77.         mov     [mem_BACKGROUND], eax
  78. ; get memory for new background
  79.         stdcall kernel_alloc, eax
  80.         test    eax, eax
  81.         jz      .memfailed
  82.         mov     [img_background], eax
  83.         jmp     .exit
  84. ;--------------------------------------
  85. align 4
  86. .memfailed:
  87. ; revert to static monotone data
  88.         mov     [img_background], static_background_data
  89.         xor     eax, eax
  90.         inc     eax
  91.         mov     [BgrDataWidth], eax
  92.         mov     [BgrDataHeight], eax
  93.         mov     [mem_BACKGROUND], 4
  94. ;--------------------------------------
  95. align 4
  96. .exit:
  97.         popad
  98.         mov     [bgrlock], 0
  99. ;--------------------------------------
  100. align 4
  101. .sbgrr:
  102.         ret
  103. ;--------------------------------------
  104. align 4
  105. .nosb1:
  106.         cmp     ebx, 2                     ; SET PIXEL
  107.         jnz     .nosb2
  108.  
  109.         mov     eax, [img_background]
  110.         test    ecx, ecx
  111.         jz      @f
  112.         cmp     eax, static_background_data
  113.         jz      .ret
  114. ;--------------------------------------
  115. align 4
  116. @@:
  117.         mov     ebx, [mem_BACKGROUND]
  118.         add     ebx, PAGE_SIZE-1
  119.         and     ebx, -PAGE_SIZE
  120.         sub     ebx, 4
  121.         cmp     ecx, ebx
  122.         ja      .ret
  123.  
  124.         mov     ebx, [eax+ecx]
  125.         and     ebx, 0xFF000000;255*256*256*256
  126.         and     edx, 0x00FFFFFF;255*256*256+255*256+255
  127.         add     edx, ebx
  128.         mov     [eax+ecx], edx
  129. ;--------------------------------------
  130. align 4
  131. .ret:
  132.         ret
  133. ;--------------------------------------
  134. align 4
  135. .nosb2:
  136.         cmp     ebx, 3                     ; DRAW BACKGROUND
  137.         jnz     nosb3
  138. ;--------------------------------------
  139. align 4
  140. draw_background_temp:
  141.         mov     [background_defined], 1
  142.         call    force_redraw_background
  143.         ret
  144. ;--------------------------------------
  145. align 4
  146. nosb3:
  147.         cmp     ebx, 4                     ; TILED / STRETCHED
  148.         jnz     nosb4
  149.         cmp     ecx, [BgrDrawMode]
  150.         je      nosb41
  151.         mov     [BgrDrawMode], ecx
  152. ;--------------------------------------
  153. align 4
  154. nosb41:
  155.         ret
  156. ;--------------------------------------
  157. align 4
  158. nosb4:
  159.         cmp     ebx, 5                     ; BLOCK MOVE TO BGR
  160.         jnz     nosb5
  161.  
  162. ; add check pointer
  163.         stdcall is_region_userspace, ecx, esi
  164.         jnz     .fin
  165.  
  166.         cmp     [img_background], static_background_data
  167.         jnz     @f
  168.         test    edx, edx
  169.         jnz     .fin
  170.         cmp     esi, 4
  171.         ja      .fin
  172. ;--------------------------------------
  173. align 4
  174. @@:
  175.   ; bughere
  176.         mov     eax, ecx
  177.         mov     ebx, edx
  178.         add     ebx, [img_background];IMG_BACKGROUND
  179.         mov     ecx, esi
  180.         call    memmove
  181. ;--------------------------------------
  182. align 4
  183. .fin:
  184.         ret
  185. ;---------------------------------------
  186. align 4
  187. nosb5:
  188.         cmp     ebx, 6
  189.         jnz     nosb6
  190. ;--------------------------------------
  191. align 4
  192. ;;Maxis use atomic bts for mutex 4.4.2009
  193. @@:
  194.         bts     dword [bgrlock], 0
  195.         jnc     @f
  196.         call    change_task
  197.         jmp     @b
  198. ;--------------------------------------
  199. align 4
  200. @@:
  201.         mov     eax, [current_slot_idx]
  202.         mov     [bgrlockpid], eax
  203.         cmp     [img_background], static_background_data
  204.         jz      .nomem
  205.         stdcall user_alloc, [mem_BACKGROUND]
  206.         mov     [esp + SYSCALL_STACK.eax], eax
  207.         test    eax, eax
  208.         jz      .nomem
  209.         mov     ebx, eax
  210.         shr     ebx, 12
  211.         or      dword [page_tabs+(ebx-1)*4], MEM_BLOCK_DONT_FREE
  212.         mov     esi, [img_background]
  213.         shr     esi, 12
  214.         mov     ecx, [mem_BACKGROUND]
  215.         add     ecx, 0xFFF
  216.         shr     ecx, 12
  217. ;--------------------------------------
  218. align 4
  219. .z:
  220.         mov     eax, [page_tabs+ebx*4]
  221.         test    al, 1
  222.         jz      @f
  223.         call    free_page
  224. ;--------------------------------------
  225. align 4
  226. @@:
  227.         mov     eax, [page_tabs+esi*4]
  228.         or      al, PG_UWR
  229.         mov     [page_tabs+ebx*4], eax
  230.         mov     eax, ebx
  231.         shl     eax, 12
  232.         invlpg  [eax]
  233.         inc     ebx
  234.         inc     esi
  235.         loop    .z
  236.         ret
  237. ;--------------------------------------
  238. align 4
  239. .nomem:
  240.         and     [bgrlockpid], 0
  241.         mov     [bgrlock], 0
  242. ;--------------------------------------
  243. align 4
  244. nosb6:
  245.         cmp     ebx, 7
  246.         jnz     nosb7
  247.         cmp     [bgrlock], 0
  248.         jz      .err
  249.         mov     eax, [current_slot_idx]
  250.         cmp     [bgrlockpid], eax
  251.         jnz     .err
  252.         mov     eax, ecx
  253.         mov     ebx, ecx
  254.         shr     eax, 12
  255.         mov     ecx, [page_tabs+(eax-1)*4]
  256.         test    cl, MEM_BLOCK_USED or MEM_BLOCK_DONT_FREE
  257.         jz      .err
  258.         jnp     .err
  259.         push    eax
  260.         shr     ecx, 12
  261.         dec     ecx
  262. ;--------------------------------------
  263. align 4
  264. @@:
  265.         and     dword [page_tabs+eax*4], 0
  266.         mov     edx, eax
  267.         shl     edx, 12
  268.         push    eax
  269.         invlpg  [edx]
  270.         pop     eax
  271.         inc     eax
  272.         loop    @b
  273.         pop     eax
  274.         and     dword [page_tabs+(eax-1)*4], not MEM_BLOCK_DONT_FREE
  275.         stdcall user_free, ebx
  276.         mov     [esp + SYSCALL_STACK.eax], eax
  277.         and     [bgrlockpid], 0
  278.         mov     [bgrlock], 0
  279.         ret
  280. ;--------------------------------------
  281. align 4
  282. .err:
  283.         and     dword [esp + SYSCALL_STACK.eax], 0
  284.         ret
  285. ;-------------------------------------
  286. align 4
  287. nosb7:
  288.         cmp     ebx, 8
  289.         jnz     nosb8
  290.  
  291.         mov     ecx, [current_slot]
  292.         mov     ecx, [ecx + APPDATA.window]
  293.         xor     eax, eax
  294.         xchg    eax, [ecx + WDATA.draw_bgr_x]
  295.         mov     [esp + SYSCALL_STACK.eax], eax ; eax = [left]*65536 + [right]
  296.         xor     eax, eax
  297.         xchg    eax, [ecx + WDATA.draw_bgr_y]
  298.         mov     [esp + SYSCALL_STACK.ebx], eax ; ebx = [top]*65536 + [bottom]
  299.         ret
  300. ;---------------------------------------
  301. align 4
  302. nosb8:
  303.         cmp     ebx, 9
  304.         jnz     .exit
  305. ; ecx = [left]*65536 + [right]
  306. ; edx = [top]*65536 + [bottom]
  307.         mov     eax, [_display.width]
  308.         mov     ebx, [_display.height]
  309. ; check [right]
  310.         cmp     cx, ax
  311.         jae     .exit
  312. ; check [left]
  313.         ror     ecx, 16
  314.         cmp     cx, ax
  315.         jae     .exit
  316. ; check [bottom]
  317.         cmp     dx, bx
  318.         jae     .exit
  319. ; check [top]
  320.         ror     edx, 16
  321.         cmp     dx, bx
  322.         jae     .exit
  323.  
  324.         movzx   eax, cx  ; [left]
  325.         movzx   ebx, dx  ; [top]
  326.  
  327.         shr     ecx, 16 ; [right]
  328.         shr     edx, 16 ; [bottom]
  329.  
  330.         mov     [background_defined], 1
  331.  
  332.         mov     [background_window + WDATA.draw_data.left], eax
  333.         mov     [background_window + WDATA.draw_data.top], ebx
  334.  
  335.         mov     [background_window + WDATA.draw_data.right], ecx
  336.         mov     [background_window + WDATA.draw_data.bottom], edx
  337.  
  338.         inc     [REDRAW_BACKGROUND]
  339.         call    wakeup_osloop
  340. ;--------------------------------------
  341. align 4
  342. .exit:
  343.         ret
  344. ;------------------------------------------------------------------------------
  345.  
  346.  
  347. align 4
  348. uglobal
  349.   BG_Rect_X_left_right  dd   0x0
  350.   BG_Rect_Y_top_bottom  dd   0x0
  351. endg
  352. ;------------------------------------------------------------------------------
  353.  
  354.  
  355. align 4
  356. force_redraw_background:
  357.         and     [background_window + WDATA.draw_data.left], 0
  358.         and     [background_window + WDATA.draw_data.top], 0
  359.         push    eax ebx
  360.         mov     eax, [_display.width]
  361.         mov     ebx, [_display.height]
  362.         dec     eax
  363.         dec     ebx
  364.         mov     [background_window + WDATA.draw_data.right], eax
  365.         mov     [background_window + WDATA.draw_data.bottom], ebx
  366.         pop     ebx eax
  367.         inc     [REDRAW_BACKGROUND]
  368.         call    wakeup_osloop
  369.         ret
  370. ;------------------------------------------------------------------------------
  371.  
  372.  
  373. align 4
  374. sys_getbackground: ; sysfn 39
  375.         dec     ebx
  376.         jnz     .nogb1
  377.         ; sysfn 39.1:
  378.         mov     eax, [BgrDataWidth]
  379.         shl     eax, 16
  380.         mov     ax, word [BgrDataHeight]
  381.         mov     [esp + SYSCALL_STACK.eax], eax
  382.         ret
  383. ;---------------------------------------
  384. align 4
  385. .nogb1:
  386.         dec     ebx
  387.         jnz     .nogb2
  388.         ; sysfn 39.2:
  389.         mov     eax, [img_background]
  390.         test    ecx, ecx
  391.         jz      @f
  392.         cmp     eax, static_background_data
  393.         jz      .ret
  394. align 4
  395. @@:
  396.         mov     ebx, [mem_BACKGROUND]
  397.         add     ebx, PAGE_SIZE-1
  398.         and     ebx, -PAGE_SIZE
  399.         sub     ebx, 4
  400.         cmp     ecx, ebx
  401.         ja      .ret
  402.  
  403.         mov     eax, [ecx+eax]
  404.  
  405.         and     eax, 0xFFFFFF
  406.         mov     [esp + SYSCALL_STACK.eax], eax
  407. align 4
  408. .ret:
  409.         ret
  410. ;------------------------------------------------------------------------------
  411. align 4
  412.         .x      dd ?
  413.         .y      dd ?
  414.         .w      dd ?
  415.         .h      dd ?
  416.         .subrect_startptr dd ?
  417.         .subrect_bytes dd ?
  418. align 4
  419. .nogb2:
  420.         dec     ebx
  421.         jnz     .nogb3
  422.         ; sysfn 39.3 read background subrect to buffer
  423.         ; ecx - <x, y>
  424.         ; edx - <w, h>
  425.         ; esi - buffer of 0x00RRGGBB
  426.         mov     eax, [img_background]
  427.         cmp     eax, static_background_data
  428.         jz      .fail_39_3
  429. align 4
  430. @@:
  431.         movzx   eax, cx ; store y in eax
  432.         mov     [.y], eax
  433.  
  434.         shr     ecx, 16 ; ecx = x
  435.         mov     [.x], ecx
  436.  
  437.         imul    eax, [BgrDataWidth]
  438.         add     eax, ecx
  439.         imul    eax, 3
  440.         mov     [.subrect_startptr], eax
  441.  
  442.         movzx   eax, dx ; store h in eax
  443.         mov     [.h], eax
  444.  
  445.         shr     edx, 16 ; edx = w
  446.         mov     [.w], edx
  447.  
  448.         imul    eax, edx
  449.         mov     [.subrect_bytes], eax
  450.  
  451.         ; check bounds
  452.         mov     ebx, [mem_BACKGROUND]
  453.         add     ebx, PAGE_SIZE-1
  454.         and     ebx, -PAGE_SIZE
  455.         sub     ebx, 4
  456.         add     eax, [.subrect_startptr]
  457.         cmp     eax, ebx
  458.         ja      .fail_39_3
  459.  
  460.         ; copy contents
  461.         mov     edi, [img_background]
  462.         xor     ecx, ecx ; ecx - row index
  463. .copy_rect:
  464.         cmp     ecx, [.h]
  465.         jae     .end_copy_rect
  466.        
  467.         xor     edx, edx ; edx - column index
  468. .copy_row:
  469.         cmp     edx, [.w]
  470.         jae     .end_copy_row
  471.  
  472.         mov     ebx, ecx
  473.         imul    ebx, [BgrDataWidth]
  474.         add     ebx, edx
  475.         imul    ebx, 3
  476.         add     ebx, [.subrect_startptr]
  477.         mov     eax, [edi + ebx]
  478.         mov     ebx, ecx
  479.         imul    ebx, [.w]
  480.         add     ebx, edx
  481.         and     eax, 0xFFFFFF
  482.         mov     [esi + ebx*4], eax      
  483.  
  484.         inc     edx
  485.         jmp     .copy_row
  486. .end_copy_row:        
  487.  
  488.         inc     ecx
  489.         jmp     .copy_rect
  490. .end_copy_rect:
  491.         xor     eax, eax
  492.         mov     [esp + SYSCALL_STACK.eax], eax
  493. align 4
  494. .ret_39_3:
  495.         ret
  496. ;--------------------------------------
  497. align 4
  498. .fail_39_3:
  499.         mov     [esp + SYSCALL_STACK.eax], -1
  500.         ret
  501. ;--------------------------------------
  502. align 4
  503. .nogb3:
  504.         dec     ebx
  505.         jnz     .nogb4
  506.         ; sysfn 39.4:
  507.         mov     eax, [BgrDrawMode]
  508. ;--------------------------------------
  509. align 4
  510. .nogb4:
  511.         mov     [esp + SYSCALL_STACK.eax], eax
  512.         ret
  513. ;-----------------------------------------------------------------------------
  514.  
  515.  
  516. align 4
  517. syscall_putarea_backgr: ; sysfn 25
  518. ;eax = 25
  519. ;ebx = pointer to bufer for img BBGGRRBBGGRR...
  520. ;ecx = [size x]*65536 + [size y]
  521. ;edx = [start x]*65536 + [start y]
  522.         pushad
  523.         mov     edi, ebx
  524.         mov     eax, edx
  525.         shr     eax, 16
  526.         mov     ebx, edx
  527.         and     ebx, 0xffff
  528.         dec     eax
  529.         dec     ebx
  530. ; eax - x, ebx - y
  531.         mov     edx, ecx
  532.         shr     ecx, 16
  533.         and     edx, 0xffff
  534.         mov     esi, ecx
  535. ; ecx - size x, edx - size y
  536.         mov     ebp, edx
  537.        
  538.         lea     ebp, [ebp*4]
  539.         imul    ebp, esi
  540.         stdcall is_region_userspace, edi, ebp
  541.         jnz     .exit
  542.  
  543.         mov     ebp, edx
  544.  
  545.         dec     ebp
  546.         shl     ebp, 2
  547.  
  548.         imul    ebp, esi
  549.  
  550.         mov     esi, ecx
  551.         dec     esi
  552.         shl     esi, 2
  553.  
  554.         add     ebp, esi
  555.         add     ebp, edi
  556.  
  557.         add     ebx, edx
  558. ;--------------------------------------
  559. align 4
  560. .start_y:
  561.         push    ecx edx
  562. ;--------------------------------------
  563. align 4
  564. .start_x:
  565.         push    eax ecx
  566.         add     eax, ecx
  567.  
  568.         mov     ecx, [ebp]
  569.         rol     ecx, 8
  570.         test    cl, cl        ; transparensy = 0
  571.         jz      .no_put
  572.  
  573.         xor     cl, cl
  574.         ror     ecx, 8
  575.  
  576.         pushad
  577.         mov     edx, [d_width_calc_area + ebx*4]
  578.         add     edx, [_display.win_map]
  579.         movzx   edx, byte [eax+edx]
  580.         cmp     dl, byte 1
  581.         jne     @f
  582.  
  583.         call    dword [PUTPIXEL]; eax - x, ebx - y
  584. ;--------------------------------------
  585. align 4
  586. @@:
  587.         popad
  588. ;--------------------------------------
  589. align 4
  590. .no_put:
  591.         pop     ecx eax
  592.  
  593.         sub     ebp, 4
  594.         dec     ecx
  595.         jnz     .start_x
  596.  
  597.         pop     edx ecx
  598.         dec     ebx
  599.         dec     edx
  600.         jnz     .start_y
  601.  
  602. .exit:
  603.         popad
  604.         ret