Subversion Repositories Kolibri OS

Rev

Rev 7474 | Rev 9679 | 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: 8869 $
  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, [TASK_BASE]
  217.         mov     ebx, [eax-twdw + WDATA.box.width]
  218.         mov     edx, [eax-twdw + WDATA.box.height]
  219.         inc     ebx
  220.         inc     edx
  221.  
  222.         xor     eax, eax
  223.  
  224.         mov     [esp+BLITTER.dc.left], eax
  225.         mov     [esp+BLITTER.dc.top], eax
  226.         mov     [esp+BLITTER.dc.right], ebx
  227.         mov     [esp+BLITTER.dc.bottom], edx
  228.  
  229.         mov     [esp+BLITTER.sc.left], eax
  230.         mov     [esp+BLITTER.sc.top], eax
  231.         mov     eax, [ecx+24]
  232.  
  233.         mov     [esp+BLITTER.sc.right], eax
  234.         mov     eax, [ecx+28]
  235.  
  236.         mov     [esp+BLITTER.sc.bottom], eax
  237.  
  238.         mov     eax, [ecx]
  239.         mov     [esp+BLITTER.dst_x], eax
  240.         mov     eax, [ecx+4]
  241.         mov     [esp+BLITTER.dst_y], eax
  242.  
  243.         mov     eax, [ecx+16]
  244.         mov     [esp+BLITTER.src_x], eax
  245.         mov     eax, [ecx+20]
  246.         mov     [esp+BLITTER.src_y], eax
  247.         mov     eax, [ecx+8]
  248.         mov     [esp+BLITTER.w], eax
  249.         mov     eax, [ecx+12]
  250.         mov     [esp+BLITTER.h], eax
  251.  
  252.  
  253.         mov     eax, [ecx+32]
  254.         mov     [esp+BLITTER.bitmap], eax
  255.         mov     eax, [ecx+36]
  256.         mov     [esp+BLITTER.stride], eax
  257.  
  258.         mov     ecx, esp
  259.         call    blit_clip
  260.         jc      .L57
  261.  
  262.         mov     eax, [TASK_BASE]
  263.  
  264.         mov     ebx, [esp+BLITTER.dst_x]
  265.         mov     ebp, [esp+BLITTER.dst_y]
  266.         add     ebx, [eax-twdw + WDATA.box.left]
  267.         add     ebp, [eax-twdw + WDATA.box.top]
  268.        
  269.         test    [esp+.flags], BLIT_CLIENT_RELATIVE
  270.         jz      .no_client_relative        
  271.  
  272.         mov     eax, [current_slot]
  273.         add     ebx, [eax + APPDATA.wnd_clientbox.left]
  274.         add     ebp, [eax + APPDATA.wnd_clientbox.top]
  275. .no_client_relative:
  276.  
  277.         mov     ecx, ebx
  278.         add     ecx, [esp+BLITTER.w]
  279.         shl     ecx, 16
  280.         mov     cx, bp
  281.         add     ecx, [esp+BLITTER.h]
  282.  
  283.         mov     eax, ebx
  284.         shl     eax, 16
  285.         mov     ax, bp
  286.         mov     [esp+.position], eax
  287.  
  288.         mov     edi, ebp
  289.  
  290. ;        imul    edi, [_display.pitch]
  291.         mov     edi, [BPSLine_calc_area+edi*4]
  292. ;        imul    ebp, [_display.width]
  293.         mov     ebp, [d_width_calc_area+ebp*4]
  294.  
  295.         add     ebp, ebx
  296.         add     ebp, [_display.win_map]
  297.  
  298.         mov     eax, [esp+BLITTER.src_y]
  299.         imul    eax, [esp+BLITTER.stride]
  300.         mov     esi, [esp+BLITTER.src_x]
  301.         lea     esi, [eax+esi*4]
  302.         add     esi, [esp+BLITTER.bitmap]
  303.  
  304.         mov     eax, ecx
  305.         mov     ecx, [esp+BLITTER.h]
  306.         mov     edx, [esp+BLITTER.w]
  307.  
  308.         test    ecx, ecx    ;FIXME check clipping
  309.         jz      .L57
  310.  
  311.         test    edx, edx
  312.         jz      .L57
  313.  
  314.         cmp     [_display.bits_per_pixel], 32
  315.         jne     .core_24
  316.  
  317.         lea     edi, [edi+ebx*4]
  318.  
  319.         mov     ebx, [current_slot_idx]
  320. ; check for hardware cursor
  321.         cmp     [_display.select_cursor], select_cursor
  322.         je      .core_32.software_cursor
  323.         cmp     [_display.select_cursor], 0
  324.         jne     .core_32.hardware_cursor
  325. ;--------------------------------------
  326. .core_32.software_cursor:
  327. align 4
  328. .outer32:
  329.  
  330. align 4
  331. .inner32:
  332.         cmp     [ebp], bl
  333.         jne     .skip
  334. ;--------------------------------------
  335.         mov     eax, [esi]
  336.  
  337.         mov     ecx, [esp+.position]
  338.  
  339. ; check mouse area for putpixel
  340.         call    [_display.check_mouse]
  341. ;--------------------------------------
  342. ; store to real LFB
  343.         mov     [LFB_BASE+edi], eax
  344. ;--------------------------------------
  345. align 4
  346. .skip:
  347.         add     esi, 4
  348.         add     edi, 4
  349.         inc     ebp
  350.         add     [esp+.position], 1 shl 16
  351.         dec     edx
  352.         jnz     .inner32
  353.  
  354.         add     esi, [esp+BLITTER.stride]
  355.         add     edi, [_display.lfb_pitch]
  356.         add     ebp, [_display.width]
  357.  
  358.         mov     edx, [esp+BLITTER.w]
  359.         mov     eax, edx
  360.         inc     [esp+.position]
  361.         sub     ebp, edx
  362.         shl     eax, 2
  363.         sub     esi, eax
  364.         sub     edi, eax
  365.         shl     eax, 16-2
  366.         sub     [esp+.position], eax
  367.         dec     [esp+BLITTER.h]
  368.         jnz     .outer32
  369.         jmp     .done
  370. .core_32.hardware_cursor:
  371. align 4
  372. .hw.outer32:
  373.         xor     ecx, ecx
  374.  
  375. align 4
  376. .hw.inner32:
  377.         cmp     [ebp+ecx], bl
  378.         jne     .hw.skip
  379.         mov     eax, [esi+ecx*4]
  380.         mov     [LFB_BASE+edi+ecx*4], eax
  381.  
  382. align 4
  383. .hw.skip:
  384.         inc     ecx
  385.         dec     edx
  386.         jnz     .hw.inner32
  387.  
  388.         add     esi, [esp+BLITTER.stride]
  389.         add     edi, [_display.lfb_pitch]
  390.         add     ebp, [_display.width]
  391.  
  392.         mov     edx, [esp+BLITTER.w]
  393.         dec     [esp+BLITTER.h]
  394.         jnz     .hw.outer32
  395.  
  396. .done:
  397. ;        call    [draw_pointer]
  398. ;        call    __sys_draw_pointer
  399. .L57:
  400.         add     esp, .local_vars_size
  401.         pop     ebx
  402.         pop     esi
  403.         pop     edi
  404.         pop     ebp
  405.         ret
  406.  
  407. .core_24:
  408.         cmp     [_display.bits_per_pixel], 24
  409.         jne     .core_16
  410.  
  411.         lea     ebx, [ebx+ebx*2]
  412.         lea     edi, [LFB_BASE+edi+ebx]
  413.         mov     ebx, [current_slot_idx]
  414.  
  415. align 4
  416. .outer24:
  417.         mov     [esp+.extra_var1], edi
  418.         xor     ecx, ecx
  419.  
  420. align 4
  421. .inner24:
  422.         cmp     [ebp+ecx], bl           ; Does the process own this pixel?
  423.         jne     .skip_1
  424. ;--------------------------------------
  425.         push    eax
  426.         mov     eax, [esi+ecx*4]
  427.  
  428.         lea     edi, [edi+ecx*2]
  429.  
  430. ; check for hardware cursor
  431.         cmp     [_display.select_cursor], select_cursor
  432.         je      @f
  433.         cmp     [_display.select_cursor], 0
  434.         jne     .no_mouseunder_1
  435. ;--------------------------------------
  436. align 4
  437. @@:
  438.         push    ecx
  439.  
  440.         mov     ecx, [esp+4]
  441.         ror     ecx, 16
  442.         sub     ecx, edx
  443.         rol     ecx, 16
  444.         sub     ecx, [esp+BLITTER.h + 8]
  445.  
  446. ; check mouse area for putpixel
  447.         call    [_display.check_mouse]
  448.         pop     ecx
  449. ;--------------------------------------
  450. align 4
  451. .no_mouseunder_1:
  452.         mov     [edi+ecx], ax
  453.         shr     eax, 16
  454.         mov     [edi+ecx+2], al
  455.  
  456.         pop     eax
  457. ;--------------------------------------
  458. align 4
  459. .skip_1:
  460.         mov     edi, [esp+.extra_var1]
  461.         inc     ecx
  462.         dec     edx
  463.         jnz     .inner24
  464.  
  465.         add     esi, [esp+BLITTER.stride]
  466.         add     edi, [_display.lfb_pitch]
  467.         add     ebp, [_display.width]
  468.  
  469.         mov     edx, [esp+BLITTER.w]
  470.         dec     [esp+BLITTER.h]
  471.         jnz     .outer24
  472.  
  473.         jmp     .done
  474.  
  475.  
  476. .core_16:
  477.         lea     edi, [LFB_BASE+edi+ebx*2]
  478.         mov     ebx, [current_slot_idx]
  479.  
  480.   .outer16:
  481.         mov     [esp+.extra_var1], edi
  482.         xor     ecx, ecx
  483.  
  484.   .inner16:
  485.         cmp     [ebp+ecx], bl                   ; Does the process own this pixel?
  486.         jne     .skip_2
  487. ;--------------------------------------
  488.         push    eax
  489.         mov     eax, [esi+ecx*4]
  490.  
  491. ; check for hardware cursor
  492.         cmp     [_display.select_cursor], select_cursor
  493.         je      @f
  494.         cmp     [_display.select_cursor], 0
  495.         jne     .no_mouseunder_2
  496. ;--------------------------------------
  497.   @@:
  498.         push    ecx
  499.  
  500.         mov     ecx, [esp+4]
  501.         ror     ecx, 16
  502.         sub     ecx, edx
  503.         rol     ecx, 16
  504.         sub     ecx, [esp+BLITTER.h + 8]
  505.  
  506. ; check mouse area for putpixel
  507.         call    [_display.check_mouse]
  508.         pop     ecx
  509. ;--------------------------------------
  510.   .no_mouseunder_2:
  511. ; convert to 16 bpp and store to LFB
  512.         and     eax, 00000000111110001111110011111000b
  513.         shr     ah, 2
  514.         shr     ax, 3
  515.         ror     eax, 8
  516.         add     al, ah
  517.         rol     eax, 8
  518.         mov     [edi+ecx*2], ax
  519.         pop     eax
  520. ;--------------------------------------
  521.   .skip_2:
  522.         mov     edi, [esp+.extra_var1]
  523.         inc     ecx
  524.         dec     edx
  525.         jnz     .inner16
  526.  
  527.         add     esi, [esp+BLITTER.stride]
  528.         add     edi, [_display.lfb_pitch]
  529.         add     ebp, [_display.width]
  530.  
  531.         mov     edx, [esp+BLITTER.w]
  532.         dec     [esp+BLITTER.h]
  533.         jnz     .outer16
  534.  
  535.         jmp     .done
  536.  
  537.