/// <summary> /// Load a tile from the store, and add it to the display container and dictionary /// If no tile is available in the store at this position, we put an empty proxy in place. /// </summary> private void AddToCache(PositionKey key) { if (key == null) { return; } var pos = VisualRectangleNative(key); var tile = new CachedTile(_displayContainer, key, pos.X, pos.Y); // calls down to "Win2dCanvasManager.Employ" tile.SetState(TileState.Locked); lock (_reflowLock) { _tileCache.Add(key, tile); _loadQueue.Enqueue(tile); } }
private void WriteTileToBackingStoreSync(PositionKey key, CachedTile tile) { if (key == null) { return; } if (tile == null) { return; } if (tile.State == TileState.Locked) { return; } var red = RawDataPool.Capture(); var green = RawDataPool.Capture(); var blue = RawDataPool.Capture(); try { var name = key.ToString(); if (tile.ImageIsBlank()) { _tileStore.Delete(name, "img"); tile.SetState(TileState.Empty); } else { var packed = tile.GetTileData(); if (packed == null) { return; } var end = TileImageSize * TileImageSize; for (int i = 0; i < end; i++) { blue[i] = packed[4 * i + 0]; green[i] = packed[4 * i + 1]; red[i] = packed[4 * i + 2]; } using (var ms = new MemoryStream()) { WaveletCompress.Compress(red, green, blue, tile.Width, tile.Height).WriteToStream(ms); ms.Seek(0, SeekOrigin.Begin); var ok = _tileStore.Store(name, "img", ms); if (ok.IsFailure) { throw new Exception("Storage error: DB might be corrupt.", ok.FailureCause); } } } } finally { RawDataPool.Release(red); RawDataPool.Release(green); RawDataPool.Release(blue); } }