Implement [QNSView isOpaque]

Re-use the QCocoaWindow implementation.

This gives a small performance boost since NSWindow
can skip drawing the background if it knows that the
content view will fill with opaque pixels.

Change-Id: I4a9a14135d890e9132dd1cb0af5a1c1a769d7e2f
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
bb10
Morten Johan Sørvig 2013-03-21 13:42:05 +01:00 committed by The Qt Project
parent a87e8f7a10
commit a8283fe4d9
4 changed files with 17 additions and 13 deletions

View File

@ -109,6 +109,7 @@ public:
void raise();
void lower();
bool isExposed() const;
bool isOpaque() const;
void propagateSizeHints();
void setOpacity(qreal level);
void setMask(const QRegion &region);
@ -161,8 +162,6 @@ protected:
QCocoaWindow *parentCocoaWindow() const;
void syncWindowState(Qt::WindowState newState);
void updateOpaque();
// private:
public: // for QNSView
friend class QCocoaBackingStore;

View File

@ -505,6 +505,14 @@ bool QCocoaWindow::isExposed() const
return m_isExposed;
}
bool QCocoaWindow::isOpaque() const
{
bool translucent = (window()->format().alphaBufferSize() > 0
|| window()->opacity() < 1
|| (m_contentView && [m_contentView hasMask]));
return !translucent;
}
void QCocoaWindow::propagateSizeHints()
{
QCocoaAutoReleasePool pool;
@ -543,20 +551,11 @@ void QCocoaWindow::propagateSizeHints()
}
}
void QCocoaWindow::updateOpaque()
{
bool translucent = window()->format().alphaBufferSize() > 0
|| window()->opacity() < 1
|| (m_contentView && [m_contentView hasMask]);
[m_nsWindow setOpaque:!translucent];
}
void QCocoaWindow::setOpacity(qreal level)
{
if (m_nsWindow) {
[m_nsWindow setAlphaValue:level];
updateOpaque();
[m_nsWindow setOpaque: isOpaque()];
}
}
@ -566,7 +565,7 @@ void QCocoaWindow::setMask(const QRegion &region)
[m_nsWindow setBackgroundColor:[NSColor clearColor]];
[m_qtView setMaskRegion:&region];
updateOpaque();
[m_nsWindow setOpaque: isOpaque()];
}
bool QCocoaWindow::setKeyboardGrabEnabled(bool grab)

View File

@ -88,6 +88,7 @@ QT_END_NAMESPACE
- (BOOL)acceptsFirstResponder;
- (BOOL)becomeFirstResponder;
- (BOOL)hasMask;
- (BOOL)isOpaque;
- (void)resetMouseButtons;

View File

@ -310,6 +310,11 @@ static QTouchDevice *touchDevice = 0;
return m_maskData != 0;
}
- (BOOL) isOpaque
{
return m_platformWindow->isOpaque();
}
- (void) setMaskRegion:(const QRegion *)region
{
m_shouldInvalidateWindowShadow = true;