Software Rendering Doesn 39;t Support Hardware Bitmaps

0 views
Skip to first unread message

Tinisha

unread,
Aug 3, 2024, 4:06:57 PM8/3/24
to rrasarlarbu

This page provides guidance on how to handle some common use cases with Coil. You might have to modify this code to fit your exact requirements, but it should hopefully give you a push in the right direction!

Using a previous request's MemoryCache.Key as a placeholder for a subsequent request can be useful if the two images are the same, though loaded at different sizes. For instance, if the first request loads the image at 100x100 and the second request loads the image at 500x500, we can use the first image as a synchronous placeholder for the second request.

Previous versions of Coil would attempt to set up this effect automatically. This required executing parts of the image pipeline synchronously on the main thread and it was ultimately removed in version 0.12.0.

Shared element transitions are incompatible with hardware bitmaps. You should set allowHardware(false) to disable hardware bitmaps for both the ImageView you are animating from and the view you are animating to. If you don't, the transition will throw an java.lang.IllegalArgumentException: Software rendering doesn't support hardware bitmaps exception.

Use the MemoryCache.Key of the start image as the placeholderMemoryCacheKey for the end image. This ensures that the start image is used as the placeholder for the end image, which results in a smooth transition with no white flashes if the image is in the memory cache.

Both AsyncImage and AsyncImagePainter have placeholder/error/fallback arguments that accept Painters. Painters are less flexible than using composables, but are faster as Coil doesn't need to use subcomposition. That said, it may be necessary to inset, stretch, tint, or transform your painter to get the desired UI. To accomplish this, copy this Gist into your project and wrap the painter like so:

If you use Hardware bitmap, or your image library use hardware bitmap by default (example: coil), the default snapshot method does not support it. To overcome the issue, you can enable the Static snapshot method which supports Hardware bitmaps.

It seems that draw contexts bridged through iterateRegion in Win32Frame::paint() always have hardware rendering enabled implicitly which seems to have something to do with the switch to direct composition. In other words, in its current form VSTGUI does not support bitmaps with sizes >= 16384 pixels on windows regardless of the setting applied through Win32Factory::useD2DHardwareRenderer ()

Hi,
in the meantime I think the solution is to add the possibility to add multiple bitmaps to the CAnimKnob class, to make this cross-platform aware. One bitmap contains as much frames as possible. So if you have a frame that is 170 x 170 pixels and you want to create a CAnimKnob with 100 frames, you must split the frames in 2 bitmaps. The first one holds 96 frames and the second one the remaining 4 frames. This has the benefit that the current optimal way to load bitmaps is not changed and no extra runtime cost is added to the opening of the editor. The small disadvantage is that this must be known to the developer and that the developer has to prepare this.
What do you think?

My idea was to extend CAnimKnob, CMovieBitmap etc. in a way that it allows for using CMultiBitmapContainer instead of a CBitmap as a background, so only projects in which the graphics size exceeds the size limitations need to be adapted, e.g. like this:

I think that there must be some way for Direct2D or Direct3D to load uncompressed image data. So one possible solution could be to uncompress the bitmap to disk once and then upload the part of the image needed to the GPU from storage.

The way to make it fast is to render the individual glyphs and store
them. Then draw text by blitting the individual glyphs to the screen. If
you are using OpenGL, then store them a textures and then texture map
them into place. You either render each glyph as its own surface, or you
can render the entire font into a surface and blit the appropriate parts
of you font surface.

Now I need to render text in SDL, not using OpenGL. But some time ago I
was writting application in SDL and OpenGL (using SDL_TTF, too). I
quickly realised that I will need to render each glyph separatly. So I
wrote class TFont, which loads and initializes font, creates textures,
OpenGL lists and so on. This class provides methods for render text and
metrics. Code was testing on same machines - and:

Now I need to render text in SDL, not using OpenGL. But some time
ago I was writting application in SDL and OpenGL (using SDL_TTF,
too). I quickly realised that I will need to render each glyph
separatly. So I wrote class TFont, which loads and initializes font,
creates textures, OpenGL lists and so on. This class provides
methods for render text and metrics. Code was testing on same
machines - and:

In my opinion, instead of converting TTF fonts to bitmaps in run-time you
should do so before to avoid extra dependecy, make the engine simpler and use
of less cpu and memory.
Making a program to convert TTF to a bitmap is very simple, as well as making
it accept arguments and add graphical effects.

should do so before to avoid extra dependecy, make the engine simpler and
use
of less cpu and memory.
Making a program to convert TTF to a bitmap is very simple, as well as
making
it accept arguments and add graphical effects.

Yeah, you are using a hardware buffer. Writing to a hardware buffer in
software is very slow. This is especially true when you are doing alpha
blending or any other operation that requires you to read from the
hardware buffer.

Also, does you hardware actually support a 16 bit video format? Did you
check to see that you are getting 16 bit format? And, are your images in
the same 16 bit format as your screen. If not, then SDL may be
converting your images on the fly and that will slow you way down.

What I suggested was to convert the TTF files into a bitmap format files and
then use the latter in your game. As you do, you have to convert the
vectorial fonts into raster bitmaps at run-time (yes, initializalition
happens during run-time).
It would avoid making your code more complex, the extra dependencies, the
need for more processor (and yes, I understood it is only once per run), and
possible differences on the TTF renderer.

In my opinion, instead of converting TTF fonts to bitmaps in run-time
you should do so before to avoid extra dependecy, make the engine
simpler and use of less cpu and memory. Making a program to convert
TTF to a bitmap is very simple, as well as making it accept arguments
and add graphical effects.

I ended up storing a copy of the text in memory, and blit to the the
main display only when that part of the screen needs to be redrawn.
Much more friendly for the CPU at the cost of a little memory.

In my opinion, instead of converting TTF fonts to bitmaps in
run-time you should do so before to avoid extra dependecy, make
the engine simpler and use of less cpu and memory. Making a
program to convert TTF to a bitmap is very simple, as well as
making it accept arguments and add graphical effects.

Although Direct2D is hardware accelerated and is meant for high performance, you must use the features correctly to maximize throughput. The techniques we show here are derived from studying common scenarios and might not apply to all app scenarios. Therefore, careful understanding of app behavior and performance goals can help achieve the results that you want.

In Direct2D, resources can be created both in software and hardware. Resource creation and deletion on hardware are expensive operations because they require lots of overhead for communicating with the video card. Let's see how Direct2D renders content to a target.

In Direct2D, all the rendering commands are enclosed between a call to BeginDraw and a call to EndDraw. These calls are made to a render target. You must call the BeginDraw method before you call rendering operations . After you call BeginDraw , a context typically builds up a batch of rendering commands, but delays processing of these commands until one of these statements is true:

As already mentioned, resource creation and deletion is expensive on hardware. So reuse resources when possible. Take the example of bitmap creation in game development. Usually, bitmaps that make up a scene in a game are all created at the same time with all the different variations that are required for later frame-to-frame rendering. At the time of actual scene rendering and re-rendering, these bitmaps are reused instead of re-created.

c80f0f1006
Reply all
Reply to author
Forward
0 new messages