VectorResourceDecoder
class VectorResourceDecoder
Implements: IResourceDecoder
Package: dev.joid.lib.resource.decoder.impl · Module: core · Source: VectorResourceDecoder.java
Decodes an SVG document and renders it again at the size it is drawn at, so that it stays sharp.
Description
Section titled “Description”SvgResourceFormat picks it.
The first render has the size of the document; each draw then asks for its size in screen pixels, at most 4096 on the longer side, rendered on a background thread and kept with the last 8 sizes.
While the size keeps changing, the closest texture already rendered is drawn, so an animated size does not render on every frame.
Every render gives the same pixels on every JDK, from Java 8 to the latest: the shapes are filled without antialiasing at 8 samples per pixel on each axis, fewer above 512 pixels but at least 2, then averaged, and JOID outlines the strokes itself instead of the JDK.
Learn more
Section titled “Learn more”Creation
Section titled “Creation”| Returns | Signature | Summary |
|---|---|---|
VectorResourceDecoder | create(Asset asset) factory | Creates a decoder of the SVG asset. |
| VectorResourceDecoder(Asset asset) protected | Creates the decoder, for a subclass. |
Methods
Section titled “Methods”| Returns | Signature | Summary |
|---|---|---|
void | prepare(ResourceData resource) | Gives the data a transparent placeholder texture until the document is rendered. |
void | decode(ResourceData resource) | Parses the document and renders it at its own size. |
void | upload(ResourceData resource) | Uploads the first render. |
void | clear(ResourceData resource) | Frees every rendered texture and the parsed document. |
boolean | isSettled() | If true, no render is in progress or waiting for its upload. |
boolean | isMipmappable() | Always false: a vector image renders at the size it is drawn at instead. |
Asset | getAsset() | Returns the SVG file. |
For subclasses
Section titled “For subclasses”| Returns | Signature | Summary |
|---|---|---|
void | update(ResourceData resource) hook | Uploads a render finished in the background, unless the document was replaced since. |
void | request(ResourceData resource, int width, int height, boolean async, boolean resizing) hook | Shows the texture of that size when it is already rendered, otherwise renders it: on the background thread when async is true, at once otherwise. |
Inherited from IResourceDecoder (1)
Creation details
Section titled “Creation details”create
Section titled “create”VectorResourceDecoder create(Asset asset) factory
Creates a decoder of the SVG asset.
VectorResourceDecoder
Section titled “VectorResourceDecoder”VectorResourceDecoder(Asset asset) protected
Creates the decoder, for a subclass.
Method details
Section titled “Method details”prepare
Section titled “prepare”void prepare(ResourceData resource)
Gives the data a transparent placeholder texture until the document is rendered.
decode
Section titled “decode”void decode(ResourceData resource)
Throws:
UncheckedIOException: The SVG … cannot be readIllegalArgumentException: … is not an SVG document that can be parsed
Parses the document and renders it at its own size.
Throws UncheckedIOException when the asset cannot be read, and IllegalArgumentException when it is not an SVG document.
upload
Section titled “upload”void upload(ResourceData resource)
Uploads the first render.
void clear(ResourceData resource)
Frees every rendered texture and the parsed document.
isSettled
Section titled “isSettled”boolean isSettled()
If true, no render is in progress or waiting for its upload.
isMipmappable
Section titled “isMipmappable”boolean isMipmappable()
Always false: a vector image renders at the size it is drawn at instead.
getAsset
Section titled “getAsset”Asset getAsset()
Returns the SVG file.
update
Section titled “update”void update(ResourceData resource) hook
Uploads a render finished in the background, unless the document was replaced since.
request
Section titled “request”void request(ResourceData resource, int width, int height, boolean async, boolean resizing) hook
Shows the texture of that size when it is already rendered, otherwise renders it: on the background thread when async is true, at once otherwise.
While resizing, it shows the closest larger texture or renders 25 % larger, so that a growing size does not render on every frame.
fluent returns the instance, typed for chaining · factory creates an instance · signal also accepts a value that follows signals, as a signal, an expression or a lambda (When does JOID compute this value again?) · hook called by JOID, override it · abstract you implement it · default interface method with a body · static called on the class · protected visible to subclasses
