Hi,
we’re currently testing our plugins with JUCE 8 and hit a performance issue with DirectX.
Code something like the following:
// Work out the source image bounds
const auto clipBounds = normBoundsToBounds(_currentImageBounds, currentImage.getBounds());
const auto clippedImage = currentImage.getClippedImage(clipBounds);
jassert(clippedImage.isValid());
g.setColour(juce::Colours::white);
g.setOpacity(1.0f);
g.drawImage(clippedImage, bounds, juce::RectanglePlacement::fillDestination);
g.drawImage is now very very slow. So I profiled it and this is the area in JUCE that seems to cause the slowdown which takes the same path on every call to drawImage.
void Direct2DGraphicsContext::drawImage (const Image& image, const AffineTransform& transform)
{
...
// Is this a Direct2D image already with the correct format?
ComSmartPtr<ID2D1Bitmap1> d2d1Bitmap;
Rectangle<int> imageClipArea;
if (auto direct2DPixelData = dynamic_cast<Direct2DPixelData*> (image.getPixelData()))
{
d2d1Bitmap = direct2DPixelData->getAdapterD2D1Bitmap();
imageClipArea = { direct2DPixelData->width, direct2DPixelData->height };
}
if (! d2d1Bitmap || d2d1Bitmap->GetPixelFormat().format != DXGI_FORMAT_B8G8R8A8_UNORM)
{
JUCE_D2DMETRICS_SCOPED_ELAPSED_TIME (Direct2DMetricsHub::getInstance()->imageContextMetrics, createBitmapTime);
d2d1Bitmap = Direct2DBitmap::toBitmap (image, deviceContext, Image::ARGB);
Specifically the call to Direct2DBitmap::toBitmap because d2d1Bitmap is null.
The comment seems to imply that we should have our images in the correct format. Is there something we should do to avoid this happening?
thanks!
