1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3 ;; Copyright (C) KolibriOS team 2004-2021. All rights reserved. ;;
4 ;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa ;;
5 ;; Distributed under terms of the GNU General Public License ;;
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11 ; Background graphics implementation
19 ;--------------------------------------
22 cmp ebx, 1 ; BACKGROUND SIZE
29 ;--------------------------------------
32 ;;Maxis use atomic bts for mutexes 4.4.2009
33 bts dword [bgrlock], 0
37 ;--------------------------------------
40 mov [BgrDataWidth], ecx
41 mov [BgrDataHeight], edx
45 ; return memory for old background
46 mov eax, [img_background]
47 cmp eax, static_background_data
49 stdcall kernel_free, eax
50 ;--------------------------------------
56 cmp [BgrDataWidth], eax
58 mov [BgrDataWidth], eax
59 ;--------------------------------------
62 cmp [BgrDataHeight], eax
64 mov [BgrDataHeight], eax
65 ;--------------------------------------
68 mov eax, [BgrDataWidth]
69 imul eax, [BgrDataHeight]
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]"
77 mov [mem_BACKGROUND], eax
78 ; get memory for new background
79 stdcall kernel_alloc, eax
82 mov [img_background], eax
84 ;--------------------------------------
87 ; revert to static monotone data
88 mov [img_background], static_background_data
91 mov [BgrDataWidth], eax
92 mov [BgrDataHeight], eax
93 mov [mem_BACKGROUND], 4
94 ;--------------------------------------
99 ;--------------------------------------
103 ;--------------------------------------
106 cmp ebx, 2 ; SET PIXEL
109 mov eax, [img_background]
112 cmp eax, static_background_data
114 ;--------------------------------------
117 mov ebx, [mem_BACKGROUND]
125 and ebx, 0xFF000000;255*256*256*256
126 and edx, 0x00FFFFFF;255*256*256+255*256+255
129 ;--------------------------------------
133 ;--------------------------------------
136 cmp ebx, 3 ; DRAW BACKGROUND
138 ;--------------------------------------
140 draw_background_temp:
141 mov [background_defined], 1
142 call force_redraw_background
143 ;--------------------------------------
147 ;--------------------------------------
150 cmp ebx, 4 ; TILED / STRETCHED
152 cmp ecx, [BgrDrawMode]
154 mov [BgrDrawMode], ecx
155 ;--------------------------------------
159 ;--------------------------------------
162 cmp ebx, 5 ; BLOCK MOVE TO BGR
166 stdcall is_region_userspace, ecx, esi
169 cmp [img_background], static_background_data
175 ;--------------------------------------
181 add ebx, [img_background];IMG_BACKGROUND
184 ;--------------------------------------
188 ;---------------------------------------
193 ;--------------------------------------
195 ;;Maxis use atomic bts for mutex 4.4.2009
197 bts dword [bgrlock], 0
201 ;--------------------------------------
204 mov eax, [current_slot_idx]
205 mov [bgrlockpid], eax
206 cmp [img_background], static_background_data
208 stdcall user_alloc, [mem_BACKGROUND]
209 mov [esp + SYSCALL_STACK.eax], eax
214 or dword [page_tabs+(ebx-1)*4], MEM_BLOCK_DONT_FREE
215 mov esi, [img_background]
217 mov ecx, [mem_BACKGROUND]
220 ;--------------------------------------
223 mov eax, [page_tabs+ebx*4]
227 ;--------------------------------------
230 mov eax, [page_tabs+esi*4]
232 mov [page_tabs+ebx*4], eax
240 ;--------------------------------------
245 ;--------------------------------------
252 mov eax, [current_slot_idx]
253 cmp [bgrlockpid], eax
258 mov ecx, [page_tabs+(eax-1)*4]
259 test cl, MEM_BLOCK_USED or MEM_BLOCK_DONT_FREE
265 ;--------------------------------------
268 and dword [page_tabs+eax*4], 0
277 and dword [page_tabs+(eax-1)*4], not MEM_BLOCK_DONT_FREE
278 stdcall user_free, ebx
279 mov [esp + SYSCALL_STACK.eax], eax
283 ;--------------------------------------
286 and dword [esp + SYSCALL_STACK.eax], 0
288 ;-------------------------------------
294 mov ecx, [current_slot]
296 xchg eax, [ecx + APPDATA.draw_bgr_x]
297 mov [esp + SYSCALL_STACK.eax], eax ; eax = [left]*65536 + [right]
299 xchg eax, [ecx + APPDATA.draw_bgr_y]
300 mov [esp + SYSCALL_STACK.ebx], eax ; ebx = [top]*65536 + [bottom]
302 ;---------------------------------------
307 ; ecx = [left]*65536 + [right]
308 ; edx = [top]*65536 + [bottom]
309 mov eax, [_display.width]
310 mov ebx, [_display.height]
326 movzx eax, cx ; [left]
327 movzx ebx, dx ; [top]
329 shr ecx, 16 ; [right]
330 shr edx, 16 ; [bottom]
332 mov [background_defined], 1
334 mov [draw_data + sizeof.RECT + RECT.left], eax
335 mov [draw_data + sizeof.RECT + RECT.top], ebx
337 mov [draw_data + sizeof.RECT + RECT.right], ecx
338 mov [draw_data + sizeof.RECT + RECT.bottom], edx
340 inc [REDRAW_BACKGROUND]
342 ;--------------------------------------
346 ;------------------------------------------------------------------------------
351 BG_Rect_X_left_right dd 0x0
352 BG_Rect_Y_top_bottom dd 0x0
354 ;------------------------------------------------------------------------------
358 force_redraw_background:
359 and [draw_data + sizeof.RECT + RECT.left], 0
360 and [draw_data + sizeof.RECT + RECT.top], 0
362 mov eax, [_display.width]
363 mov ebx, [_display.height]
366 mov [draw_data + sizeof.RECT + RECT.right], eax
367 mov [draw_data + sizeof.RECT + RECT.bottom], ebx
369 inc [REDRAW_BACKGROUND]
372 ;------------------------------------------------------------------------------
376 sys_getbackground: ; sysfn 39
380 mov eax, [BgrDataWidth]
382 mov ax, word [BgrDataHeight]
383 mov [esp + SYSCALL_STACK.eax], eax
385 ;---------------------------------------
391 mov eax, [img_background]
394 cmp eax, static_background_data
398 mov ebx, [mem_BACKGROUND]
408 mov [esp + SYSCALL_STACK.eax], eax
412 ;------------------------------------------------------------------------------
418 .subrect_startptr dd ?
424 ; sysfn 39.3 read background subrect to buffer
427 ; esi - buffer of 0x00RRGGBB
428 mov eax, [img_background]
429 cmp eax, static_background_data
433 movzx eax, cx ; store y in eax
436 shr ecx, 16 ; ecx = x
439 imul eax, [BgrDataWidth]
442 mov [.subrect_startptr], eax
444 movzx eax, dx ; store h in eax
447 shr edx, 16 ; edx = w
451 mov [.subrect_bytes], eax
454 mov ebx, [mem_BACKGROUND]
458 add eax, [.subrect_startptr]
463 mov edi, [img_background]
464 xor ecx, ecx ; ecx - row index
469 xor edx, edx ; edx - column index
475 imul ebx, [BgrDataWidth]
478 add ebx, [.subrect_startptr]
484 mov [esi + ebx*4], eax
494 mov [esp + SYSCALL_STACK.eax], eax
495 ;--------------------------------------
502 ;--------------------------------------
508 mov eax, [BgrDrawMode]
509 ;--------------------------------------
512 mov [esp + SYSCALL_STACK.eax], eax
514 ;-----------------------------------------------------------------------------
518 syscall_putarea_backgr: ; sysfn 25
520 ;ebx = pointer to bufer for img BBGGRRBBGGRR...
521 ;ecx = [size x]*65536 + [size y]
522 ;edx = [start x]*65536 + [start y]
536 ; ecx - size x, edx - size y
541 stdcall is_region_userspace, edi, ebp
559 ;--------------------------------------
563 ;--------------------------------------
571 test cl, cl ; transparensy = 0
578 mov edx, [d_width_calc_area + ebx*4]
579 add edx, [_display.win_map]
580 movzx edx, byte [eax+edx]
584 call dword [PUTPIXEL]; eax - x, ebx - y
585 ;--------------------------------------
589 ;--------------------------------------