From d577a48bb7cce5f88904e86499906ade86809d8a Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sun, 5 Aug 2012 11:28:48 +0100 Subject: Abstract pen obtain/release and structure so we can add these to a physical browser window's list --- amiga/gui.c | 9 ++++++++- amiga/gui.h | 1 + amiga/plotters.c | 44 ++++++++++++++++++++++++-------------------- amiga/plotters.h | 2 ++ 4 files changed, 35 insertions(+), 21 deletions(-) (limited to 'amiga') diff --git a/amiga/gui.c b/amiga/gui.c index ee15ee98e..347fcde23 100755 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -2209,6 +2209,7 @@ void ami_switch_tab(struct gui_window_2 *gwin,bool redraw) return; } + ami_plot_release_pens(&g->shared->shared_pens); ami_update_buttons(gwin); ami_menu_update_disabled(gwin->bw->window, gwin->bw->current_content); @@ -2574,6 +2575,8 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw, return NULL; } + NewList(&g->shared->shared_pens); + g->shared->scrollerhook.h_Entry = (void *)ami_scroller_hook; g->shared->scrollerhook.h_Data = g->shared; @@ -3182,6 +3185,8 @@ void gui_window_destroy(struct gui_window *g) return; } + ami_plot_release_pens(&g->shared->shared_pens); + DisposeObject(g->shared->objects[OID_MAIN]); ami_gui_appicon_remove(g->shared); if(g->shared->appwin) RemoveAppWindow(g->shared->appwin); @@ -3280,6 +3285,8 @@ void ami_do_redraw_tiled(struct gui_window_2 *gwin, int tile_x_scale = (int)(nsoption_int(redraw_tile_size_x) / gwin->bw->scale); int tile_y_scale = (int)(nsoption_int(redraw_tile_size_y) / gwin->bw->scale); + browserglob.shared_pens = &gwin->shared_pens; + if(top < 0) { height += top; top = 0; @@ -3997,7 +4004,7 @@ void gui_window_new_content(struct gui_window *g) g->shared->oldh = 0; g->shared->oldv = 0; g->favicon = NULL; - + ami_plot_release_pens(&g->shared->shared_pens); ami_menu_update_disabled(g, c); } diff --git a/amiga/gui.h b/amiga/gui.h index 01588c790..013be50c0 100755 --- a/amiga/gui.h +++ b/amiga/gui.h @@ -112,6 +112,7 @@ struct gui_window_2 { gui_drag_type drag_op; struct IBox *ptr_lock; struct AppWindow *appwin; + struct MinList shared_pens; }; struct gui_window diff --git a/amiga/plotters.c b/amiga/plotters.c index 348e66e94..34f596474 100755 --- a/amiga/plotters.c +++ b/amiga/plotters.c @@ -227,6 +227,26 @@ void ami_clearclipreg(struct gui_globals *gg) gg->rect.MaxY = scrn->Height-1; } +ULONG ami_plot_obtain_pen(struct MinList *shared_pens, ULONG colour) +{ + ULONG pen = ObtainBestPenA(scrn->ViewPort.ColorMap, + (colour & 0x000000ff) << 24, + (colour & 0x0000ff00) << 16, + (colour & 0x00ff0000) << 8, + NULL); + + if(pen == -1) LOG(("WARNING: Cannot allocate pen for ABGR:%lx", colour)); + + /* TODO: add allocated pen to list */ + + return pen; +} + +void ami_plot_release_pens(struct MinList *shared_pens) +{ + /* TODO: trawl through list releasing pens */ +} + void ami_plot_setapen(ULONG colour) { if(palette_mapped == false) { @@ -234,16 +254,8 @@ void ami_plot_setapen(ULONG colour) p96EncodeColor(RGBFF_A8B8G8R8, colour), TAG_DONE); } else { - ULONG pen = ObtainBestPenA(scrn->ViewPort.ColorMap, - (colour & 0x000000ff) << 24, - (colour & 0x0000ff00) << 16, - (colour & 0x00ff0000) << 8, - NULL); - - if(pen == -1) LOG(("WARNING: Cannot allocate pen for ABGR:%lx", colour)); - - SetAPen(glob->rp, pen); - /* TODO: Add pen to a list for later release */ + ULONG pen = ami_plot_obtain_pen(gg->shared_pens, colour); + if(pen != -1) SetAPen(glob->rp, pen); } } @@ -254,16 +266,8 @@ void ami_plot_setopen(ULONG colour) p96EncodeColor(RGBFF_A8B8G8R8, colour), TAG_DONE); } else { - ULONG pen = ObtainBestPenA(scrn->ViewPort.ColorMap, - (colour & 0x000000ff) << 24, - (colour & 0x0000ff00) << 16, - (colour & 0x00ff0000) << 8, - NULL); - - if(pen == -1) LOG(("WARNING: Cannot allocate pen for ABGR:%lx", colour)); - - SetOPen(glob->rp, pen); - /* TODO: Add pen to a list for later release */ + ULONG pen = ami_plot_obtain_pen(gg->shared_pens, colour); + if(pen != -1) SetOPen(glob->rp, pen); } } diff --git a/amiga/plotters.h b/amiga/plotters.h index c3f816dca..94dfaee6e 100755 --- a/amiga/plotters.h +++ b/amiga/plotters.h @@ -33,6 +33,7 @@ struct gui_globals APTR areabuf; APTR tmprasbuf; struct Rectangle rect; + struct MinList *shared_pens; #ifdef NS_AMIGA_CAIRO cairo_surface_t *surface; cairo_t *cr; @@ -63,6 +64,7 @@ bool ami_path(const float *p, unsigned int n, colour fill, float width, void ami_init_layers(struct gui_globals *gg, ULONG width, ULONG height); void ami_free_layers(struct gui_globals *gg); void ami_clearclipreg(struct gui_globals *gg); +void ami_plot_release_pens(struct MinList *shared_pens); struct gui_globals *glob; #endif -- cgit v1.2.3