/** * Expands a given rectangle to the next tile boundary. Note, this will * expand the rectangle if it is already on tile boundaries. */ static CSSRect ExpandDisplayPortToTileBoundaries( const CSSRect& aDisplayPort, const CSSToLayerScale& aLayerPixelsPerCSSPixel) { // Convert the given rect to layer coordinates so we can inflate to tile // boundaries (layer space corresponds to texture pixel space here). LayerRect displayPortInLayerSpace = aDisplayPort * aLayerPixelsPerCSSPixel; // Inflate the rectangle by 1 so that we always push to the next tile // boundary. This is desirable to stop from having a rectangle with a // moving origin occasionally being smaller when it coincidentally lines // up to tile boundaries. displayPortInLayerSpace.Inflate(1); // Now nudge the rectangle to the nearest equal or larger tile boundary. gfxFloat left = TILEDLAYERBUFFER_TILE_SIZE * floor(displayPortInLayerSpace.x / TILEDLAYERBUFFER_TILE_SIZE); gfxFloat top = TILEDLAYERBUFFER_TILE_SIZE * floor(displayPortInLayerSpace.y / TILEDLAYERBUFFER_TILE_SIZE); gfxFloat right = TILEDLAYERBUFFER_TILE_SIZE * ceil(displayPortInLayerSpace.XMost() / TILEDLAYERBUFFER_TILE_SIZE); gfxFloat bottom = TILEDLAYERBUFFER_TILE_SIZE * ceil(displayPortInLayerSpace.YMost() / TILEDLAYERBUFFER_TILE_SIZE); displayPortInLayerSpace = LayerRect(left, top, right - left, bottom - top); CSSRect displayPort = displayPortInLayerSpace / aLayerPixelsPerCSSPixel; return displayPort; }
LayerRect Intersection(const LayerRect &rect1, const LayerRect &rect2) { LayerRect res; if (!IsValid(rect1) || !IsValid(rect2)) { return LayerRect(); } res.left = MAX(rect1.left, rect2.left); res.top = MAX(rect1.top, rect2.top); res.right = MIN(rect1.right, rect2.right); res.bottom = MIN(rect1.bottom, rect2.bottom); if (!IsValid(res)) { return LayerRect(); } return res; }
LayerRect Reposition(const LayerRect &rect, const int &x_offset, const int &y_offset) { LayerRect res; if (!IsValid(rect)) { return LayerRect(); } res.left = rect.left + FLOAT(x_offset); res.top = rect.top + FLOAT(y_offset); res.right = rect.right + FLOAT(x_offset); res.bottom = rect.bottom + FLOAT(y_offset); return res; }