Skip to content

CachedImageAtSize never hits at device zoom != 100 (points compared against pixels) #3511

Description

@vogella

CachedImageAtSize.refresh converts the requested draw size to pixels:

int scaledWidth = DPIUtil.pointToPixel(destWidth, DPIUtil.getDeviceZoom());

and hands it to isReusable, which compares it against the cached image's width.
That field is in points: loadImageAtSize builds the cached image with
new Image(device, imageData, getDeviceZoom()), and Image.init(ImageData, zoom)
sets this.width = round(imageDataWidth / scaleFactor).

At zoom 200 the comparison is scaledWidth/2 == scaledWidth, never true. The
single-entry size cache therefore never hits at any zoom other than 100, so every
scaled GC.drawImage misses and reloads the image.

Measured with strace -f -e trace=openat, 100 draws of one Image at a stable draw
size through the 5-arg overload, SVG:

Device zoom Opens per draw Total over 100 draws
100 0.02 2 (one miss, then hits)
200 2.00 200 (a miss every draw)

#3506 makes each miss cheaper but not rarer, and #3510 removes a different zoom-200
open; neither corrects the units.

Cocoa and win32 are unaffected: cocoa's cached image keeps pixels (init gets zoom
100), and win32's HandleAtSize compares the requested size against the requested size.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions