mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
macOS: Use CGContextGetUserSpaceToDeviceSpaceTransform to get backing scale factor of graphics context to avoid unnecessary upscaling on retina displays on macOS 10.14+
This commit is contained in:
parent
b5214a341e
commit
7b17d42039
4 changed files with 8 additions and 10 deletions
|
|
@ -23,7 +23,7 @@ namespace juce
|
|||
class CoreGraphicsContext : public LowLevelGraphicsContext
|
||||
{
|
||||
public:
|
||||
CoreGraphicsContext (CGContextRef context, float flipHeight, float targetScale);
|
||||
CoreGraphicsContext (CGContextRef context, float flipHeight);
|
||||
~CoreGraphicsContext() override;
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -69,7 +69,6 @@ public:
|
|||
private:
|
||||
CGContextRef context;
|
||||
const CGFloat flipHeight;
|
||||
float targetScale;
|
||||
CGColorSpaceRef rgbColourSpace, greyColourSpace;
|
||||
mutable Rectangle<int> lastClipRect;
|
||||
mutable bool lastClipRectIsValid = false;
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ public:
|
|||
{
|
||||
freeCachedImageRef();
|
||||
sendDataChangeMessage();
|
||||
return std::make_unique<CoreGraphicsContext> (context, height, 1.0f);
|
||||
return std::make_unique<CoreGraphicsContext> (context, height);
|
||||
}
|
||||
|
||||
void initialiseBitmapData (Image::BitmapData& bitmap, int x, int y, Image::BitmapData::ReadWriteMode mode) override
|
||||
|
|
@ -187,10 +187,9 @@ ImagePixelData::Ptr NativeImageType::create (Image::PixelFormat format, int widt
|
|||
}
|
||||
|
||||
//==============================================================================
|
||||
CoreGraphicsContext::CoreGraphicsContext (CGContextRef c, float h, float scale)
|
||||
CoreGraphicsContext::CoreGraphicsContext (CGContextRef c, float h)
|
||||
: context (c),
|
||||
flipHeight (h),
|
||||
targetScale (scale),
|
||||
state (new SavedState())
|
||||
{
|
||||
CGContextRetain (context);
|
||||
|
|
@ -238,14 +237,14 @@ void CoreGraphicsContext::addTransform (const AffineTransform& transform)
|
|||
lastClipRectIsValid = false;
|
||||
|
||||
jassert (getPhysicalPixelScaleFactor() > 0.0f);
|
||||
jassert (getPhysicalPixelScaleFactor() > 0.0f);
|
||||
}
|
||||
|
||||
float CoreGraphicsContext::getPhysicalPixelScaleFactor()
|
||||
{
|
||||
auto t = CGContextGetCTM (context);
|
||||
auto t = CGContextGetUserSpaceToDeviceSpaceTransform (context);
|
||||
auto determinant = (t.a * t.d) - (t.c * t.b);
|
||||
|
||||
return targetScale * (float) (juce_hypot (t.a, t.c) + juce_hypot (t.b, t.d)) / 2.0f;
|
||||
return (float) std::sqrt (std::abs (determinant));
|
||||
}
|
||||
|
||||
bool CoreGraphicsContext::clipToRectangle (const Rectangle<int>& r)
|
||||
|
|
|
|||
|
|
@ -1087,7 +1087,7 @@ void UIViewComponentPeer::drawRect (CGRect r)
|
|||
|
||||
// NB the CTM on iOS already includes a factor for the display scale, so
|
||||
// we'll tell the context that the scale is 1.0 to avoid it using it twice
|
||||
CoreGraphicsContext g (cg, getComponent().getHeight(), 1.0f);
|
||||
CoreGraphicsContext g (cg, getComponent().getHeight());
|
||||
|
||||
insideDrawRect = true;
|
||||
handlePaint (g);
|
||||
|
|
|
|||
|
|
@ -873,7 +873,7 @@ public:
|
|||
#if USE_COREGRAPHICS_RENDERING
|
||||
if (usingCoreGraphics)
|
||||
{
|
||||
CoreGraphicsContext context (cg, (float) [view frame].size.height, displayScale);
|
||||
CoreGraphicsContext context (cg, (float) [view frame].size.height);
|
||||
invokePaint (context);
|
||||
}
|
||||
else
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue