Subversion Repositories Kolibri OS

Rev

Rev 9930 | 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: 9948 $
  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.  
  150.         mov     [BgrDrawMode], ecx
  151.         ret
  152. ;--------------------------------------
  153. align 4
  154. nosb4:
  155.         cmp     ebx, 5                     ; BLOCK MOVE TO BGR
  156.         jnz     nosb5
  157.  
  158. ; add check pointer
  159.         stdcall is_region_userspace, ecx, esi
  160.         jnz     .fin
  161.  
  162.         cmp     [img_background], static_background_data
  163.         jnz     @f
  164.         test    edx, edx
  165.         jnz     .fin
  166.         cmp     esi, 4
  167.         ja      .fin
  168. ;--------------------------------------
  169. align 4
  170. @@:
  171.   ; bughere
  172.         mov     eax, ecx
  173.         mov     ebx, edx
  174.         add     ebx, [img_background];IMG_BACKGROUND
  175.         mov     ecx, esi
  176.         call    memmove
  177. ;--------------------------------------
  178. align 4
  179. .fin:
  180.         ret
  181. ;---------------------------------------
  182. align 4
  183. nosb5:
  184.         cmp     ebx, 6
  185.         jnz     nosb6
  186. ;--------------------------------------
  187. align 4
  188. ;;Maxis use atomic bts for mutex 4.4.2009
  189. @@:
  190.         bts     dword [bgrlock], 0
  191.         jnc     @f
  192.         call    change_task
  193.         jmp     @b
  194. ;--------------------------------------
  195. align 4
  196. @@:
  197.         mov     eax, [current_slot_idx]
  198.         mov     [bgrlockpid], eax
  199.         cmp     [img_background], static_background_data
  200.         jz      .nomem
  201.         stdcall user_alloc, [mem_BACKGROUND]
  202.         mov     [esp + SYSCALL_STACK.eax], eax
  203.         test    eax, eax
  204.         jz      .nomem
  205.         mov     ebx, eax
  206.         shr     ebx, 12
  207.         or      dword [page_tabs+(ebx-1)*4], MEM_BLOCK_DONT_FREE
  208.         mov     esi, [img_background]
  209.         shr     esi, 12
  210.         mov     ecx, [mem_BACKGROUND]
  211.         add     ecx, 0xFFF
  212.         shr     ecx, 12
  213. ;--------------------------------------
  214. align 4
  215. .z:
  216.         mov     eax, [page_tabs+ebx*4]
  217.         test    al, 1
  218.         jz      @f
  219.         call    free_page
  220. ;--------------------------------------
  221. align 4
  222. @@:
  223.         mov     eax, [page_tabs+esi*4]
  224.         or      al, PG_UWR
  225.         mov     [page_tabs+ebx*4], eax
  226.         mov     eax, ebx
  227.         shl     eax, 12
  228.         invlpg  [eax]
  229.         inc     ebx
  230.         inc     esi
  231.         loop    .z
  232.         ret
  233. ;--------------------------------------
  234. align 4
  235. .nomem:
  236.         and     [bgrlockpid], 0
  237.         mov     [bgrlock], 0
  238. ;--------------------------------------
  239. align 4
  240. nosb6:
  241.         cmp     ebx, 7
  242.         jnz     nosb7
  243.         cmp     [bgrlock], 0
  244.         jz      .err
  245.         mov     eax, [current_slot_idx]
  246.         cmp     [bgrlockpid], eax
  247.         jnz     .err
  248.         mov     eax, ecx
  249.         mov     ebx, ecx
  250.         shr     eax, 12
  251.         mov     ecx, [page_tabs+(eax-1)*4]
  252.         test    cl, MEM_BLOCK_USED or MEM_BLOCK_DONT_FREE
  253.         jz      .err
  254.         jnp     .err
  255.         push    eax
  256.         shr     ecx, 12
  257.         dec     ecx
  258. ;--------------------------------------
  259. align 4
  260. @@:
  261.         and     dword [page_tabs+eax*4], 0
  262.         mov     edx, eax
  263.         shl     edx, 12
  264.         push    eax
  265.         invlpg  [edx]
  266.         pop     eax
  267.         inc     eax
  268.         loop    @b
  269.         pop     eax
  270.         and     dword [page_tabs+(eax-1)*4], not MEM_BLOCK_DONT_FREE
  271.         stdcall user_free, ebx
  272.         mov     [esp + SYSCALL_STACK.eax], eax
  273.         and     [bgrlockpid], 0
  274.         mov     [bgrlock], 0
  275.         ret
  276. ;--------------------------------------
  277. align 4
  278. .err:
  279.         and     dword [esp + SYSCALL_STACK.eax], 0
  280.         ret
  281. ;-------------------------------------
  282. align 4
  283. nosb7:
  284.         cmp     ebx, 8
  285.         jnz     nosb8
  286.  
  287.         mov     ecx, [current_slot]
  288.         mov     ecx, [ecx + APPDATA.window]
  289.         xor     eax, eax
  290.         xchg    eax, [ecx + WDATA.draw_bgr_x]
  291.         mov     [esp + SYSCALL_STACK.eax], eax ; eax = [left]*65536 + [right]
  292.         xor     eax, eax
  293.         xchg    eax, [ecx + WDATA.draw_bgr_y]
  294.         mov     [esp + SYSCALL_STACK.ebx], eax ; ebx = [top]*65536 + [bottom]
  295.         ret
  296. ;---------------------------------------
  297. align 4
  298. nosb8:
  299.         cmp     ebx, 9
  300.         jnz     .exit
  301. ; ecx = [left]*65536 + [right]
  302. ; edx = [top]*65536 + [bottom]
  303.         mov     eax, [_display.width]
  304.         mov     ebx, [_display.height]
  305. ; check [right]
  306.         cmp     cx, ax
  307.         jae     .exit
  308. ; check [left]
  309.         ror     ecx, 16
  310.         cmp     cx, ax
  311.         jae     .exit
  312. ; check [bottom]
  313.         cmp     dx, bx
  314.         jae     .exit
  315. ; check [top]
  316.         ror     edx, 16
  317.         cmp     dx, bx
  318.         jae     .exit
  319.  
  320.         movzx   eax, cx  ; [left]
  321.         movzx   ebx, dx  ; [top]
  322.  
  323.         shr     ecx, 16 ; [right]
  324.         shr     edx, 16 ; [bottom]
  325.  
  326.         mov     [background_defined], 1
  327.  
  328.         mov     [background_window + WDATA.draw_data.left], eax
  329.         mov     [background_window + WDATA.draw_data.top], ebx
  330.  
  331.         mov     [background_window + WDATA.draw_data.right], ecx
  332.         mov     [background_window + WDATA.draw_data.bottom], edx
  333.  
  334.         inc     [REDRAW_BACKGROUND]
  335.         call    wakeup_osloop
  336. ;--------------------------------------
  337. align 4
  338. .exit:
  339.         ret
  340. ;------------------------------------------------------------------------------
  341.  
  342.  
  343. align 4
  344. uglobal
  345.   BG_Rect_X_left_right  dd   0x0
  346.   BG_Rect_Y_top_bottom  dd   0x0
  347. endg
  348. ;------------------------------------------------------------------------------
  349.  
  350.  
  351. align 4
  352. force_redraw_background:
  353.         and     [background_window + WDATA.draw_data.left], 0
  354.         and     [background_window + WDATA.draw_data.top], 0
  355.         push    eax ebx
  356.         mov     eax, [_display.width]
  357.         mov     ebx, [_display.height]
  358.         dec     eax
  359.         dec     ebx
  360.         mov     [background_window + WDATA.draw_data.right], eax
  361.         mov     [background_window + WDATA.draw_data.bottom], ebx
  362.         pop     ebx eax
  363.         inc     [REDRAW_BACKGROUND]
  364.         call    wakeup_osloop
  365.         ret
  366. ;------------------------------------------------------------------------------
  367.  
  368.  
  369. align 4
  370. sys_getbackground: ; sysfn 39
  371.         dec     ebx
  372.         jnz     .nogb1
  373.         ; sysfn 39.1:
  374.         mov     eax, [BgrDataWidth]
  375.         shl     eax, 16
  376.         mov     ax, word [BgrDataHeight]
  377.         mov     [esp + SYSCALL_STACK.eax], eax
  378.         ret
  379. ;---------------------------------------
  380. align 4
  381. .nogb1:
  382.         dec     ebx
  383.         jnz     .nogb2
  384.         ; sysfn 39.2:
  385.         mov     eax, [img_background]
  386.         test    ecx, ecx
  387.         jz      @f
  388.         cmp     eax, static_background_data
  389.         jz      .ret
  390. align 4
  391. @@:
  392.         mov     ebx, [mem_BACKGROUND]
  393.         add     ebx, PAGE_SIZE-1
  394.         and     ebx, -PAGE_SIZE
  395.         sub     ebx, 4
  396.         cmp     ecx, ebx
  397.         ja      .ret
  398.  
  399.         mov     eax, [ecx+eax]
  400.  
  401.         and     eax, 0xFFFFFF
  402.         mov     [esp + SYSCALL_STACK.eax], eax
  403. align 4
  404. .ret:
  405.         ret
  406. ;------------------------------------------------------------------------------
  407. align 4
  408. .nogb2:
  409.         dec     ebx
  410.         jnz     .nogb3
  411.         ; sysfn 39.3 read background subrect to buffer
  412.         ; ecx - <x, y>
  413.         ; edx - <w, h>
  414.         ; esi - buffer of 0x00RRGGBB
  415.         mov     eax, [img_background]
  416.         cmp     eax, static_background_data
  417.         jz      .exit_39_3
  418.  
  419.         sub     esp, 4*3 ; local values
  420.         ; get start offset
  421.         movzx   eax, cx ; store y in eax
  422.         cmp     eax, [BgrDataHeight]
  423.         jae     .fail_39_3
  424.         mov     [esp], eax ; save y
  425.  
  426.         shr     ecx, 16 ; ecx = x
  427.         cmp     ecx, [BgrDataWidth]
  428.         jae     .fail_39_3
  429.  
  430.         imul    eax, [BgrDataWidth]
  431.         add     eax, ecx
  432.         imul    eax, 3
  433.         mov     [esp + 4*2], eax  ; offset first poixel for copy
  434.         ; get count pixels
  435.         movzx   eax, dx   ; h
  436.         shr     edx, 16   ; w
  437.         add     ecx, edx  ; get RECT.right
  438.         cmp     ecx, [BgrDataWidth]
  439.         jae     .fail_39_3
  440.         ; check area
  441.         mov     ecx, [esp]
  442.         add     ecx, eax
  443.         cmp     ecx, [BgrDataHeight]
  444.         jae     .fail_39_3
  445.  
  446.         mov     [esp + 4], eax ; save H
  447.         mov     [esp], edx     ; save W
  448.         ; check buffer
  449.         add     eax, edx
  450.         lea     eax, [eax*3]
  451.         stdcall is_region_userspace, esi, eax
  452.         jnz     .fail_39_3
  453.  
  454.         ; loop copy lines
  455.         mov     edi, esi
  456.         mov     esi, [img_background]
  457.         add     esi, [esp + 4*2] ; add offset start copy
  458.         xor     ecx, ecx         ; index in line
  459.         cmp     ecx, [esp + 4]   ; check H == zerro
  460.         jz      .exit_39_3
  461.         xor     edx, edx         ; offset in line
  462.         cld
  463. .loop:
  464.         cmp     ecx, [esp]       ; check ecx < W
  465.         jae     @f
  466.  
  467.         mov     eax, [esi + edx]
  468.         and     eax, 0xFFFFFF
  469.         stosd   ; [edi] = eax ; edi+=4;
  470.         inc     ecx
  471.         add     edx, 3
  472.  
  473.         jmp     .loop
  474. @@:
  475.         xor     edx, edx
  476.         mov     eax, [BgrDataWidth]
  477.         lea     esi, [esi + eax*2]
  478.         add     esi, eax
  479.         mov     ecx, edx
  480.         dec     dword[esp + 4] ; h--
  481.         jnz     .loop
  482.         ; free stack
  483. .exit_39_3:
  484.         add     esp, 4*3
  485.         xor     eax, eax
  486.         mov     [esp + SYSCALL_STACK.eax], eax
  487.         ret
  488. ;--------------------------------------
  489. align 4
  490. .fail_39_3:
  491.         add     esp, 4*3
  492.         mov     [esp + SYSCALL_STACK.eax], -1
  493.         ret
  494. ;--------------------------------------
  495. align 4
  496. .nogb3:
  497.         dec     ebx
  498.         jnz     .nogb4
  499.         ; sysfn 39.4:
  500.         mov     eax, [BgrDrawMode]
  501. ;--------------------------------------
  502. align 4
  503. .nogb4:
  504.         mov     [esp + SYSCALL_STACK.eax], eax
  505.         ret
  506. ;-----------------------------------------------------------------------------
  507.  
  508.  
  509. align 4
  510. syscall_putarea_backgr: ; sysfn 25
  511. ;eax = 25
  512. ;ebx = pointer to bufer for img BBGGRRBBGGRR...
  513. ;ecx = [size x]*65536 + [size y]
  514. ;edx = [start x]*65536 + [start y]
  515.         pushad
  516.         mov     edi, ebx
  517.         mov     eax, edx
  518.         shr     eax, 16
  519.         mov     ebx, edx
  520.         and     ebx, 0xffff
  521.         dec     eax
  522.         dec     ebx
  523. ; eax - x, ebx - y
  524.         mov     edx, ecx
  525.         shr     ecx, 16
  526.         and     edx, 0xffff
  527.         mov     esi, ecx
  528. ; ecx - size x, edx - size y
  529.         mov     ebp, edx
  530.        
  531.         lea     ebp, [ebp*4]
  532.         imul    ebp, esi
  533.         stdcall is_region_userspace, edi, ebp
  534.         jnz     .exit
  535.  
  536.         mov     ebp, edx
  537.  
  538.         dec     ebp
  539.         shl     ebp, 2
  540.  
  541.         imul    ebp, esi
  542.  
  543.         mov     esi, ecx
  544.         dec     esi
  545.         shl     esi, 2
  546.  
  547.         add     ebp, esi
  548.         add     ebp, edi
  549.  
  550.         add     ebx, edx
  551. ;--------------------------------------
  552. align 4
  553. .start_y:
  554.         push    ecx edx
  555. ;--------------------------------------
  556. align 4
  557. .start_x:
  558.         push    eax ecx
  559.         add     eax, ecx
  560.  
  561.         mov     ecx, [ebp]
  562.         rol     ecx, 8
  563.         test    cl, cl        ; transparensy = 0
  564.         jz      .no_put
  565.  
  566.         xor     cl, cl
  567.         ror     ecx, 8
  568.  
  569.         pushad
  570.         mov     edx, [d_width_calc_area + ebx*4]
  571.         add     edx, [_display.win_map]
  572.         movzx   edx, byte [eax+edx]
  573.         cmp     dl, byte 1
  574.         jne     @f
  575.  
  576.         call    dword [PUTPIXEL]; eax - x, ebx - y
  577. ;--------------------------------------
  578. align 4
  579. @@:
  580.         popad
  581. ;--------------------------------------
  582. align 4
  583. .no_put:
  584.         pop     ecx eax
  585.  
  586.         sub     ebp, 4
  587.         dec     ecx
  588.         jnz     .start_x
  589.  
  590.         pop     edx ecx
  591.         dec     ebx
  592.         dec     edx
  593.         jnz     .start_y
  594.  
  595. .exit:
  596.         popad
  597.         ret