int main(void) { FILE *in=fopen("milk2.in", "r"), *out=fopen("milk2.out", "w"); milking_period periods[MAX_N]; long int longest_ws=0, longest_we=0, longest_wt=0, longest_it=0; int i, n; fscanf(in, "%d\n", &n); for (i=0; i < n; i++) { fscanf(in, "%ld %ld\n", &periods[i].s, &periods[i].e); } qsort(periods, n, sizeof(milking_period), cmp_period); for (i=0; i < n; i++) { if (INTERSECTS(periods[i].s, periods[i].e, longest_ws, longest_we)) { longest_ws = MIN(longest_ws, periods[i].s); longest_we = MAX(longest_we, periods[i].e); } else { if (i) longest_it = MAX(longest_it, periods[i].s - longest_we); longest_ws = periods[i].s; longest_we = periods[i].e; } longest_wt = MAX(longest_wt, longest_we - longest_ws); } fprintf(out, "%ld %ld\n", longest_wt, longest_it); fclose(in); fclose(out); return 0; }
/* * Prints warning message for the bytes in the file that couldn't be recovered. * Uses 0/0 for offset/size to signal end of all lost data. */ static void warn_lost_data (pid_t pid, Elf32_Ehdr *ehdr, Elf32_Phdr *phdr, unsigned int offset, unsigned int size) { static unsigned int last_offset = 0; /* for recording last offset */ static unsigned int last_size = 0; /* and size - initialised to zero */ int p; if (offset != 0 && size != 0) { if ((last_offset + last_size) == offset) { /* join offsets */ last_size += size; return; } } if (last_offset != 0 && last_size != 0) { fprintf(stderr, "could not recover data - %d bytes at file offset %d\n", last_size, last_offset); for (p = 0; p < ehdr->e_phnum; p++) { if (phdr[p].p_type != PT_NULL) { if (INTERSECTS(last_offset, last_size, phdr[p].p_offset, phdr[p].p_filesz)) { fprintf(stderr, " ! data from phdr[%d] was not recovered\n", p); } } } if ((ehdr->e_shnum != 0) && INTERSECTS(last_offset, last_size, ehdr->e_shoff, ehdr->e_shnum * ehdr->e_shentsize)) { fprintf(stderr, " ! section header table was not recovered\n"); } } /* record this offset and size */ last_offset = offset; last_size = size; }
int clientwin_validate_func(dlist *l, void *data) { ClientWin *cw = (ClientWin *)l->data; CARD32 desktop = (*(CARD32*)data), w_desktop = wm_get_window_desktop(cw->mainwin->dpy, cw->client.window); #ifdef XINERAMA if(cw->mainwin->xin_active && ! INTERSECTS(cw->client.x, cw->client.y, cw->client.width, cw->client.height, cw->mainwin->xin_active->x_org, cw->mainwin->xin_active->y_org, cw->mainwin->xin_active->width, cw->mainwin->xin_active->height)) return 0; #endif return (w_desktop == (CARD32)-1 || desktop == w_desktop) && wm_validate_window(cw->mainwin->dpy, cw->client.window); }
int clientwin_validate_func(dlist *l, void *data) { ClientWin *cw = l->data; MainWin *mw = cw->mainwin; CARD32 desktop = (*(CARD32*)data), w_desktop = wm_get_window_desktop(mw->ps, cw->wid_client); #ifdef CFG_XINERAMA if(mw->xin_active && ! INTERSECTS(cw->src.x, cw->src.y, cw->src.width, cw->src.height, mw->xin_active->x_org, mw->xin_active->y_org, mw->xin_active->width, mw->xin_active->height)) return 0; #endif return (w_desktop == (CARD32)-1 || desktop == w_desktop) && wm_validate_window(mw->ps, cw->wid_client); }
/** * This method checks to see if the given LCD glyph bounds fall within the * cached destination texture bounds. If so, this method can return * immediately. If not, this method will copy a chunk of framebuffer data * into the cached destination texture and then update the current cached * destination bounds before returning. * * The agx1, agx2 are "adjusted" glyph bounds, which are only used when checking * against the previous glyph bounds. */ static HRESULT D3DTR_UpdateCachedDestination(D3DContext *d3dc, D3DSDOps *dstOps, GlyphInfo *ginfo, jint gx1, jint gy1, jint gx2, jint gy2, jint agx1, jint agx2, jint glyphIndex, jint totalGlyphs) { jint dx1, dy1, dx2, dy2; D3DResource *pCachedDestTexRes; IDirect3DSurface9 *pCachedDestSurface, *pDst; HRESULT res; if (isCachedDestValid && INSIDE(gx1, gy1, gx2, gy2, cachedDestBounds)) { // glyph is already within the cached destination bounds; no need // to read back the entire destination region again, but we do // need to see if the current glyph overlaps the previous glyph... // only use the "adjusted" glyph bounds when checking against // previous glyph's bounds gx1 = agx1; gx2 = agx2; if (INTERSECTS(gx1, gy1, gx2, gy2, previousGlyphBounds)) { // the current glyph overlaps the destination region touched // by the previous glyph, so now we need to read back the part // of the destination corresponding to the previous glyph dx1 = previousGlyphBounds.x1; dy1 = previousGlyphBounds.y1; dx2 = previousGlyphBounds.x2; dy2 = previousGlyphBounds.y2; // REMIND: make sure we flush any pending primitives that are // dependent on the current contents of the cached dest d3dc->FlushVertexQueue(); RETURN_STATUS_IF_NULL(dstOps->pResource, E_FAIL); RETURN_STATUS_IF_NULL(pDst = dstOps->pResource->GetSurface(), E_FAIL); res = d3dc->GetResourceManager()-> GetCachedDestTexture(dstOps->pResource->GetDesc()->Format, &pCachedDestTexRes); RETURN_STATUS_IF_FAILED(res); pCachedDestSurface = pCachedDestTexRes->GetSurface(); // now dxy12 represent the "desired" destination bounds, but the // StretchRect() call may fail if these fall outside the actual // surface bounds; therefore, we use cxy12 to represent the // clamped bounds, and dxy12 are saved for later jint cx1 = (dx1 < 0) ? 0 : dx1; jint cy1 = (dy1 < 0) ? 0 : dy1; jint cx2 = (dx2 > dstOps->width) ? dstOps->width : dx2; jint cy2 = (dy2 > dstOps->height) ? dstOps->height : dy2; if (cx2 > cx1 && cy2 > cy1) { // copy destination into subregion of cached texture tile // cx1-cachedDestBounds.x1 == +xoffset from left of texture // cy1-cachedDestBounds.y1 == +yoffset from top of texture // cx2-cachedDestBounds.x1 == +xoffset from left of texture // cy2-cachedDestBounds.y1 == +yoffset from top of texture jint cdx1 = cx1-cachedDestBounds.x1; jint cdy1 = cy1-cachedDestBounds.y1; jint cdx2 = cx2-cachedDestBounds.x1; jint cdy2 = cy2-cachedDestBounds.y1; RECT srcRect = { cx1, cy1, cx2, cy2 }; RECT dstRect = { cdx1, cdy1, cdx2, cdy2 }; IDirect3DDevice9 *pd3dDevice = d3dc->Get3DDevice(); res = pd3dDevice->StretchRect(pDst, &srcRect, pCachedDestSurface, &dstRect, D3DTEXF_NONE); } } } else { // destination region is not valid, so we need to read back a // chunk of the destination into our cached texture // position the upper-left corner of the destination region on the // "top" line of glyph list // REMIND: this isn't ideal; it would be better if we had some idea // of the bounding box of the whole glyph list (this is // do-able, but would require iterating through the whole // list up front, which may present its own problems) dx1 = gx1; dy1 = gy1; jint remainingWidth; if (ginfo->advanceX > 0) { // estimate the width based on our current position in the glyph // list and using the x advance of the current glyph (this is just // a quick and dirty heuristic; if this is a "thin" glyph image, // then we're likely to underestimate, and if it's "thick" then we // may end up reading back more than we need to) remainingWidth = (jint)(ginfo->advanceX * (totalGlyphs - glyphIndex)); if (remainingWidth > D3DTR_CACHED_DEST_WIDTH) { remainingWidth = D3DTR_CACHED_DEST_WIDTH; } else if (remainingWidth < ginfo->width) { // in some cases, the x-advance may be slightly smaller // than the actual width of the glyph; if so, adjust our // estimate so that we can accomodate the entire glyph remainingWidth = ginfo->width; } } else { // a negative advance is possible when rendering rotated text, // in which case it is difficult to estimate an appropriate // region for readback, so we will pick a region that // encompasses just the current glyph remainingWidth = ginfo->width; } dx2 = dx1 + remainingWidth; // estimate the height (this is another sloppy heuristic; we'll // make the cached destination region tall enough to encompass most // glyphs that are small enough to fit in the glyph cache, and then // we add a little something extra to account for descenders dy2 = dy1 + D3DTR_CACHE_CELL_HEIGHT + 2; // REMIND: make sure we flush any pending primitives that are // dependent on the current contents of the cached dest d3dc->FlushVertexQueue(); RETURN_STATUS_IF_NULL(dstOps->pResource, E_FAIL); RETURN_STATUS_IF_NULL(pDst = dstOps->pResource->GetSurface(), E_FAIL); res = d3dc->GetResourceManager()-> GetCachedDestTexture(dstOps->pResource->GetDesc()->Format, &pCachedDestTexRes); RETURN_STATUS_IF_FAILED(res); pCachedDestSurface = pCachedDestTexRes->GetSurface(); // now dxy12 represent the "desired" destination bounds, but the // StretchRect() call may fail if these fall outside the actual // surface bounds; therefore, we use cxy12 to represent the // clamped bounds, and dxy12 are saved for later jint cx1 = (dx1 < 0) ? 0 : dx1; jint cy1 = (dy1 < 0) ? 0 : dy1; jint cx2 = (dx2 > dstOps->width) ? dstOps->width : dx2; jint cy2 = (dy2 > dstOps->height) ? dstOps->height : dy2; if (cx2 > cx1 && cy2 > cy1) { // copy destination into cached texture tile (the upper-left // corner of the destination region will be positioned at the // upper-left corner (0,0) of the texture) RECT srcRect = { cx1, cy1, cx2, cy2 }; RECT dstRect = { cx1-dx1, cy1-dy1, cx2-dx1, cy2-dy1 }; IDirect3DDevice9 *pd3dDevice = d3dc->Get3DDevice(); res = pd3dDevice->StretchRect(pDst, &srcRect, pCachedDestSurface, &dstRect, D3DTEXF_NONE); } // update the cached bounds and mark it valid cachedDestBounds.x1 = dx1; cachedDestBounds.y1 = dy1; cachedDestBounds.x2 = dx2; cachedDestBounds.y2 = dy2; isCachedDestValid = JNI_TRUE; } // always update the previous glyph bounds previousGlyphBounds.x1 = gx1; previousGlyphBounds.y1 = gy1; previousGlyphBounds.x2 = gx2; previousGlyphBounds.y2 = gy2; return res; }
/** * This method checks to see if the given LCD glyph bounds fall within the * cached destination texture bounds. If so, this method can return * immediately. If not, this method will copy a chunk of framebuffer data * into the cached destination texture and then update the current cached * destination bounds before returning. */ static void OGLTR_UpdateCachedDestination(OGLSDOps *dstOps, GlyphInfo *ginfo, jint gx1, jint gy1, jint gx2, jint gy2, jint glyphIndex, jint totalGlyphs) { jint dx1, dy1, dx2, dy2; jint dx1adj, dy1adj; if (isCachedDestValid && INSIDE(gx1, gy1, gx2, gy2, cachedDestBounds)) { // glyph is already within the cached destination bounds; no need // to read back the entire destination region again, but we do // need to see if the current glyph overlaps the previous glyph... if (INTERSECTS(gx1, gy1, gx2, gy2, previousGlyphBounds)) { // the current glyph overlaps the destination region touched // by the previous glyph, so now we need to read back the part // of the destination corresponding to the previous glyph dx1 = previousGlyphBounds.x1; dy1 = previousGlyphBounds.y1; dx2 = previousGlyphBounds.x2; dy2 = previousGlyphBounds.y2; // this accounts for lower-left origin of the destination region dx1adj = dstOps->xOffset + dx1; dy1adj = dstOps->yOffset + dstOps->height - dy2; // copy destination into subregion of cached texture tile: // dx1-cachedDestBounds.x1 == +xoffset from left side of texture // cachedDestBounds.y2-dy2 == +yoffset from bottom of texture j2d_glActiveTextureARB(GL_TEXTURE1_ARB); j2d_glCopyTexSubImage2D(GL_TEXTURE_2D, 0, dx1 - cachedDestBounds.x1, cachedDestBounds.y2 - dy2, dx1adj, dy1adj, dx2-dx1, dy2-dy1); } } else { jint remainingWidth; // destination region is not valid, so we need to read back a // chunk of the destination into our cached texture // position the upper-left corner of the destination region on the // "top" line of glyph list // REMIND: this isn't ideal; it would be better if we had some idea // of the bounding box of the whole glyph list (this is // do-able, but would require iterating through the whole // list up front, which may present its own problems) dx1 = gx1; dy1 = gy1; if (ginfo->advanceX > 0) { // estimate the width based on our current position in the glyph // list and using the x advance of the current glyph (this is just // a quick and dirty heuristic; if this is a "thin" glyph image, // then we're likely to underestimate, and if it's "thick" then we // may end up reading back more than we need to) remainingWidth = (jint)(ginfo->advanceX * (totalGlyphs - glyphIndex)); if (remainingWidth > OGLTR_CACHED_DEST_WIDTH) { remainingWidth = OGLTR_CACHED_DEST_WIDTH; } else if (remainingWidth < ginfo->width) { // in some cases, the x-advance may be slightly smaller // than the actual width of the glyph; if so, adjust our // estimate so that we can accomodate the entire glyph remainingWidth = ginfo->width; } } else { // a negative advance is possible when rendering rotated text, // in which case it is difficult to estimate an appropriate // region for readback, so we will pick a region that // encompasses just the current glyph remainingWidth = ginfo->width; } dx2 = dx1 + remainingWidth; // estimate the height (this is another sloppy heuristic; we'll // make the cached destination region tall enough to encompass most // glyphs that are small enough to fit in the glyph cache, and then // we add a little something extra to account for descenders dy2 = dy1 + OGLTR_CACHE_CELL_HEIGHT + 2; // this accounts for lower-left origin of the destination region dx1adj = dstOps->xOffset + dx1; dy1adj = dstOps->yOffset + dstOps->height - dy2; // copy destination into cached texture tile (the lower-left corner // of the destination region will be positioned at the lower-left // corner (0,0) of the texture) j2d_glActiveTextureARB(GL_TEXTURE1_ARB); j2d_glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, dx1adj, dy1adj, dx2-dx1, dy2-dy1); // update the cached bounds and mark it valid cachedDestBounds.x1 = dx1; cachedDestBounds.y1 = dy1; cachedDestBounds.x2 = dx2; cachedDestBounds.y2 = dy2; isCachedDestValid = JNI_TRUE; } // always update the previous glyph bounds previousGlyphBounds.x1 = gx1; previousGlyphBounds.y1 = gy1; previousGlyphBounds.x2 = gx2; previousGlyphBounds.y2 = gy2; }