static inline Uint8 genGetNearestColor(Uint32 src_pixel, SDL_Palette * palette) { /** alexx's code **/ if (src_pixel == 0x00000000) return 0; // black color caching register Uint8 i; Uint8 result = 1; static SDL_Color src; RGBA_TO_SDL_COLOR(src,src_pixel); for (i = 2; i < palette->ncolors; i++) if (compare_color(&src, &(palette->colors[result])) > compare_color(&src, &(palette->colors[i]))) result = i; return result; }
static int test_transparentalpha(display_t * disp) { int32_t surfattr[] = { gconfig_TRANSPARENT_ALPHA, 1, gconfig_BITS_BUFFER, 32, gconfig_NONE }; windowconfig_t winattr[] = { windowconfig_INIT_TITLE("test-graphic-window"), windowconfig_INIT_SIZE(100, 100), windowconfig_INIT_POS(50, 100), windowconfig_INIT_NONE }; window_t top = window_FREE; window_t bottom = window_FREE; gconfig_t gconf = gconfig_FREE; uint32_t snr = defaultscreennr_display(disp); EGLContext eglcontext = EGL_NO_CONTEXT; // prepare TEST(0 == init_gconfig(&gconf, disp, surfattr)); eglcontext = eglCreateContext(gl_display(disp), gl_gconfig(&gconf), EGL_NO_CONTEXT, 0); TEST(EGL_NO_CONTEXT != eglcontext); // TEST init_window: gconfig_TRANSPARENT_ALPHA: draw overlay on top of bottom TEST(0 == init_window(&top, disp, snr, 0, &gconf, winattr)); TEST(0 == init_window(&bottom, disp, snr, 0, &gconf, winattr)); // TEST swapbuffer_window: bottom window opaque color TEST(0 == show_x11window(os_window(&bottom))); WAITFOR(disp, os_window(&bottom)->state == x11window_state_SHOWN); TEST(EGL_TRUE == eglMakeCurrent(gl_display(disp), (void*)gl_window(&bottom), (void*)gl_window(&bottom), eglcontext)); glClearColor(1, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT); TEST(0 == swapbuffer_window(&bottom, disp)); eglWaitGL(); // red color TEST(0 == compare_color(os_window(&bottom), 100, 100, 1, 0, 0)); // TEST swapbuffer_window: top window with transparent value TEST(0 == show_x11window(os_window(&top))); WAITFOR(disp, os_window(&top)->state == x11window_state_SHOWN); TEST(EGL_TRUE == eglMakeCurrent(gl_display(disp), (void*)gl_window(&top), (void*)gl_window(&top), eglcontext)); glClearColor(0, 0, 1, 0); // transparent blue glClear(GL_COLOR_BUFFER_BIT); TEST(0 == swapbuffer_window(&top, disp)); eglWaitGL(); // resulting color is the combination of red and blue TEST(0 == compare_color(os_window(&bottom), 100, 100, 1, 0, 1)); // unprepare TEST(EGL_TRUE == eglMakeCurrent(gl_display(disp), EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)); TEST(EGL_TRUE == eglDestroyContext(gl_display(disp), eglcontext)); TEST(0 == free_gconfig(&gconf)); TEST(0 == free_window(&bottom)); TEST(0 == free_window(&top)); WAITFOR(disp, false); eglReleaseThread(); return 0; ONERR: eglMakeCurrent(gl_display(disp), EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); if (eglcontext != EGL_NO_CONTEXT) eglDestroyContext(gl_display(disp), eglcontext); (void) free_gconfig(&gconf); (void) free_window(&top); (void) free_window(&bottom); return EINVAL; }
static void test_clipper_blt(void) { IDirectDrawSurface7 *src_surface, *dst_surface; RECT client_rect, src_rect, *rect; IDirectDrawClipper *clipper; DDSURFACEDESC2 surface_desc; unsigned int i, j, x, y; IDirectDraw7 *ddraw; RGNDATA *rgn_data; D3DCOLOR color; HRGN r1, r2; HWND window; DDBLTFX fx; HRESULT hr; DWORD ret; static const D3DCOLOR expected1[] = { 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000, 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff, 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff, }; static const D3DCOLOR expected2[] = { 0x000000ff, 0x000000ff, 0x00000000, 0x00000000, 0x000000ff, 0x000000ff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x000000ff, 0x000000ff, 0x00000000, 0x00000000, 0x000000ff, 0x000000ff, }; window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW, 10, 10, 640, 480, 0, 0, 0, 0); ShowWindow(window, SW_SHOW); if (!(ddraw = create_ddraw())) { skip("Failed to create a ddraw object, skipping test.\n"); DestroyWindow(window); return; } ret = GetClientRect(window, &client_rect); ok(ret, "Failed to get client rect.\n"); ret = MapWindowPoints(window, NULL, (POINT *)&client_rect, 2); ok(ret, "Failed to map client rect.\n"); hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL); ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr); hr = IDirectDraw7_CreateClipper(ddraw, 0, &clipper, NULL); ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr); hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret); ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr); hr = IDirectDrawClipper_SetHWnd(clipper, 0, window); ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr); hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret); ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr); rgn_data = HeapAlloc(GetProcessHeap(), 0, ret); hr = IDirectDrawClipper_GetClipList(clipper, NULL, rgn_data, &ret); ok(SUCCEEDED(hr), "Failed to get clip list, hr %#x.\n", hr); ok(rgn_data->rdh.dwSize == sizeof(rgn_data->rdh), "Got unexpected structure size %#x.\n", rgn_data->rdh.dwSize); ok(rgn_data->rdh.iType == RDH_RECTANGLES, "Got unexpected type %#x.\n", rgn_data->rdh.iType); ok(rgn_data->rdh.nCount == 1, "Got unexpected count %u.\n", rgn_data->rdh.nCount); ok(rgn_data->rdh.nRgnSize == 16, "Got unexpected region size %u.\n", rgn_data->rdh.nRgnSize); ok(EqualRect(&rgn_data->rdh.rcBound, &client_rect), "Got unexpected bounding rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n", rgn_data->rdh.rcBound.left, rgn_data->rdh.rcBound.top, rgn_data->rdh.rcBound.right, rgn_data->rdh.rcBound.bottom, client_rect.left, client_rect.top, client_rect.right, client_rect.bottom); rect = (RECT *)&rgn_data->Buffer[0]; ok(EqualRect(rect, &client_rect), "Got unexpected clip rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n", rect->left, rect->top, rect->right, rect->bottom, client_rect.left, client_rect.top, client_rect.right, client_rect.bottom); HeapFree(GetProcessHeap(), 0, rgn_data); r1 = CreateRectRgn(0, 0, 320, 240); ok(!!r1, "Failed to create region.\n"); r2 = CreateRectRgn(320, 240, 640, 480); ok(!!r2, "Failed to create region.\n"); CombineRgn(r1, r1, r2, RGN_OR); ret = GetRegionData(r1, 0, NULL); rgn_data = HeapAlloc(GetProcessHeap(), 0, ret); ret = GetRegionData(r1, ret, rgn_data); ok(!!ret, "Failed to get region data.\n"); DeleteObject(r2); DeleteObject(r1); hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0); ok(hr == DDERR_CLIPPERISUSINGHWND, "Got unexpected hr %#x.\n", hr); hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL); ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr); hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0); ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr); HeapFree(GetProcessHeap(), 0, rgn_data); memset(&surface_desc, 0, sizeof(surface_desc)); surface_desc.dwSize = sizeof(surface_desc); surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT; surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; surface_desc.dwWidth = 640; surface_desc.dwHeight = 480; U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat); U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB; U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32; U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000; U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00; U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff; hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &src_surface, NULL); ok(SUCCEEDED(hr), "Failed to create source surface, hr %#x.\n", hr); hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &dst_surface, NULL); ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr); memset(&fx, 0, sizeof(fx)); fx.dwSize = sizeof(fx); hr = IDirectDrawSurface7_Blt(src_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx); ok(SUCCEEDED(hr), "Failed to clear source surface, hr %#x.\n", hr); hr = IDirectDrawSurface7_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx); ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr); hr = IDirectDrawSurface7_Lock(src_surface, NULL, &surface_desc, 0, NULL); ok(SUCCEEDED(hr), "Failed to lock source surface, hr %#x.\n", hr); ((DWORD *)surface_desc.lpSurface)[0] = 0xff0000ff; ((DWORD *)surface_desc.lpSurface)[1] = 0xff00ff00; ((DWORD *)surface_desc.lpSurface)[2] = 0xffff0000; ((DWORD *)surface_desc.lpSurface)[3] = 0xffffffff; hr = IDirectDrawSurface7_Unlock(src_surface, NULL); ok(SUCCEEDED(hr), "Failed to unlock source surface, hr %#x.\n", hr); hr = IDirectDrawSurface7_SetClipper(dst_surface, clipper); ok(SUCCEEDED(hr), "Failed to set clipper, hr %#x.\n", hr); SetRect(&src_rect, 0, 0, 4, 1); hr = IDirectDrawSurface7_Blt(dst_surface, NULL, src_surface, &src_rect, DDBLT_WAIT, NULL); ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr); for (i = 0; i < 4; ++i) { for (j = 0; j < 4; ++j) { x = 80 * ((2 * j) + 1); y = 60 * ((2 * i) + 1); color = get_surface_color(dst_surface, x, y); ok(compare_color(color, expected1[i * 4 + j], 1), "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1[i * 4 + j], x, y, color); } } U5(fx).dwFillColor = 0xff0000ff; hr = IDirectDrawSurface7_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx); ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr); for (i = 0; i < 4; ++i) { for (j = 0; j < 4; ++j) { x = 80 * ((2 * j) + 1); y = 60 * ((2 * i) + 1); color = get_surface_color(dst_surface, x, y); ok(compare_color(color, expected2[i * 4 + j], 1), "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2[i * 4 + j], x, y, color); } } hr = IDirectDrawSurface7_BltFast(dst_surface, 0, 0, src_surface, NULL, DDBLTFAST_WAIT); ok(hr == DDERR_BLTFASTCANTCLIP, "Got unexpected hr %#x.\n", hr); hr = IDirectDrawClipper_SetHWnd(clipper, 0, window); ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr); hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret); ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr); DestroyWindow(window); hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret); ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr); hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL); ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr); hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret); ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr); hr = IDirectDrawClipper_SetClipList(clipper, NULL, 0); ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr); hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret); ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr); hr = IDirectDrawSurface7_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx); ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr); IDirectDrawSurface7_Release(dst_surface); IDirectDrawSurface7_Release(src_surface); IDirectDrawClipper_Release(clipper); IDirectDraw7_Release(ddraw); }
void apply_new_win_data_to_page (struct Window *win_data_orig, struct Window *win_data, struct Page *page_data) { #ifdef DETAIL g_debug("! Launch apply_new_win_data_to_page() with win_data_orig = %p, win_data = %p, page_data = %p", win_data_orig, win_data, page_data); #endif #ifdef SAFEMODE if ((win_data_orig==NULL) || (win_data==NULL) || (page_data==NULL) || (page_data->vte==NULL)) return; #endif // if (win_data_orig->use_rgba != win_data->use_rgba) // init_rgba(win_data); #ifdef ENABLE_RGBA set_window_opacity (NULL, 0, win_data->window_opacity, win_data); #endif init_monitor_cmdline_datas(win_data, page_data); if (win_data_orig->enable_hyperlink != win_data->enable_hyperlink) set_hyprelink(win_data, page_data); // ---- the color used in vte ---- // gboolean update_color = FALSE; if (compare_color(&(win_data_orig->cursor_color), &(win_data->cursor_color)) || (win_data_orig->have_custom_color != win_data->have_custom_color) || (win_data_orig->use_custom_theme != win_data->use_custom_theme) || (win_data_orig->color_brightness != win_data->color_brightness)) update_color = TRUE; gint i; if (! update_color && (win_data->use_custom_theme)) { for (i=0; i<COLOR; i++) if (compare_color(&(win_data_orig->color[i]), &(win_data->color[i]))) update_color = TRUE; } if (update_color) set_vte_color(page_data->vte, use_default_vte_theme(win_data), win_data->cursor_color, win_data->color, FALSE); // ---- tabs on notebook ---- // if (win_data_orig->tabs_bar_position != win_data->tabs_bar_position) { if (win_data->tabs_bar_position) gtk_notebook_set_tab_pos(GTK_NOTEBOOK(win_data->notebook), GTK_POS_BOTTOM); else gtk_notebook_set_tab_pos(GTK_NOTEBOOK(win_data->notebook), GTK_POS_TOP); } // the fill_tabs_bar may not always work, so we should call set_fill_tabs_bar() every time. // if (win_data_orig->fill_tabs_bar != win_data->fill_tabs_bar) set_fill_tabs_bar(GTK_NOTEBOOK(win_data->notebook), win_data->fill_tabs_bar, page_data); if (win_data_orig->page_width != win_data->page_width) set_page_width(win_data, page_data); // g_debug("ORI: %d", win_data_orig->page_shows_current_cmdline || // win_data_orig->page_shows_current_dir || // win_data_orig->page_shows_window_title); // g_debug("NEW: %d", win_data->page_shows_current_cmdline || // win_data->page_shows_current_dir || // win_data->page_shows_window_title); if ((proc_exist) && ((page_data->page_update_method != PAGE_METHOD_NORMAL) || (win_data->page_shows_current_cmdline || win_data->page_shows_current_dir || win_data->page_shows_window_title))) { // FIXME: Is it necessary? if (page_data->page_update_method == PAGE_METHOD_WINDOW_TITLE) page_data->window_title_updated = 1; page_data->page_update_method = PAGE_METHOD_REFRESH; } // g_debug("page_data->page_update_method = %d", page_data->page_update_method); if (win_data->page_shows_window_title != win_data_orig->page_shows_window_title) add_remove_window_title_changed_signal(page_data); if (win_data->check_root_privileges != win_data_orig->check_root_privileges) { if (win_data->check_root_privileges) page_data->is_root = check_is_root(page_data->displayed_tpgid); else page_data->is_root = FALSE; // g_debug("apply_new_win_data_to_page(): page_data->is_root = %d", page_data->is_root); } if (page_data->is_bold) { if (page_data->vte == win_data->current_vte) { if (win_data->bold_current_page_name == FALSE) { page_data->is_bold = page_data->should_be_bold; if (win_data->bold_action_page_name == FALSE) page_data->is_bold = FALSE; } } else { if (win_data->bold_action_page_name == FALSE) page_data->is_bold = FALSE; } } else { if (page_data->vte == win_data->current_vte) page_data->is_bold = win_data->bold_current_page_name; else if (win_data->bold_action_page_name == TRUE) page_data->is_bold = page_data->should_be_bold; } if ((win_data_orig->window_title_shows_current_page != win_data->window_title_shows_current_page) || (win_data_orig->window_title_append_package_name != win_data->window_title_append_package_name)) { check_and_update_window_title(win_data, page_data->custom_window_title, page_data->page_no+1, page_data->custom_page_name, page_data->page_name); // g_debug("FINAL: New window title = %s", gtk_window_get_title(GTK_WINDOW(win_data->window))); } get_and_update_page_name(page_data, FALSE); if ((win_data_orig->show_close_button_on_tab != win_data->show_close_button_on_tab) || (win_data_orig->show_close_button_on_all_tabs != win_data->show_close_button_on_all_tabs)) show_close_button_on_tab(win_data, page_data); // ---- font ---- // if (win_data_orig->font_anti_alias != win_data->font_anti_alias) vte_terminal_set_font_from_string_full (VTE_TERMINAL(page_data->vte), page_data->font_name, win_data->font_anti_alias); // ---- other settings for init a vte ---- // if (compare_strings(win_data_orig->word_chars, win_data->word_chars, TRUE)) vte_terminal_set_word_chars(VTE_TERMINAL(page_data->vte), win_data->word_chars); if (win_data_orig->show_scroll_bar != win_data->show_scroll_bar) // hide_scroll_bar(win_data, page_data); show_and_hide_scroll_bar(page_data, check_show_or_hide_scroll_bar(win_data)); if (win_data_orig->scroll_bar_position != win_data->scroll_bar_position) { g_object_ref(page_data->vte); gtk_container_remove (GTK_CONTAINER(page_data->hbox), page_data->vte); g_object_ref(page_data->scroll_bar); gtk_container_remove (GTK_CONTAINER(page_data->hbox), page_data->scroll_bar); pack_vte_and_scroll_bar_to_hbox(win_data, page_data); g_object_unref(page_data->vte); g_object_unref(page_data->scroll_bar); } if (compare_color(&(win_data_orig->color[0]), &(win_data->color[0])) || (win_data_orig->transparent_background != win_data->transparent_background) || (win_data_orig->background_saturation != win_data->background_saturation) || (win_data_orig->scroll_background != win_data->scroll_background) || compare_strings (win_data_orig->background_image, win_data->background_image, TRUE)) set_background_saturation (NULL, 0, win_data->background_saturation, page_data->vte); if (win_data_orig->scrollback_lines != win_data->scrollback_lines) vte_terminal_set_scrollback_lines (VTE_TERMINAL(page_data->vte), win_data->scrollback_lines); if (win_data_orig->cursor_blinks != win_data->cursor_blinks) set_cursor_blink(win_data, page_data); if (win_data_orig->allow_bold_text != win_data->allow_bold_text) vte_terminal_set_allow_bold(VTE_TERMINAL(page_data->vte), win_data->allow_bold_text); if (win_data_orig->audible_bell != win_data->audible_bell) vte_terminal_set_audible_bell (VTE_TERMINAL(page_data->vte), win_data->audible_bell); if (win_data_orig->visible_bell != win_data->visible_bell) vte_terminal_set_visible_bell (VTE_TERMINAL(page_data->vte), win_data->visible_bell); #ifdef ENABLE_BEEP_SINGAL if (win_data_orig->urgent_bell != win_data->urgent_bell) set_vte_urgent_bell(win_data, page_data); #endif if (win_data_orig->erase_binding != win_data->erase_binding) vte_terminal_set_backspace_binding (VTE_TERMINAL(page_data->vte), win_data->erase_binding); #ifdef ENABLE_CURSOR_SHAPE if (win_data_orig->cursor_shape != win_data->cursor_shape) vte_terminal_set_cursor_shape(VTE_TERMINAL(page_data->vte), win_data->cursor_shape); #endif if (compare_strings(win_data_orig->emulate_term, win_data->emulate_term, TRUE)) vte_terminal_set_emulation (VTE_TERMINAL(page_data->vte), win_data->emulate_term); }