void GetPMLvalues(const GlobalOrdinal i, const GlobalOrdinal nx, const GlobalOrdinal ny, const GlobalOrdinal nz, const double h, const double delta, const double Dx, const double Dy, const double Dz, const double LBx, const double RBx, const double LBy, const double RBy, const double LBz, const double RBz, Scalar& sx_left, Scalar& sx_center, Scalar& sx_right, Scalar& sy_left, Scalar& sy_center, Scalar& sy_right, Scalar& sz_left, Scalar& sz_center, Scalar& sz_right) { GlobalOrdinal ixy, ix, iy, iz; ixy = i % (nx * ny); iz = (i - ixy) / (nx * ny); ix = ixy % nx; iy = (ixy - ix) / nx; double xcoord, ycoord, zcoord; xcoord=((double) ix)*h; ycoord=((double) iy)*h; zcoord=((double) iz)*h; double Lx=std::max(LBx,Dx-RBx); if(Lx==0.0) { Lx=1.0; } double Ly=std::max(LBy,Dy-RBy); if(Ly==0.0) { Ly=1.0; } double Lz=std::max(LBz,Dz-RBz); if(Lz==0.0) { Lz=1.0; } GetStretch(xcoord-h,delta,LBx,RBx,Lx,sx_left); GetStretch(xcoord+0,delta,LBx,RBx,Lx,sx_center); GetStretch(xcoord+h,delta,LBx,RBx,Lx,sx_right); GetStretch(ycoord-h,delta,LBy,RBy,Ly,sy_left); GetStretch(ycoord+0,delta,LBy,RBy,Ly,sy_center); GetStretch(ycoord+h,delta,LBy,RBy,Ly,sy_right); GetStretch(zcoord-h,delta,LBz,RBz,Lz,sz_left); GetStretch(zcoord+0,delta,LBz,RBz,Lz,sz_center); GetStretch(zcoord+h,delta,LBz,RBz,Lz,sz_right); }
Rect Image::GetCoverageBounds () { // FIXME: SL3 final only supports PixelFormatPbgra32 which makes this optimization // obsolete - unless we keep an "has_alpha" flag with each image ?!? return Rect (); #if FALSE ImageSource *source = GetSource (); if (!source || source->GetPixelFormat () == PixelFormatPbgra32) return Rect (); Stretch stretch = GetStretch (); if (stretch == StretchFill || stretch == StretchUniformToFill) return bounds; cairo_matrix_t matrix; Rect image = Rect (0, 0, source->GetPixelWidth (), source->GetPixelHeight ()); Rect paint = Rect (0, 0, GetActualWidth (), GetActualHeight ()); image_brush_compute_pattern_matrix (&matrix, paint.width, paint.height, image.width, image.height, stretch, AlignmentXCenter, AlignmentYCenter, NULL, NULL); cairo_matrix_invert (&matrix); cairo_matrix_multiply (&matrix, &matrix, &absolute_xform); image = image.Transform (&matrix); image = image.Intersection (bounds); return image; #endif }
Size Image::MeasureOverrideWithError (Size availableSize, MoonError *error) { Size desired = availableSize; Rect shape_bounds = Rect (); ImageSource *source = GetSource (); double sx = 0.0; double sy = 0.0; if (source) shape_bounds = Rect (0,0,source->GetPixelWidth (),source->GetPixelHeight ()); /* don't stretch to infinite size */ if (isinf (desired.width)) desired.width = shape_bounds.width; if (isinf (desired.height)) desired.height = shape_bounds.height; /* compute the scaling */ if (shape_bounds.width > 0) sx = desired.width / shape_bounds.width; if (shape_bounds.height > 0) sy = desired.height / shape_bounds.height; /* don't use infinite dimensions as constraints */ if (isinf (availableSize.width)) sx = sy; if (isinf (availableSize.height)) sy = sx; switch (GetStretch ()) { case StretchUniform: sx = sy = MIN (sx, sy); break; case StretchUniformToFill: sx = sy = MAX (sx, sy); break; case StretchFill: if (isinf (availableSize.width)) sx = sy; if (isinf (availableSize.height)) sy = sx; break; case StretchNone: sx = sy = 1.0; break; } desired = Size (shape_bounds.width * sx, shape_bounds.height * sy); return desired; }
Size Image::ArrangeOverrideWithError (Size finalSize, MoonError *error) { Size arranged = finalSize; Rect shape_bounds = Rect (); ImageSource *source = GetSource (); double sx = 1.0; double sy = 1.0; if (source) shape_bounds = Rect (0, 0, source->GetPixelWidth (), source->GetPixelHeight ()); /* compute the scaling */ if (shape_bounds.width == 0) shape_bounds.width = arranged.width; if (shape_bounds.height == 0) shape_bounds.height = arranged.height; if (shape_bounds.width != arranged.width) sx = arranged.width / shape_bounds.width; if (shape_bounds.height != arranged.height) sy = arranged.height / shape_bounds.height; switch (GetStretch ()) { case StretchUniform: sx = sy = MIN (sx, sy); break; case StretchUniformToFill: sx = sy = MAX (sx, sy); break; case StretchNone: sx = sy = 1.0; default: break; } arranged = Size (shape_bounds.width * sx, shape_bounds.height * sy); return arranged; }
void GetPMLvalues(const GlobalOrdinal i, const GlobalOrdinal nx, const GlobalOrdinal ny, const double h, const double delta, const double Dx, const double Dy, const double LBx, const double RBx, const double LBy, const double RBy, Scalar& sx_left, Scalar& sx_center, Scalar& sx_right, Scalar& sy_left, Scalar& sy_center, Scalar& sy_right) { GlobalOrdinal ix, iy; ix = i % nx; iy = (i - ix) / nx; double xcoord, ycoord; xcoord=((double) ix)*h; ycoord=((double) iy)*h; double Lx=std::max(LBx,Dx-RBx); if(Lx==0.0) { Lx=1.0; } double Ly=std::max(LBy,Dy-RBy); if(Ly==0.0) { Ly=1.0; } GetStretch(xcoord-h,delta,LBx,RBx,Lx,sx_left); GetStretch(xcoord+0,delta,LBx,RBx,Lx,sx_center); GetStretch(xcoord+h,delta,LBx,RBx,Lx,sx_right); GetStretch(ycoord-h,delta,LBy,RBy,Ly,sy_left); GetStretch(ycoord+0,delta,LBy,RBy,Ly,sy_center); GetStretch(ycoord+h,delta,LBy,RBy,Ly,sy_right); }
CPath2008 StretchIntersectItem::GetPath() { return GetStretch()->GetPath(); }
static IDCOffer_clp Mount_m(MountLocal_cl *self, IDCOffer_clp drive, uint32_t partition, MountLocal_Options options, Context_clp settings) { IDCOffer_clp res; ext2fs_st *st; Type_Any any; Heap_clp heap; struct inode *root = NULL; uint32_t blockcache_size = 1024*128; /* Size of blockcache in bytes */ CSClientStubMod_cl *stubmod_clp; TRC(printf("ext2fs: mount %d from %p\n", partition, drive)); /* It's probably a good idea to have a separate heap for the filesystem. For now let's just use Pvs(heap), but eventually create a stretch of our own. */ heap = Pvs(heap); if(!(st = Heap$Malloc(heap, sizeof(*st)))) { fprintf(stderr, "ext2fs: cannot allocate state.\n"); RAISE_MountLocal$Failure(); } /* Where is this declared? */ bzero(st, sizeof(*st)); /* Fill in the fields that we can initialise without accessing the filesystem */ st->heap = heap; st->entrymod = NAME_FIND("modules>EntryMod", EntryMod_clp); st->shmtransport = NAME_FIND("modules>ShmTransport", IDCTransport_clp); st->csidc = NAME_FIND("modules>CSIDCTransport", CSIDCTransport_clp); st->client.entry = Pvs(entry); /* It's not clearn how many entries we are going to require yet We probably want separate ones for the USDCallback and the FSClient offers. We need to arrange that the entry threads die properly when the FS is unmounted. */ /* Interpret mount flags */ st->fs.readonly = SET_IN(options,MountLocal_Option_ReadOnly); st->fs.debug = SET_IN(options,MountLocal_Option_Debug); /* Place the drive in the state. */ st->disk.partition = partition; st->disk.drive_offer = drive; st->disk.drive_binding = IDCOffer$Bind(drive, Pvs(gkpr), &any); st->disk.usddrive = NARROW(&any, USDDrive_clp); TRC(printf("ext2fs: state at [%p, %p]\n",st, (void *)st + sizeof(*st))); DBO(printf("ext2fs: debugging output is switched on\n")); /* Connect to the disk */ init_usd(st); /* We need a stretch shared between us and the USD to allow us to read and write metadata. We'll use this stretch as a cache of blocks read from the disk. Because we won't know the blocksize until we have managed to read the superblock, we'd better make this buffer a multiple of 8k long (8k is currently the maximum blocksize). */ st->cache.str = Gatekeeper$GetStretch(Pvs(gkpr), IDCOffer$PDID(drive), blockcache_size, SET_ELEM(Stretch_Right_Read) | SET_ELEM(Stretch_Right_Write), PAGE_WIDTH, PAGE_WIDTH); st->cache.buf = STR_RANGE(st->cache.str, &st->cache.size); TRC(printf("ext2fs: buf is %d bytes at %p\n", st->cache.size, st->cache.buf)); if (st->cache.size < blockcache_size) { printf("ext2fs: warning: couldn't allocate a large blockcache\n"); } /* Now we can get at the disk. Read the superblock, and calculate constants from it. */ if (!read_superblock(st)) { printf("ext2fs: couldn't read superblock\n"); shutdown_usd(st); RAISE_MountLocal$BadFS(MountLocal_Problem_BadSuperblock); } /* XXX should sanity check filesystem size with partition size */ TRC(printf("ext2fs: filesystem size %d blocks (%d phys)\n" " partition size %d blocks (%d phys)\n", st->superblock->s_blocks_count, PHYS_BLKS(st, st->superblock->s_blocks_count), LOGICAL_BLKS(st, st->disk.partition_size), st->disk.partition_size)); if (st->disk.partition_size < PHYS_BLKS(st, st->superblock->s_blocks_count)) { printf("WARNING - filesystem is larger than partition **********\n"); /* XXX should probably give up now */ } /* Now that we know the logical block size we can initialise the block cache */ init_block_cache(st); /* From this point on, all access to the filesystem should be done through the block cache. DON'T call logical_read, call bread instead. Remember to free blocks once you're finished with them. */ init_groups(st); if(!init_inodes(st)) { fprintf(stderr, "ext2fs: failed to initialise inode cache.\n"); shutdown_usd(st); RAISE_MountLocal$Failure(); } /* Checking this probably isn't a bad idea, but let's wait until later */ /* Ok, now we are capable of reading the root inode (I hope!) */ TRC(printf("ext2fs: checking root inode.\n")); root = get_inode(st, EXT2_ROOT_INO); if(!root) { fprintf(stderr, "ext2fs: failed to read root inode.\n"); shutdown_usd(st); RAISE_MountLocal$BadFS(MountLocal_Problem_BadRoot); } if(!S_ISDIR(root->i_mode)) { fprintf(stderr, "ext2fs: urk!\n" " inode %d does not refer to a directory\n", EXT2_ROOT_INO); shutdown_usd(st); RAISE_MountLocal$BadFS(MountLocal_Problem_BadRoot); } release_inode(st, root); /* *thinks* should probably do something about deallocating state if we fail, too. */ /* Initialise the list of clients */ LINK_INIT(&st->client.clients); /* We create a server for the local domain; it lives in the head of the list of clients. The call to CSIDCTransport$Offer() will set up client-side stubs for this domain and put them in the object table. */ create_client(st, &st->client.clients, NULL); /* Now we do all the export stuff */ CL_INIT(st->client.callback, &client_callback_ms, st); ANY_INIT(&any, Ext2_clp, &st->client.clients.cl); stubmod_clp = Heap$Malloc(st->heap, sizeof(*stubmod_clp)); CLP_INIT(stubmod_clp, &stubmod_ms, NULL); res = CSIDCTransport$Offer ( st->csidc, &any, FSClient_clp__code, stubmod_clp, &st->client.callback, /* XXX produces a warning */ st->heap, Pvs(gkpr), st->client.entry, &st->client.service); TRC(printf("ext2fs: offer at %p\n",res)); return res; }
void Image::Render (cairo_t *cr, Region *region, bool path_only) { ImageSource *source = GetSource (); cairo_pattern_t *pattern = NULL; cairo_matrix_t matrix; if (!source) return; source->Lock (); cairo_save (cr); Size specified (GetActualWidth (), GetActualHeight ()); Size stretched = ApplySizeConstraints (specified); bool adjust = specified != GetRenderSize (); if (GetStretch () != StretchUniformToFill) specified = specified.Min (stretched); Rect paint = Rect (0, 0, specified.width, specified.height); if (!path_only) { Rect image = Rect (0, 0, source->GetPixelWidth (), source->GetPixelHeight ()); if (GetStretch () == StretchNone) paint = paint.Union (image); if (image.width == 0.0 && image.height == 0.0) goto cleanup; pattern = cairo_pattern_create_for_surface (source->GetSurface (cr)); image_brush_compute_pattern_matrix (&matrix, paint.width, paint.height, image.width, image.height, GetStretch (), AlignmentXCenter, AlignmentYCenter, NULL, NULL); cairo_pattern_set_matrix (pattern, &matrix); #if MAKE_EVERYTHING_SLOW_AND_BUGGY cairo_pattern_set_extend (pattern, CAIRO_EXTEND_PAD); #endif if (cairo_pattern_status (pattern) == CAIRO_STATUS_SUCCESS) { cairo_set_source (cr, pattern); } cairo_pattern_destroy (pattern); } if (adjust) { // FIXME: Propagate error properly MoonError error; specified = MeasureOverrideWithError (specified, &error); paint = Rect ((stretched.width - specified.width) * 0.5, (stretched.height - specified.height) * 0.5, specified.width, specified.height); } if (!path_only) RenderLayoutClip (cr); paint = paint.Intersection (Rect (0, 0, stretched.width, stretched.height)); paint.Draw (cr); if (!path_only) cairo_fill (cr); cleanup: cairo_restore (cr); source->Unlock (); }