Subversion Repositories Kolibri OS

Rev

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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2011-2015. All rights reserved. ;;
  4. ;; Distributed under terms of the GNU General Public License    ;;
  5. ;;                                                              ;;
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7.  
  8. $Revision: 9679 $
  9.  
  10.  
  11. struct  BLITTER_BLOCK
  12.         xmin            dd ?
  13.         ymin            dd ?
  14.         xmax            dd ?
  15.         ymax            dd ?
  16. ends
  17.  
  18.  
  19. struct  BLITTER
  20.         dc              RECT
  21.         sc              RECT
  22.         dst_x           dd ?            ;  32
  23.         dst_y           dd ?            ;  36
  24.         src_x           dd ?            ;  40
  25.         src_y           dd ?            ;  44
  26.         w               dd ?            ;  48
  27.         h               dd ?            ;  52
  28.  
  29.         bitmap          dd ?            ;  56
  30.         stride          dd ?            ;  60
  31. ends
  32.  
  33.  
  34.  
  35. align 4
  36. block_clip:
  37. ;esi= clip RECT ptr
  38. ;edi= RECT ptr
  39. ;return code:
  40. ;CF= 0 - draw, 1 - don't draw
  41.  
  42.         push    ebx
  43.  
  44.         mov     eax, [edi+RECT.left]
  45.         mov     ebx, [edi+RECT.right]
  46.         mov     ecx, [esi+RECT.left]    ;clip.left
  47.         mov     edx, [esi+RECT.right]   ;clip.right
  48.  
  49.         cmp     eax, edx                ;left >= clip.right
  50.         jge     .fail
  51.  
  52.         cmp     ebx, ecx                ;right < clip.left
  53.         jl      .fail
  54.  
  55.         cmp     eax, ecx                ;left >= clip.left
  56.         jge     @F
  57.  
  58.         mov     [edi+RECT.left], ecx
  59. @@:
  60.         cmp     ebx, edx                ;right <= clip.right
  61.         jle     @f
  62.  
  63.         mov     [edi+RECT.right], edx
  64. @@:
  65.         mov     eax, [edi+RECT.top]
  66.         mov     ebx, [edi+RECT.bottom]
  67.         mov     ecx, [esi+RECT.top]     ;clip.top
  68.         mov     edx, [esi+RECT.bottom]  ;clip.bottom
  69.  
  70.         cmp     eax, edx                ;top >= clip.bottom
  71.         jge     .fail
  72.  
  73.         cmp     ebx, ecx                ;bottom < clip.top
  74.         jl      .fail
  75.  
  76.         cmp     eax, ecx                ;top >= clip.top
  77.         jge     @F
  78.  
  79.         mov     [edi+RECT.top], ecx
  80. @@:
  81.         cmp     ebx, edx                ;bottom <= clip.bottom
  82.         jle     @f
  83.  
  84.         mov     [edi+RECT.bottom], edx
  85. @@:
  86.         pop     ebx
  87.         clc
  88.         ret
  89. .fail:
  90.         pop     ebx
  91.         stc
  92.         ret
  93.  
  94.  
  95. align 4
  96. blit_clip:
  97.  
  98. ;return code:
  99. ;CF= 0 - draw, 1 - don't draw
  100.  
  101. .sx0   = 8
  102. .sy0   = 12
  103. .sx1   = 16
  104. .sy1   = 20
  105.  
  106. .dx0   = 24
  107. .dy0   = 28
  108. .dx1   = 32
  109. .dy1   = 36
  110.  
  111.  
  112.         push    edi
  113.         push    esi
  114.         push    ebx
  115.         sub     esp, 40
  116.  
  117.         mov     ebx, ecx
  118.         mov     edx, [ecx+BLITTER.src_x]
  119.         mov     [esp+.sx0], edx
  120.         mov     eax, [ecx+BLITTER.src_y]
  121.         mov     [esp+.sy0], eax
  122.         add     edx, [ecx+BLITTER.w]
  123.         add     eax, [ecx+BLITTER.h]
  124.         mov     [esp+.sx1], edx
  125.         mov     [esp+.sy1], eax
  126.  
  127.         lea     edi, [esp+.sx0]
  128.         lea     esi, [ebx+BLITTER.sc]
  129.  
  130.         call    block_clip
  131.         jc      .done
  132.  
  133.         mov     edi, [esp+.sx0]
  134.         mov     edx, [ebx+BLITTER.dst_x]
  135.         add     edx, edi
  136.         sub     edx, [ebx+BLITTER.src_x]
  137.         mov     [esp+.dx0], edx
  138.  
  139.         mov     ecx, [esp+.sy0]
  140.         mov     eax, [ebx+BLITTER.dst_y]
  141.         add     eax, ecx
  142.         sub     eax, [ebx+BLITTER.src_y]
  143.         mov     [esp+.dy0], eax
  144.  
  145.         sub     edx, edi
  146.         add     edx, [esp+.sx1]
  147.         mov     [esp+.dx1], edx
  148.  
  149.         sub     eax, ecx
  150.         add     eax, [esp+.sy1]
  151.         mov     [esp+.dy1], eax
  152.  
  153.         lea     edi, [esp+.dx0]
  154.         lea     esi, [ebx+BLITTER.dc]
  155.         call    block_clip
  156.         jc      .done
  157.  
  158.         mov     edx, [esp+.dx0]
  159.         mov     eax, [esp+.dx1]
  160.         sub     eax, edx
  161.         mov     [ebx+BLITTER.w], eax
  162.  
  163.         mov     eax, [esp+.dy0]
  164.         mov     ecx, [esp+.dy1]
  165.         sub     ecx, eax
  166.         mov     [ebx+BLITTER.h], ecx
  167.  
  168.         mov     ecx, [ebx+BLITTER.src_x]
  169.         add     ecx, edx
  170.         sub     ecx, [ebx+BLITTER.dst_x]
  171.         mov     [ebx+BLITTER.src_x], ecx
  172.  
  173.         mov     ecx, [ebx+BLITTER.src_y]
  174.         add     ecx, eax
  175.         sub     ecx, [ebx+BLITTER.dst_y]
  176.         mov     [ebx+BLITTER.src_y], ecx
  177.         mov     [ebx+BLITTER.dst_x], edx
  178.         mov     [ebx+BLITTER.dst_y], eax
  179.         clc
  180. .done:
  181.         add     esp, 40
  182.         pop     ebx
  183.         pop     esi
  184.         pop     edi
  185.  
  186.  
  187. purge .sx0
  188. purge .sy0
  189. purge .sx1
  190. purge .sy1
  191.  
  192. purge .dx0
  193. purge .dy0
  194. purge .dx1
  195. purge .dy1
  196.  
  197.         ret
  198.  
  199. align 4
  200. blit_32:
  201.         push    ebp
  202.         push    edi
  203.         push    esi
  204.         push    ebx
  205. virtual at sizeof.BLITTER
  206. .position       dd      ? ; (x shl 16) + y
  207. ; ???
  208. .extra_var1     dd      ?
  209. .flags          dd      ?
  210. .local_vars_size = $
  211. end virtual
  212.         sub     esp, .local_vars_size
  213.        
  214.         mov     [esp+.flags], ebx
  215.  
  216.         mov     eax, [current_slot_idx]
  217.         shl     eax, 5 ; sizeof.WDATA
  218.         mov     ebx, [eax + window_data + WDATA.box.width]
  219.         mov     edx, [eax + window_data + WDATA.box.height]
  220.         inc     ebx
  221.         inc     edx
  222.  
  223.         xor     eax, eax
  224.  
  225.         mov     [esp+BLITTER.dc.left], eax
  226.         mov     [esp+BLITTER.dc.top], eax
  227.         mov     [esp+BLITTER.dc.right], ebx
  228.         mov     [esp+BLITTER.dc.bottom], edx
  229.  
  230.         mov     [esp+BLITTER.sc.left], eax
  231.         mov     [esp+BLITTER.sc.top], eax
  232.         mov     eax, [ecx+24]
  233.  
  234.         mov     [esp+BLITTER.sc.right], eax
  235.         mov     eax, [ecx+28]
  236.  
  237.         mov     [esp+BLITTER.sc.bottom], eax
  238.  
  239.         mov     eax, [ecx]
  240.         mov     [esp+BLITTER.dst_x], eax
  241.         mov     eax, [ecx+4]
  242.         mov     [esp+BLITTER.dst_y], eax
  243.  
  244.         mov     eax, [ecx+16]
  245.         mov     [esp+BLITTER.src_x], eax
  246.         mov     eax, [ecx+20]
  247.         mov     [esp+BLITTER.src_y], eax
  248.         mov     eax, [ecx+8]
  249.         mov     [esp+BLITTER.w], eax
  250.         mov     eax, [ecx+12]
  251.         mov     [esp+BLITTER.h], eax
  252.  
  253.  
  254.         mov     eax, [ecx+32]
  255.         mov     [esp+BLITTER.bitmap], eax
  256.         mov     eax, [ecx+36]
  257.         mov     [esp+BLITTER.stride], eax
  258.  
  259.         mov     ecx, esp
  260.         call    blit_clip
  261.         jc      .L57
  262.  
  263.         mov     eax, [current_slot_idx]
  264.         shl     eax, 5 ; sizeof.WDATA
  265.  
  266.         mov     ebx, [esp+BLITTER.dst_x]
  267.         mov     ebp, [esp+BLITTER.dst_y]
  268.         add     ebx, [eax + window_data + WDATA.box.left]
  269.         add     ebp, [eax + window_data + WDATA.box.top]
  270.        
  271.         test    [esp+.flags], BLIT_CLIENT_RELATIVE
  272.         jz      .no_client_relative        
  273.  
  274.         mov     eax, [current_slot]
  275.         add     ebx, [eax + APPDATA.wnd_clientbox.left]
  276.         add     ebp, [eax + APPDATA.wnd_clientbox.top]
  277. .no_client_relative:
  278.  
  279.         mov     ecx, ebx
  280.         add     ecx, [esp+BLITTER.w]
  281.         shl     ecx, 16
  282.         mov     cx, bp
  283.         add     ecx, [esp+BLITTER.h]
  284.  
  285.         mov     eax, ebx
  286.         shl     eax, 16
  287.         mov     ax, bp
  288.         mov     [esp+.position], eax
  289.  
  290.         mov     edi, ebp
  291.  
  292. ;        imul    edi, [_display.pitch]
  293.         mov     edi, [BPSLine_calc_area+edi*4]
  294. ;        imul    ebp, [_display.width]
  295.         mov     ebp, [d_width_calc_area+ebp*4]
  296.  
  297.         add     ebp, ebx
  298.         add     ebp, [_display.win_map]
  299.  
  300.         mov     eax, [esp+BLITTER.src_y]
  301.         imul    eax, [esp+BLITTER.stride]
  302.         mov     esi, [esp+BLITTER.src_x]
  303.         lea     esi, [eax+esi*4]
  304.         add     esi, [esp+BLITTER.bitmap]
  305.  
  306.         mov     eax, ecx
  307.         mov     ecx, [esp+BLITTER.h]
  308.         mov     edx, [esp+BLITTER.w]
  309.  
  310.         test    ecx, ecx    ;FIXME check clipping
  311.         jz      .L57
  312.  
  313.         test    edx, edx
  314.         jz      .L57
  315.  
  316.         cmp     [_display.bits_per_pixel], 32
  317.         jne     .core_24
  318.  
  319.         lea     edi, [edi+ebx*4]
  320.  
  321.         mov     ebx, [current_slot_idx]
  322. ; check for hardware cursor
  323.         cmp     [_display.select_cursor], select_cursor
  324.         je      .core_32.software_cursor
  325.         cmp     [_display.select_cursor], 0
  326.         jne     .core_32.hardware_cursor
  327. ;--------------------------------------
  328. .core_32.software_cursor:
  329. align 4
  330. .outer32:
  331.  
  332. align 4
  333. .inner32:
  334.         cmp     [ebp], bl
  335.         jne     .skip
  336. ;--------------------------------------
  337.         mov     eax, [esi]
  338.  
  339.         mov     ecx, [esp+.position]
  340.  
  341. ; check mouse area for putpixel
  342.         call    [_display.check_mouse]
  343. ;--------------------------------------
  344. ; store to real LFB
  345.         mov     [LFB_BASE+edi], eax
  346. ;--------------------------------------
  347. align 4
  348. .skip:
  349.         add     esi, 4
  350.         add     edi, 4
  351.         inc     ebp
  352.         add     [esp+.position], 1 shl 16
  353.         dec     edx
  354.         jnz     .inner32
  355.  
  356.         add     esi, [esp+BLITTER.stride]
  357.         add     edi, [_display.lfb_pitch]
  358.         add     ebp, [_display.width]
  359.  
  360.         mov     edx, [esp+BLITTER.w]
  361.         mov     eax, edx
  362.         inc     [esp+.position]
  363.         sub     ebp, edx
  364.         shl     eax, 2
  365.         sub     esi, eax
  366.         sub     edi, eax
  367.         shl     eax, 16-2
  368.         sub     [esp+.position], eax
  369.         dec     [esp+BLITTER.h]
  370.         jnz     .outer32
  371.         jmp     .done
  372. .core_32.hardware_cursor:
  373. align 4
  374. .hw.outer32:
  375.         xor     ecx, ecx
  376.  
  377. align 4
  378. .hw.inner32:
  379.         cmp     [ebp+ecx], bl
  380.         jne     .hw.skip
  381.         mov     eax, [esi+ecx*4]
  382.         mov     [LFB_BASE+edi+ecx*4], eax
  383.  
  384. align 4
  385. .hw.skip:
  386.         inc     ecx
  387.         dec     edx
  388.         jnz     .hw.inner32
  389.  
  390.         add     esi, [esp+BLITTER.stride]
  391.         add     edi, [_display.lfb_pitch]
  392.         add     ebp, [_display.width]
  393.  
  394.         mov     edx, [esp+BLITTER.w]
  395.         dec     [esp+BLITTER.h]
  396.         jnz     .hw.outer32
  397.  
  398. .done:
  399. ;        call    [draw_pointer]
  400. ;        call    __sys_draw_pointer
  401. .L57:
  402.         add     esp, .local_vars_size
  403.         pop     ebx
  404.         pop     esi
  405.         pop     edi
  406.         pop     ebp
  407.         ret
  408.  
  409. .core_24:
  410.         cmp     [_display.bits_per_pixel], 24
  411.         jne     .core_16
  412.  
  413.         lea     ebx, [ebx+ebx*2]
  414.         lea     edi, [LFB_BASE+edi+ebx]
  415.         mov     ebx, [current_slot_idx]
  416.  
  417. align 4
  418. .outer24:
  419.         mov     [esp+.extra_var1], edi
  420.         xor     ecx, ecx
  421.  
  422. align 4
  423. .inner24:
  424.         cmp     [ebp+ecx], bl           ; Does the process own this pixel?
  425.         jne     .skip_1
  426. ;--------------------------------------
  427.         push    eax
  428.         mov     eax, [esi+ecx*4]
  429.  
  430.         lea     edi, [edi+ecx*2]
  431.  
  432. ; check for hardware cursor
  433.         cmp     [_display.select_cursor], select_cursor
  434.         je      @f
  435.         cmp     [_display.select_cursor], 0
  436.         jne     .no_mouseunder_1
  437. ;--------------------------------------
  438. align 4
  439. @@:
  440.         push    ecx
  441.  
  442.         mov     ecx, [esp+4]
  443.         ror     ecx, 16
  444.         sub     ecx, edx
  445.         rol     ecx, 16
  446.         sub     ecx, [esp+BLITTER.h + 8]
  447.  
  448. ; check mouse area for putpixel
  449.         call    [_display.check_mouse]
  450.         pop     ecx
  451. ;--------------------------------------
  452. align 4
  453. .no_mouseunder_1:
  454.         mov     [edi+ecx], ax
  455.         shr     eax, 16
  456.         mov     [edi+ecx+2], al
  457.  
  458.         pop     eax
  459. ;--------------------------------------
  460. align 4
  461. .skip_1:
  462.         mov     edi, [esp+.extra_var1]
  463.         inc     ecx
  464.         dec     edx
  465.         jnz     .inner24
  466.  
  467.         add     esi, [esp+BLITTER.stride]
  468.         add     edi, [_display.lfb_pitch]
  469.         add     ebp, [_display.width]
  470.  
  471.         mov     edx, [esp+BLITTER.w]
  472.         dec     [esp+BLITTER.h]
  473.         jnz     .outer24
  474.  
  475.         jmp     .done
  476.  
  477.  
  478. .core_16:
  479.         lea     edi, [LFB_BASE+edi+ebx*2]
  480.         mov     ebx, [current_slot_idx]
  481.  
  482.   .outer16:
  483.         mov     [esp+.extra_var1], edi
  484.         xor     ecx, ecx
  485.  
  486.   .inner16:
  487.         cmp     [ebp+ecx], bl                   ; Does the process own this pixel?
  488.         jne     .skip_2
  489. ;--------------------------------------
  490.         push    eax
  491.         mov     eax, [esi+ecx*4]
  492.  
  493. ; check for hardware cursor
  494.         cmp     [_display.select_cursor], select_cursor
  495.         je      @f
  496.         cmp     [_display.select_cursor], 0
  497.         jne     .no_mouseunder_2
  498. ;--------------------------------------
  499.   @@:
  500.         push    ecx
  501.  
  502.         mov     ecx, [esp+4]
  503.         ror     ecx, 16
  504.         sub     ecx, edx
  505.         rol     ecx, 16
  506.         sub     ecx, [esp+BLITTER.h + 8]
  507.  
  508. ; check mouse area for putpixel
  509.         call    [_display.check_mouse]
  510.         pop     ecx
  511. ;--------------------------------------
  512.   .no_mouseunder_2:
  513. ; convert to 16 bpp and store to LFB
  514.         and     eax, 00000000111110001111110011111000b
  515.         shr     ah, 2
  516.         shr     ax, 3
  517.         ror     eax, 8
  518.         add     al, ah
  519.         rol     eax, 8
  520.         mov     [edi+ecx*2], ax
  521.         pop     eax
  522. ;--------------------------------------
  523.   .skip_2:
  524.         mov     edi, [esp+.extra_var1]
  525.         inc     ecx
  526.         dec     edx
  527.         jnz     .inner16
  528.  
  529.         add     esi, [esp+BLITTER.stride]
  530.         add     edi, [_display.lfb_pitch]
  531.         add     ebp, [_display.width]
  532.  
  533.         mov     edx, [esp+BLITTER.w]
  534.         dec     [esp+BLITTER.h]
  535.         jnz     .outer16
  536.  
  537.         jmp     .done
  538.  
  539.