Skip to content

Commit d6b8e99

Browse files
PatriceJiangminggo
authored andcommitted
fix mac retina support (#19672)
1 parent 62dc64a commit d6b8e99

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

cocos/platform/mac/CCGLViewImpl-mac.mm

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -319,12 +319,18 @@ of this software and associated documentation files (the "Software"), to deal
319319
return false;
320320
}
321321

322+
323+
int fbWidth, fbHeight;
324+
glfwGetFramebufferSize(_mainWindow, &fbWidth, &fbHeight);
325+
326+
327+
CGSize size;
328+
size.width = static_cast<CGFloat>(fbWidth);
329+
size.height = static_cast<CGFloat>(fbHeight);
330+
322331
// Initialize device.
323332
NSView* contentView = [getCocoaWindow() contentView];
324333
[contentView setWantsLayer: YES];
325-
CGSize size;
326-
size.width = rect.size.width;
327-
size.height = rect.size.height;
328334
CAMetalLayer* layer = [CAMetalLayer layer];
329335
[layer setDevice:MTLCreateSystemDefaultDevice()];
330336
[layer setPixelFormat:MTLPixelFormatBGRA8Unorm];
@@ -614,21 +620,20 @@ of this software and associated documentation files (the "Software"), to deal
614620
int frameBufferW = 0, frameBufferH = 0;
615621
glfwGetFramebufferSize(_mainWindow, &frameBufferW, &frameBufferH);
616622

617-
//TODO coulsonwang
618-
// if (frameBufferW == 2 * w && frameBufferH == 2 * h)
619-
// {
620-
// if (_isRetinaEnabled)
621-
// {
622-
// _retinaFactor = 1;
623-
// }
624-
// else
625-
// {
626-
// _retinaFactor = 2;
627-
// }
628-
// glfwSetWindowSize(_mainWindow, _screenSize.width/2 * _retinaFactor * _frameZoomFactor, _screenSize.height/2 * _retinaFactor * _frameZoomFactor);
629-
// _isInRetinaMonitor = true;
630-
// }
631-
// else
623+
if (frameBufferW == 2 * w && frameBufferH == 2 * h)
624+
{
625+
if (_isRetinaEnabled)
626+
{
627+
_retinaFactor = 1;
628+
}
629+
else
630+
{
631+
_retinaFactor = 2;
632+
}
633+
glfwSetWindowSize(_mainWindow, _screenSize.width/2 * _retinaFactor * _frameZoomFactor, _screenSize.height/2 * _retinaFactor * _frameZoomFactor);
634+
_isInRetinaMonitor = true;
635+
}
636+
else
632637
{
633638
if (_isInRetinaMonitor)
634639
{
@@ -650,10 +655,10 @@ of this software and associated documentation files (the "Software"), to deal
650655
void GLViewImpl::setViewPortInPoints(float x , float y , float w , float h)
651656
{
652657
Viewport vp;
653-
vp.x = x * _scaleX * _frameZoomFactor + _viewPortRect.origin.x * _frameZoomFactor;
654-
vp.y = y * _scaleY * _frameZoomFactor + _viewPortRect.origin.y * _frameZoomFactor;
655-
vp.w = w * _scaleX * _frameZoomFactor;
656-
vp.h = h * _scaleY * _frameZoomFactor;
658+
vp.x = x * _scaleX * _retinaFactor * _frameZoomFactor + _viewPortRect.origin.x * _retinaFactor *_frameZoomFactor;
659+
vp.y = y * _scaleY * _retinaFactor *_frameZoomFactor + _viewPortRect.origin.y * _retinaFactor *_frameZoomFactor;
660+
vp.w = w * _scaleX *_retinaFactor * _frameZoomFactor;
661+
vp.h = h * _scaleY * _retinaFactor * _frameZoomFactor;
657662
Camera::setDefaultViewport(vp);
658663
}
659664

0 commit comments

Comments
 (0)