Subversion Repositories Kolibri OS

Rev

Rev 9925 | Rev 9930 | 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: 9926 $
  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.         xor     eax, eax
  293.         xchg    eax, [ecx + APPDATA.draw_bgr_x]
  294.         mov     [esp + SYSCALL_STACK.eax], eax ; eax = [left]*65536 + [right]
  295.         xor     eax, eax
  296.         xchg    eax, [ecx + APPDATA.draw_bgr_y]
  297.         mov     [esp + SYSCALL_STACK.ebx], eax ; ebx = [top]*65536 + [bottom]
  298.         ret
  299. ;---------------------------------------
  300. align 4
  301. nosb8:
  302.         cmp     ebx, 9
  303.         jnz     .exit
  304. ; ecx = [left]*65536 + [right]
  305. ; edx = [top]*65536 + [bottom]
  306.         mov     eax, [_display.width]
  307.         mov     ebx, [_display.height]
  308. ; check [right]
  309.         cmp     cx, ax
  310.         jae     .exit
  311. ; check [left]
  312.         ror     ecx, 16
  313.         cmp     cx, ax
  314.         jae     .exit
  315. ; check [bottom]
  316.         cmp     dx, bx
  317.         jae     .exit
  318. ; check [top]
  319.         ror     edx, 16
  320.         cmp     dx, bx
  321.         jae     .exit
  322.  
  323.         movzx   eax, cx  ; [left]
  324.         movzx   ebx, dx  ; [top]
  325.  
  326.         shr     ecx, 16 ; [right]
  327.         shr     edx, 16 ; [bottom]
  328.  
  329.         mov     [background_defined], 1
  330.  
  331.         mov     [draw_data + sizeof.WDATA + RECT.left], eax
  332.         mov     [draw_data + sizeof.WDATA + RECT.top], ebx
  333.  
  334.         mov     [draw_data + sizeof.WDATA + RECT.right], ecx
  335.         mov     [draw_data + sizeof.WDATA + RECT.bottom], edx
  336.  
  337.         inc     [REDRAW_BACKGROUND]
  338.         call    wakeup_osloop
  339. ;--------------------------------------
  340. align 4
  341. .exit:
  342.         ret
  343. ;------------------------------------------------------------------------------
  344.  
  345.  
  346. align 4
  347. uglobal
  348.   BG_Rect_X_left_right  dd   0x0
  349.   BG_Rect_Y_top_bottom  dd   0x0
  350. endg
  351. ;------------------------------------------------------------------------------
  352.  
  353.  
  354. align 4
  355. force_redraw_background:
  356.         and     [draw_data + sizeof.WDATA + RECT.left], 0
  357.         and     [draw_data + sizeof.WDATA + RECT.top], 0
  358.         push    eax ebx
  359.         mov     eax, [_display.width]
  360.         mov     ebx, [_display.height]
  361.         dec     eax
  362.         dec     ebx
  363.         mov     [draw_data + sizeof.WDATA + RECT.right], eax
  364.         mov     [draw_data + sizeof.WDATA + RECT.bottom], ebx
  365.         pop     ebx eax
  366.         inc     [REDRAW_BACKGROUND]
  367.         call    wakeup_osloop
  368.         ret
  369. ;------------------------------------------------------------------------------
  370.  
  371.  
  372. align 4
  373. sys_getbackground: ; sysfn 39
  374.         dec     ebx
  375.         jnz     .nogb1
  376.         ; sysfn 39.1:
  377.         mov     eax, [BgrDataWidth]
  378.         shl     eax, 16
  379.         mov     ax, word [BgrDataHeight]
  380.         mov     [esp + SYSCALL_STACK.eax], eax
  381.         ret
  382. ;---------------------------------------
  383. align 4
  384. .nogb1:
  385.         dec     ebx
  386.         jnz     .nogb2
  387.         ; sysfn 39.2:
  388.         mov     eax, [img_background]
  389.         test    ecx, ecx
  390.         jz      @f
  391.         cmp     eax, static_background_data
  392.         jz      .ret
  393. align 4
  394. @@:
  395.         mov     ebx, [mem_BACKGROUND]
  396.         add     ebx, PAGE_SIZE-1
  397.         and     ebx, -PAGE_SIZE
  398.         sub     ebx, 4
  399.         cmp     ecx, ebx
  400.         ja      .ret
  401.  
  402.         mov     eax, [ecx+eax]
  403.  
  404.         and     eax, 0xFFFFFF
  405.         mov     [esp + SYSCALL_STACK.eax], eax
  406. align 4
  407. .ret:
  408.         ret
  409. ;------------------------------------------------------------------------------
  410. align 4
  411.         .x      dd ?
  412.         .y      dd ?
  413.         .w      dd ?
  414.         .h      dd ?
  415.         .subrect_startptr dd ?
  416.         .subrect_bytes dd ?
  417. align 4
  418. .nogb2:
  419.         dec     ebx
  420.         jnz     .nogb3
  421.         ; sysfn 39.3 read background subrect to buffer
  422.         ; ecx - <x, y>
  423.         ; edx - <w, h>
  424.         ; esi - buffer of 0x00RRGGBB
  425.         mov     eax, [img_background]
  426.         cmp     eax, static_background_data
  427.         jz      .ret_39_3
  428. align 4
  429. @@:
  430.         movzx   eax, cx ; store y in eax
  431.         mov     [.y], eax
  432.  
  433.         shr     ecx, 16 ; ecx = x
  434.         mov     [.x], ecx
  435.  
  436.         imul    eax, [BgrDataWidth]
  437.         add     eax, ecx
  438.         imul    eax, 3
  439.         mov     [.subrect_startptr], eax
  440.  
  441.         movzx   eax, dx ; store h in eax
  442.         mov     [.h], eax
  443.  
  444.         shr     edx, 16 ; edx = w
  445.         mov     [.w], edx
  446.  
  447.         imul    eax, edx
  448.         mov     [.subrect_bytes], eax
  449.  
  450.         ; check bounds
  451.         mov     ebx, [mem_BACKGROUND]
  452.         add     ebx, PAGE_SIZE-1
  453.         and     ebx, -PAGE_SIZE
  454.         sub     ebx, 4
  455.         add     eax, [.subrect_startptr]
  456.         cmp     eax, ebx
  457.         ja      .fail_39_3
  458.  
  459.         ; copy contents
  460.         mov     edi, [img_background]
  461.         xor     ecx, ecx ; ecx - row index
  462. .copy_rect:
  463.         cmp     ecx, [.h]
  464.         jae     .end_copy_rect
  465.        
  466.         xor     edx, edx ; edx - column index
  467. .copy_row:
  468.         cmp     edx, [.w]
  469.         jae     .end_copy_row
  470.  
  471.         mov     ebx, ecx
  472.         imul    ebx, [BgrDataWidth]
  473.         add     ebx, edx
  474.         imul    ebx, 3
  475.         add     ebx, [.subrect_startptr]
  476.         mov     eax, [edi + ebx]
  477.         mov     ebx, ecx
  478.         imul    ebx, [.w]
  479.         add     ebx, edx
  480.         and     eax, 0xFFFFFF
  481.         mov     [esi + ebx*4], eax      
  482.  
  483.         inc     edx
  484.         jmp     .copy_row
  485. .end_copy_row:        
  486.  
  487.         inc     ecx
  488.         jmp     .copy_rect
  489. .end_copy_rect:
  490.         xor     eax, eax
  491.         mov     [esp + SYSCALL_STACK.eax], eax
  492. ;--------------------------------------
  493. align 4
  494. .fail_39_3:
  495.         mov     eax, -1
  496. align 4
  497. .ret_39_3:
  498.         ret
  499. ;--------------------------------------
  500. align 4
  501. .nogb3:
  502.         dec     ebx
  503.         jnz     .nogb4
  504.         ; sysfn 39.4:
  505.         mov     eax, [BgrDrawMode]
  506. ;--------------------------------------
  507. align 4
  508. .nogb4:
  509.         mov     [esp + SYSCALL_STACK.eax], eax
  510.         ret
  511. ;-----------------------------------------------------------------------------
  512.  
  513.  
  514. align 4
  515. syscall_putarea_backgr: ; sysfn 25
  516. ;eax = 25
  517. ;ebx = pointer to bufer for img BBGGRRBBGGRR...
  518. ;ecx = [size x]*65536 + [size y]
  519. ;edx = [start x]*65536 + [start y]
  520.         pushad
  521.         mov     edi, ebx
  522.         mov     eax, edx
  523.         shr     eax, 16
  524.         mov     ebx, edx
  525.         and     ebx, 0xffff
  526.         dec     eax
  527.         dec     ebx
  528. ; eax - x, ebx - y
  529.         mov     edx, ecx
  530.         shr     ecx, 16
  531.         and     edx, 0xffff
  532.         mov     esi, ecx
  533. ; ecx - size x, edx - size y
  534.         mov     ebp, edx
  535.        
  536.         lea     ebp, [ebp*4]
  537.         imul    ebp, esi
  538.         stdcall is_region_userspace, edi, ebp
  539.         jnz     .exit
  540.  
  541.         mov     ebp, edx
  542.  
  543.         dec     ebp
  544.         shl     ebp, 2
  545.  
  546.         imul    ebp, esi
  547.  
  548.         mov     esi, ecx
  549.         dec     esi
  550.         shl     esi, 2
  551.  
  552.         add     ebp, esi
  553.         add     ebp, edi
  554.  
  555.         add     ebx, edx
  556. ;--------------------------------------
  557. align 4
  558. .start_y:
  559.         push    ecx edx
  560. ;--------------------------------------
  561. align 4
  562. .start_x:
  563.         push    eax ecx
  564.         add     eax, ecx
  565.  
  566.         mov     ecx, [ebp]
  567.         rol     ecx, 8
  568.         test    cl, cl        ; transparensy = 0
  569.         jz      .no_put
  570.  
  571.         xor     cl, cl
  572.         ror     ecx, 8
  573.  
  574.         pushad
  575.         mov     edx, [d_width_calc_area + ebx*4]
  576.         add     edx, [_display.win_map]
  577.         movzx   edx, byte [eax+edx]
  578.         cmp     dl, byte 1
  579.         jne     @f
  580.  
  581.         call    dword [PUTPIXEL]; eax - x, ebx - y
  582. ;--------------------------------------
  583. align 4
  584. @@:
  585.         popad
  586. ;--------------------------------------
  587. align 4
  588. .no_put:
  589.         pop     ecx eax
  590.  
  591.         sub     ebp, 4
  592.         dec     ecx
  593.         jnz     .start_x
  594.  
  595.         pop     edx ecx
  596.         dec     ebx
  597.         dec     edx
  598.         jnz     .start_y
  599.  
  600. .exit:
  601.         popad
  602.         ret