static int pmatfactor(void*MM, int *flag){ plapackM* ctx=(plapackM*)MM; int info,dummy; double ddxerror; DSDPFunctionBegin; wallclock(&ctx->t1); info=PLA_Obj_set_to_one(ctx->wVec);DSDPCHKERR(info); info=PLA_Obj_set_to_zero(ctx->vVec);DSDPCHKERR(info); info=PLA_Symv( PLA_LOWER_TRIANGULAR, ctx->one, ctx->AMat, ctx->wVec, ctx->zero, ctx->vVec ); DSDPCHKERR(info); *flag=0; info = PLA_Chol(PLA_LOWER_TRIANGULAR, ctx->AMat); DSDPCHKERR(info); if (info!=0) { *flag=1; printf("PLAPACK WARNING: Non positive-definite Matrix M : Row: %d\n",info); } info = PLA_Trsv(PLA_LOWER_TRIANGULAR, PLA_NO_TRANSPOSE, PLA_NONUNIT_DIAG, ctx->AMat, ctx->vVec);DSDPCHKERR(info); info = PLA_Trsv(PLA_LOWER_TRIANGULAR, PLA_TRANSPOSE, PLA_NONUNIT_DIAG, ctx->AMat,ctx->vVec); DSDPCHKERR(info); info=PLA_Obj_set_to_minus_one(ctx->wVec);DSDPCHKERR(info); info=PLA_Axpy( ctx->one, ctx->vVec, ctx->wVec );DSDPCHKERR(info); info=PLA_Nrm2( ctx->wVec, ctx->dxerror );DSDPCHKERR(info); PLA_Obj_get_local_contents( ctx->dxerror, PLA_NO_TRANS, &dummy, &dummy, &ddxerror, 1, 1 ); if (ddxerror/sqrt(1.0*ctx->global_size) > 0.1){ *flag=1; if (ctx->rank==-1){ printf("PDSDPPLAPACK: Non positive-definite Matrix. %4.2e\n",ddxerror); } } wallclock(&ctx->t2); ctx->tsolve+=ctx->t2-ctx->t1; PPDSDPPrintTime(ctx->rank,"PLAPACK: Factor M",ctx->t2-ctx->t1,ctx->tsolve); PPDSDPPrintTime(ctx->rank,"Subtotal Time",0,ctx->t2-ctx->t1); DSDPFunctionReturn(0); }
void StaticServer::Validate() const { wallclock_t start = wallclock(); cout << "Validating statics files: "; for( unsigned short y = 0; y < _descriptor.height; y += STATICBLOCK_CHUNK ) { for( unsigned short x = 0; x < _descriptor.width; x += STATICBLOCK_CHUNK ) { ValidateBlock( x, y ); } } wallclock_t end = wallclock(); long ms = wallclock_diff_ms( start, end ); cout << "Completed in " << ms << " ms." << endl; }
void mace4_exit(int exit_code) { if (Opt && flag(Opt->verbose)) p_mem(); if (Opt && parm(Opt->report_stderr) > 0) fprintf(stderr, "Domain_size=%d. Models=%d. User_CPU=%.2f.\n", Domain_size, Total_models, user_seconds()); printf("\nUser_CPU=%.2f, System_CPU=%.2f, Wall_clock=%d.\n", user_seconds(), system_seconds(), wallclock()); if (Total_models == 0) printf("\nExiting with failure.\n"); else printf("\nExiting with %d model%s.\n", Total_models, Total_models == 1 ? "" : "s"); fprintf(stderr, "\n------ process %d exit (%s) ------\n", my_process_id(), exit_string(exit_code)); printf("\nProcess %d exit (%s) %s", my_process_id(), exit_string(exit_code), get_date()); printf("The process finished %s", get_date()); exit(exit_code); } /* mace4_exit */
nserror content__init(struct content *c, const content_handler *handler, lwc_string *imime_type, const http_parameter *params, llcache_handle *llcache, const char *fallback_charset, bool quirks) { struct content_user *user_sentinel; nserror error; LOG(("url "URL_FMT_SPC" -> %p", nsurl_access(llcache_handle_get_url(llcache)), c)); user_sentinel = calloc(1, sizeof(struct content_user)); if (user_sentinel == NULL) { return NSERROR_NOMEM; } if (fallback_charset != NULL) { c->fallback_charset = strdup(fallback_charset); if (c->fallback_charset == NULL) { free(user_sentinel); return NSERROR_NOMEM; } } c->llcache = llcache; c->mime_type = lwc_string_ref(imime_type); c->handler = handler; c->status = CONTENT_STATUS_LOADING; c->width = 0; c->height = 0; c->available_width = 0; c->quirks = quirks; c->refresh = 0; c->time = wallclock(); c->size = 0; c->title = NULL; c->active = 0; user_sentinel->callback = NULL; user_sentinel->pw = NULL; user_sentinel->next = NULL; c->user_list = user_sentinel; c->sub_status[0] = 0; c->locked = false; c->total_size = 0; c->http_code = 0; c->error_count = 0; content_set_status(c, messages_get("Loading")); /* Finally, claim low-level cache events */ error = llcache_handle_change_callback(llcache, content_llcache_callback, c); if (error != NSERROR_OK) { lwc_string_unref(c->mime_type); return error; } return NSERROR_OK; }
void content_set_done(struct content *c) { union content_msg_data msg_data; c->status = CONTENT_STATUS_DONE; c->time = wallclock() - c->time; content_update_status(c); content_broadcast(c, CONTENT_MSG_DONE, msg_data); }
static int pmatzero(void*MM){ plapackM* ctx=(plapackM*)MM; DSDPFunctionBegin; wallclock(&ctx->t1); PLA_Obj_set_to_zero(ctx->AMat); PLA_API_begin(); PLA_Obj_API_open(ctx->AMat); DSDPFunctionReturn(0); }
static int pmatassemble(void*MM){ plapackM* ctx=(plapackM*)MM; int info; DSDPFunctionBegin; /* info=pmatshiftdiagonal(MM,1.0e-13); */ info=PLA_Obj_API_close(ctx->AMat);DSDPCHKERR(info); info=PLA_API_end();DSDPCHKERR(info); wallclock(&ctx->t2); ctx->thessian+=ctx->t2-ctx->t1; PPDSDPPrintTime(ctx->rank,"Compute M",ctx->t2-ctx->t1,ctx->thessian); DSDPFunctionReturn(0); }
static int pmatsolve(void* MM, double bb[], double xx[], int n){ plapackM* ctx=(plapackM*)MM; double d_one=1.0,drank=1.0/ctx->nprocs; int i,info; DSDPFunctionBegin; wallclock(&ctx->t1); /* Copy RHS from DSDPVector to PLAPACK vector. This assumes the entries in the local DSDP Vectors are not duplicated on multiple processors. It adds the first element of each vector together, second element, ... */ info=PLA_Obj_set_to_zero(ctx->vVec);DSDPCHKERR(info); info=PLA_API_begin();DSDPCHKERR(info); info=PLA_Obj_API_open(ctx->vVec);DSDPCHKERR(info); info=PLA_API_axpy_vector_to_global(n, &d_one, bb , 1, ctx->vVec, 0); DSDPCHKERR(info); info=PLA_Obj_API_close(ctx->vVec); DSDPCHKERR(info); info=PLA_API_end(); DSDPCHKERR(info); /* Assuming the matrix is already factored, solve the equations. */ info = PLA_Trsv(PLA_LOWER_TRIANGULAR, PLA_NO_TRANSPOSE, PLA_NONUNIT_DIAG, ctx->AMat, ctx->vVec);DSDPCHKERR(info); info = PLA_Trsv(PLA_LOWER_TRIANGULAR, PLA_TRANSPOSE, PLA_NONUNIT_DIAG, ctx->AMat,ctx->vVec); DSDPCHKERR(info); /* Copy solution from PLAPACK vector to DSDPVector */ memset((void*)xx,0,n*sizeof(double)); info=PLA_API_begin(); info=PLA_Obj_API_open(ctx->vVec); info=PLA_API_axpy_global_to_vector(n, &d_one, ctx->vVec, 0, xx, 1); DSDPCHKERR(info); info=PLA_Obj_API_close(ctx->vVec); DSDPCHKERR(info); info=PLA_API_end(); DSDPCHKERR(info); for (i=0;i<n;i++){xx[i]*=drank;} wallclock(&ctx->t2); ctx->tsolve+=ctx->t2-ctx->t1; /* PPDSDPPrintTime(ctx->rank,"Solve M",ctx->t2-ctx->t1,ctx->tsolve);*/ DSDPFunctionReturn(0); }
int pmatsetup(void *MM, int m){ plapackM* ctx=(plapackM*)MM; MPI_Comm rowcomm,colcomm; int itmp,nprocs,info; DSDPFunctionBegin; ctx->global_size=m; info = MPI_Comm_size(ctx->mpi_comm,&nprocs); DSDPCHKERR(info); itmp=(m-nprocs+1)/nprocs; itmp=DSDPMax(2,itmp); ctx->nb_distr=DSDPMin(ctx->nb_distr,itmp); info = PLA_Comm_1D_to_2D_ratio(ctx->mpi_comm,ctx->ratio,&ctx->plapack_comm); DSDPCHKERR(info); info = PLA_Init(ctx->plapack_comm); DSDPCHKERR(info); info = PLA_Temp_create(ctx->nb_distr, 0, &ctx->templ); DSDPCHKERR(info); info=PLA_Matrix_create(MPI_DOUBLE, m, m, ctx->templ, PLA_ALIGN_FIRST, PLA_ALIGN_FIRST, &ctx->AMat);DSDPCHKERR(info); info=PLA_Mvector_create(MPI_DOUBLE, m, 1, ctx->templ, PLA_ALIGN_FIRST, &ctx->vVec);DSDPCHKERR(info); info=PLA_Mvector_create(MPI_DOUBLE, m, 1, ctx->templ, PLA_ALIGN_FIRST, &ctx->wVec);DSDPCHKERR(info); info=PLA_Mscalar_create( MPI_DOUBLE, PLA_ALL_ROWS, PLA_ALL_COLS, 1, 1, ctx->templ, &ctx->dxerror );DSDPCHKERR(info); info=PLA_Mscalar_create( MPI_DOUBLE, PLA_ALL_ROWS, PLA_ALL_COLS, 1, 1, ctx->templ, &ctx->one );DSDPCHKERR(info); info=PLA_Mscalar_create( MPI_DOUBLE, PLA_ALL_ROWS, PLA_ALL_COLS, 1, 1, ctx->templ, &ctx->zero );DSDPCHKERR(info); info=PLA_Obj_set_to_one(ctx->one);DSDPCHKERR(info); info=PLA_Obj_set_to_zero(ctx->zero);DSDPCHKERR(info); info = MPI_Comm_rank(ctx->plapack_comm,&ctx->rank); DSDPCHKERR(info); info = MPI_Comm_size(ctx->plapack_comm,&ctx->nprocs); DSDPCHKERR(info); info = PLA_Temp_comm_col_info(ctx->templ, &rowcomm, &ctx->rowrank, &ctx->numrownodes); DSDPCHKERR(info); info = PLA_Temp_comm_row_info(ctx->templ, &colcomm, &ctx->colrank, &ctx->numcolnodes); DSDPCHKERR(info); ctx->t0=0;ctx->t1=0;ctx->t2=0; ctx->thessian=0;ctx->tsolve=0; wallclock(&ctx->t0); DSDPFunctionReturn(0); }
bool run(int argc, char **argv) { for( unsigned pi = 0; pi < compilercfg.PackageRoot.size(); ++pi ) { load_packages( compilercfg.PackageRoot[pi], true /* quiet */ ); } replace_packages(); check_package_deps(); wallclock_t start = wallclock(); bool any = false; for(int i=1;i<argc;i++) { #ifdef __linux__ if (argv[i][0] == '-') #else if (argv[i][0] == '/' || argv[i][0] == '-') #endif { // -r[i] [<dir>] if (argv[i][1] == 'A') { compilercfg.UpdateOnlyOnAutoCompile = (argv[i][2] == 'u'); any = true; AutoCompile(); } else if (argv[i][1] == 'r') { any = true; string dir("."); bool compile_inc = (argv[i][2] == 'i'); // compile .inc files ++i; if (i<argc && argv[i] && argv[i][0] != '-') dir.assign(argv[i]); if (compilercfg.ThreadedCompilation) { vector<string> files; if (compile_inc) recurse_compile_inc( normalized_dir_form( dir ), &files ); else recurse_compile( normalized_dir_form( dir ),&files ); parallel_compile(files); } else { if (compile_inc) recurse_compile_inc( normalized_dir_form( dir ), NULL ); else recurse_compile( normalized_dir_form( dir ),NULL ); } } else if (argv[i][1] == 'C') { ++i; // skip the config file pathname } // and skip any other option. } else { any = true; #ifdef _WIN32 forspec(argv[i], compile_file_wrapper); #else compile_file_wrapper( argv[i] ); #endif } } if (!any && compilercfg.AutoCompileByDefault) { any = true; AutoCompile(); } wallclock_t finish = wallclock(); unload_packages(); if (any && compilercfg.DisplaySummary && !quiet) { cout << "Compilation Summary:" << endl; if (summary.CompiledScripts) cout << " Compiled " << summary.CompiledScripts << " script" << (summary.CompiledScripts==1?"":"s") << " in " << wallclock_diff_ms( start, finish ) << " ms." << endl; if (summary.ScriptsWithCompileErrors) cout << " " << summary.ScriptsWithCompileErrors << " of those script" << (summary.ScriptsWithCompileErrors==1?"":"s") << " had errors." << endl; if (summary.UpToDateScripts) cout << " " << summary.UpToDateScripts << " script" << (summary.UpToDateScripts==1?" was":"s were") << " already up-to-date." << endl; } return any; }
/* called back when click in browser window */ static int fb_browser_window_click(fbtk_widget_t *widget, fbtk_callback_info *cbi) { struct gui_window *gw = cbi->context; struct browser_widget_s *bwidget = fbtk_get_userpw(widget); browser_mouse_state mouse; float scale = browser_window_get_scale(gw->bw); int x = (cbi->x + bwidget->scrollx) / scale; int y = (cbi->y + bwidget->scrolly) / scale; unsigned int time_now; static struct { enum { CLICK_SINGLE, CLICK_DOUBLE, CLICK_TRIPLE } type; unsigned int time; } last_click; if (cbi->event->type != NSFB_EVENT_KEY_DOWN && cbi->event->type != NSFB_EVENT_KEY_UP) return 0; LOG(("browser window clicked at %d,%d", cbi->x, cbi->y)); switch (cbi->event->type) { case NSFB_EVENT_KEY_DOWN: switch (cbi->event->value.keycode) { case NSFB_KEY_MOUSE_1: browser_window_mouse_click(gw->bw, BROWSER_MOUSE_PRESS_1, x, y); gui_drag.state = GUI_DRAG_PRESSED; gui_drag.button = 1; gui_drag.x = x; gui_drag.y = y; break; #if 0 case NSFB_KEY_MOUSE_3: browser_window_mouse_click(gw->bw, BROWSER_MOUSE_PRESS_2, x, y); gui_drag.state = GUI_DRAG_PRESSED; gui_drag.button = 2; gui_drag.x = x; gui_drag.y = y; break; #else case NSFB_KEY_MOUSE_2: /* scroll right */ if (browser_window_scroll_at_point(gw->bw, x, y, 100, 0) == false) widget_scroll_x(gw, 100, false); break; case NSFB_KEY_MOUSE_3: /* scroll left */ if (browser_window_scroll_at_point(gw->bw, x, y, -100, 0) == false) widget_scroll_x(gw, -100, false); break; #endif case NSFB_KEY_MOUSE_4: /* scroll up */ if (browser_window_scroll_at_point(gw->bw, x, y, 0, -100) == false) { widget_scroll_y(gw, -100, false); } break; case NSFB_KEY_MOUSE_5: /* scroll down */ if (browser_window_scroll_at_point(gw->bw, x, y, 0, 100) == false) { widget_scroll_y(gw, 100, false); } break; default: break; } break; case NSFB_EVENT_KEY_UP: mouse = 0; time_now = wallclock(); switch (cbi->event->value.keycode) { case NSFB_KEY_MOUSE_1: if (gui_drag.state == GUI_DRAG_DRAG) { /* End of a drag, rather than click */ if (gui_drag.grabbed_pointer) { /* need to ungrab pointer */ fbtk_tgrab_pointer(widget); gui_drag.grabbed_pointer = false; } gui_drag.state = GUI_DRAG_NONE; /* Tell core */ browser_window_mouse_track(gw->bw, 0, x, y); break; } /* This is a click; * clear PRESSED state and pass to core */ gui_drag.state = GUI_DRAG_NONE; mouse = BROWSER_MOUSE_CLICK_1; break; #if 0 case NSFB_KEY_MOUSE_3: if (gui_drag.state == GUI_DRAG_DRAG) { /* End of a drag, rather than click */ gui_drag.state = GUI_DRAG_NONE; if (gui_drag.grabbed_pointer) { /* need to ungrab pointer */ fbtk_tgrab_pointer(widget); gui_drag.grabbed_pointer = false; } /* Tell core */ browser_window_mouse_track(gw->bw, 0, x, y); break; } /* This is a click; * clear PRESSED state and pass to core */ gui_drag.state = GUI_DRAG_NONE; mouse = BROWSER_MOUSE_CLICK_2; break; #endif default: break; } /* Determine if it's a double or triple click, allowing * 0.5 seconds (50cs) between clicks */ if (time_now < last_click.time + 50 && cbi->event->value.keycode != NSFB_KEY_MOUSE_4 && cbi->event->value.keycode != NSFB_KEY_MOUSE_5) { if (last_click.type == CLICK_SINGLE) { /* Set double click */ mouse |= BROWSER_MOUSE_DOUBLE_CLICK; last_click.type = CLICK_DOUBLE; } else if (last_click.type == CLICK_DOUBLE) { /* Set triple click */ mouse |= BROWSER_MOUSE_TRIPLE_CLICK; last_click.type = CLICK_TRIPLE; } else { /* Set normal click */ last_click.type = CLICK_SINGLE; } } else { last_click.type = CLICK_SINGLE; } if (mouse) browser_window_mouse_click(gw->bw, mouse, x, y); last_click.time = time_now; break; default: break; } return 1; }
int main( int argc, char*argv[] ) { float *p_old,*p_new,*p_tmp; int n,nn; float gosa,gflops,thruput,thruput2; double time_start,time_max,target,bytes; cudaStream_t stream_top,stream_btm; NP=1; gpu=0; ME=0; target= 60.0; omega= 0.8f; imax = MIMAX-1; jmax = MJMAX-1; kmax = MKMAX-1; imax_global = NP*(imax-2)+2; nn = ITERS; if(ME==0) { printf("\n mimax = %d mjmax = %d mkmax = %d pitch = %d\n",MIMAX, MJMAX, MKMAX, PITCH); printf(" imax = %d jmax = %d kmax = %d\n",imax_global,jmax,kmax); printf(" gridX = %d gridY = %d blockX = %d blockY = %d\n", GRID_X, GRID_Y, BLOCK_X, BLOCK_Y); } //printf("There are %d processes, I am process# %d using GPU %d\n",NP,ME,gpu); CUDA_SAFE_CALL(cudaSetDevice(gpu)); stream_top = 0; stream_btm = 0; #if (CUDART_VERSION >= 3000) { #if (CUDART_VERSION > 3000) struct cudaDeviceProp prop; // display ECC configuration, only queryable post r3.0 CUDA_SAFE_CALL(cudaGetDeviceProperties(&prop, gpu)); printf (" ECC on GPU %d is %s\n", gpu, prop.ECCEnabled ? "ON" : "OFF"); #endif /* CUDART_VERSION > 3000 */ // configure kernels for large shared memory to get better occupancy printf (" Configuring GPU L1 cache size ...\n"); set_kernel_cache_config (cudaFuncCachePreferShared); } #endif /* CUDART_VERSION >= 3000 */ CUDA_SAFE_CALL(cudaStreamCreate(&stream_top)); CUDA_SAFE_CALL(cudaStreamCreate(&stream_btm)); if(ME==0) printf(" Allocating Memory...\n"); allocate_memory(); if(ME==0) printf(" Initializing Data...\n\n"); initmt(); if(ME==0) { printf(" Now, start GPU measurement process.\n"); printf(" The loop will be excuted %d times\n",nn); printf(" Wait for a while\n\n"); } time_start = wallclock(); gosa = 0.0f; p_new = p2_d; p_old = p1_d; for(n=0 ; n<nn; n++) { //swap pointers p_tmp = p_new; p_new = p_old; p_old = p_tmp; jacobi_GPU_btm_even (stream_btm,a0_d,a1_d,a2_d,a3_d,b0_d,b1_d,b2_d,c0_d, c1_d,c2_d,wrk_d,bnd_d,p_old,p_new,gosa_d,omega,n); cudaMemcpyAsync (gosa_btm, gosa_d, sizeof(float), cudaMemcpyDeviceToHost, stream_btm); // Since we want to print intermediate values of gosa every PRINT_ITER // iterations, we need to synchronize before picking up the asynchronously // updated value. if (!(n % PRINT_ITER)) { cudaStreamSynchronize(stream_btm); gosa = *gosa_btm; } if(ME==0 && n%PRINT_ITER==0) printf(" iter: %d \tgosa: %e\n",n,gosa); } cudaThreadSynchronize(); gosa = *gosa_btm; time_max = wallclock() - time_start; gflops = (float)(34.0*( (double)nn*(double)(imax_global-2)*(double)(jmax-2)*(double)(kmax-2) ) / time_max * 1e-9); bytes = NP*((double)nn*(56.0*(imax-2)+8.0)*(double)(jmax)*(double)(kmax)); thruput = (float)(bytes / time_max / 1024.0 / 1024.0 / 1024.0); thruput2 = (float)(bytes / time_max / 1e9); if(ME==0) { printf(" \nLoop executed for %d times\n",nn); printf(" Gosa : %e \n",gosa); printf(" total Compute : %4.1f GFLOPS\ttime : %f seconds\n",gflops,time_max); printf(" total Bandwidth : %4.1f GB/s\n", thruput); printf(" total Bandwidth : %4.1f GB/s (STREAM equivalent)\n",thruput2); printf(" Score based on Pentium III 600MHz : %f\n\n",1000.0*gflops/82.0); } cleanup(); CUDA_SAFE_CALL(cudaStreamDestroy(stream_top)); CUDA_SAFE_CALL(cudaStreamDestroy(stream_btm)); //check_results(); return (EXIT_SUCCESS); }
static nserror html_object_callback(hlcache_handle *object, const hlcache_event *event, void *pw) { struct content_html_object *o = pw; html_content *c = (html_content *) o->parent; int x, y; struct box *box; assert(c->base.status != CONTENT_STATUS_ERROR); box = o->box; if (box == NULL && event->type != CONTENT_MSG_ERROR) { return NSERROR_OK; } switch (event->type) { case CONTENT_MSG_LOADING: if (c->base.status != CONTENT_STATUS_LOADING && c->bw != NULL) content_open(object, c->bw, &c->base, box->object_params); break; case CONTENT_MSG_READY: if (content_can_reformat(object)) { /* TODO: avoid knowledge of box internals here */ content_reformat(object, false, box->max_width != UNKNOWN_MAX_WIDTH ? box->width : 0, box->max_width != UNKNOWN_MAX_WIDTH ? box->height : 0); /* Adjust parent content for new object size */ html_object_done(box, object, o->background); if (c->base.status == CONTENT_STATUS_READY || c->base.status == CONTENT_STATUS_DONE) content__reformat(&c->base, false, c->base.available_width, c->base.height); } break; case CONTENT_MSG_DONE: c->base.active--; LOG("%d fetches active", c->base.active); html_object_done(box, object, o->background); if (c->base.status != CONTENT_STATUS_LOADING && box->flags & REPLACE_DIM) { union content_msg_data data; if (!box_visible(box)) break; box_coords(box, &x, &y); data.redraw.x = x + box->padding[LEFT]; data.redraw.y = y + box->padding[TOP]; data.redraw.width = box->width; data.redraw.height = box->height; data.redraw.full_redraw = true; content_broadcast(&c->base, CONTENT_MSG_REDRAW, data); } break; case CONTENT_MSG_ERROR: hlcache_handle_release(object); o->content = NULL; if (box != NULL) { c->base.active--; LOG("%d fetches active", c->base.active); content_add_error(&c->base, "?", 0); html_object_failed(box, c, o->background); } break; case CONTENT_MSG_REDRAW: if (c->base.status != CONTENT_STATUS_LOADING) { union content_msg_data data = event->data; if (!box_visible(box)) break; box_coords(box, &x, &y); if (object == box->background) { /* Redraw request is for background */ css_fixed hpos = 0, vpos = 0; css_unit hunit = CSS_UNIT_PX; css_unit vunit = CSS_UNIT_PX; int width = box->padding[LEFT] + box->width + box->padding[RIGHT]; int height = box->padding[TOP] + box->height + box->padding[BOTTOM]; int t, h, l, w; /* Need to know background-position */ css_computed_background_position(box->style, &hpos, &hunit, &vpos, &vunit); w = content_get_width(box->background); if (hunit == CSS_UNIT_PCT) { l = (width - w) * hpos / INTTOFIX(100); } else { l = FIXTOINT(nscss_len2px(hpos, hunit, box->style)); } h = content_get_height(box->background); if (vunit == CSS_UNIT_PCT) { t = (height - h) * vpos / INTTOFIX(100); } else { t = FIXTOINT(nscss_len2px(vpos, vunit, box->style)); } /* Redraw area depends on background-repeat */ switch (css_computed_background_repeat( box->style)) { case CSS_BACKGROUND_REPEAT_REPEAT: data.redraw.x = 0; data.redraw.y = 0; data.redraw.width = box->width; data.redraw.height = box->height; break; case CSS_BACKGROUND_REPEAT_REPEAT_X: data.redraw.x = 0; data.redraw.y += t; data.redraw.width = box->width; break; case CSS_BACKGROUND_REPEAT_REPEAT_Y: data.redraw.x += l; data.redraw.y = 0; data.redraw.height = box->height; break; case CSS_BACKGROUND_REPEAT_NO_REPEAT: data.redraw.x += l; data.redraw.y += t; break; default: break; } data.redraw.object_width = box->width; data.redraw.object_height = box->height; /* Add offset to box */ data.redraw.x += x; data.redraw.y += y; data.redraw.object_x += x; data.redraw.object_y += y; content_broadcast(&c->base, CONTENT_MSG_REDRAW, data); break; } else { /* Non-background case */ if (hlcache_handle_get_content(object) == event->data.redraw.object) { int w = content_get_width(object); int h = content_get_height(object); if (w != 0) { data.redraw.x = data.redraw.x * box->width / w; data.redraw.width = data.redraw.width * box->width / w; } if (h != 0) { data.redraw.y = data.redraw.y * box->height / h; data.redraw.height = data.redraw.height * box->height / h; } data.redraw.object_width = box->width; data.redraw.object_height = box->height; } data.redraw.x += x + box->padding[LEFT]; data.redraw.y += y + box->padding[TOP]; data.redraw.object_x += x + box->padding[LEFT]; data.redraw.object_y += y + box->padding[TOP]; } content_broadcast(&c->base, CONTENT_MSG_REDRAW, data); } break; case CONTENT_MSG_REFRESH: if (content_get_type(object) == CONTENT_HTML) { /* only for HTML objects */ guit->misc->schedule(event->data.delay * 1000, html_object_refresh, o); } break; case CONTENT_MSG_LINK: /* Don't care about favicons that aren't on top level content */ break; case CONTENT_MSG_GETCTX: *(event->data.jscontext) = NULL; break; case CONTENT_MSG_SCROLL: if (box->scroll_x != NULL) scrollbar_set(box->scroll_x, event->data.scroll.x0, false); if (box->scroll_y != NULL) scrollbar_set(box->scroll_y, event->data.scroll.y0, false); break; case CONTENT_MSG_DRAGSAVE: { union content_msg_data msg_data; if (event->data.dragsave.content == NULL) msg_data.dragsave.content = object; else msg_data.dragsave.content = event->data.dragsave.content; content_broadcast(&c->base, CONTENT_MSG_DRAGSAVE, msg_data); } break; case CONTENT_MSG_SAVELINK: case CONTENT_MSG_POINTER: case CONTENT_MSG_SELECTMENU: case CONTENT_MSG_GADGETCLICK: /* These messages are for browser window layer. * we're not interested, so pass them on. */ content_broadcast(&c->base, event->type, event->data); break; case CONTENT_MSG_CARET: { union html_focus_owner focus_owner; focus_owner.content = box; switch (event->data.caret.type) { case CONTENT_CARET_REMOVE: case CONTENT_CARET_HIDE: html_set_focus(c, HTML_FOCUS_CONTENT, focus_owner, true, 0, 0, 0, NULL); break; case CONTENT_CARET_SET_POS: html_set_focus(c, HTML_FOCUS_CONTENT, focus_owner, false, event->data.caret.pos.x, event->data.caret.pos.y, event->data.caret.pos.height, event->data.caret.pos.clip); break; } } break; case CONTENT_MSG_DRAG: { html_drag_type drag_type = HTML_DRAG_NONE; union html_drag_owner drag_owner; drag_owner.content = box; switch (event->data.drag.type) { case CONTENT_DRAG_NONE: drag_type = HTML_DRAG_NONE; drag_owner.no_owner = true; break; case CONTENT_DRAG_SCROLL: drag_type = HTML_DRAG_CONTENT_SCROLL; break; case CONTENT_DRAG_SELECTION: drag_type = HTML_DRAG_CONTENT_SELECTION; break; } html_set_drag_type(c, drag_type, drag_owner, event->data.drag.rect); } break; case CONTENT_MSG_SELECTION: { html_selection_type sel_type; union html_selection_owner sel_owner; if (event->data.selection.selection) { sel_type = HTML_SELECTION_CONTENT; sel_owner.content = box; } else { sel_type = HTML_SELECTION_NONE; sel_owner.none = true; } html_set_selection(c, sel_type, sel_owner, event->data.selection.read_only); } break; default: break; } if (c->base.status == CONTENT_STATUS_READY && c->base.active == 0 && (event->type == CONTENT_MSG_LOADING || event->type == CONTENT_MSG_DONE || event->type == CONTENT_MSG_ERROR)) { /* all objects have arrived */ content__reformat(&c->base, false, c->base.available_width, c->base.height); content_set_done(&c->base); } /* If 1) the configuration option to reflow pages while objects are * fetched is set * 2) an object is newly fetched & converted, * 3) the box's dimensions need to change due to being replaced * 4) the object's parent HTML is ready for reformat, * 5) the time since the previous reformat is more than the * configured minimum time between reformats * then reformat the page to display newly fetched objects */ else if (nsoption_bool(incremental_reflow) && event->type == CONTENT_MSG_DONE && box != NULL && !(box->flags & REPLACE_DIM) && (c->base.status == CONTENT_STATUS_READY || c->base.status == CONTENT_STATUS_DONE) && (wallclock() > c->base.reformat_time)) { content__reformat(&c->base, false, c->base.available_width, c->base.height); } return NSERROR_OK; }