static void paintRepaintRectOverlay(CGContextRef context, WKImageRef image, WKArrayRef repaintRects) { WKSize imageSize = WKImageGetSize(image); CGContextSaveGState(context); // Using a transparency layer is easier than futzing with clipping. CGContextBeginTransparencyLayer(context, 0); // Flip the context. CGContextScaleCTM(context, 1, -1); CGContextTranslateCTM(context, 0, -imageSize.height); CGContextSetRGBFillColor(context, 0, 0, 0, static_cast<CGFloat>(0.66)); CGContextFillRect(context, CGRectMake(0, 0, imageSize.width, imageSize.height)); // Clear the repaint rects. size_t count = WKArrayGetSize(repaintRects); for (size_t i = 0; i < count; ++i) { WKRect rect = WKRectGetValue(static_cast<WKRectRef>(WKArrayGetItemAtIndex(repaintRects, i))); CGRect cgRect = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height); CGContextClearRect(context, cgRect); } CGContextEndTransparencyLayer(context); CGContextRestoreGState(context); }
void GraphicsContext::beginTransparencyLayer(float opacity) { if (paintingDisabled()) return; CGContextRef context = platformContext(); CGContextSaveGState(context); CGContextSetAlpha(context, opacity); CGContextBeginTransparencyLayer(context, 0); m_data->beginTransparencyLayer(); }
void GraphicsContext::beginTransparencyLayer(float opacity) { if (paintingDisabled()) return; CGContextRef context = platformContext(); CGContextSaveGState(context); CGContextSetAlpha(context, opacity); CGContextBeginTransparencyLayer(context, 0); m_data->beginTransparencyLayer(); m_data->m_userToDeviceTransformKnownToBeIdentity = false; }
void UIFrameBufferQuartz2D::paintEvent(QPaintEvent *aEvent) { /* If the machine is NOT in 'running' state, * the link between framebuffer and video memory * is broken, we should go fallback now... */ if (m_fUsesGuestVRAM && !m_pMachineView->uisession()->isRunning() && !m_pMachineView->uisession()->isPaused() && /* Online snapshotting: */ m_pMachineView->uisession()->machineState() != KMachineState_Saving) { /* Simulate fallback through fake resize-event: */ UIResizeEvent event(FramebufferPixelFormat_Opaque, NULL, 0, 0, 640, 480); resizeEvent(&event); } /* For debugging /Developer/Applications/Performance Tools/Quartz * Debug.app is a nice tool to see which parts of the screen are * updated.*/ Assert(m_image); QWidget* viewport = m_pMachineView->viewport(); Assert(VALID_PTR(viewport)); /* Get the dimensions of the viewport */ CGRect viewRect = ::darwinToCGRect(viewport->geometry()); /* Get the context of this window from Qt */ CGContextRef ctx = ::darwinToCGContextRef(viewport); Assert(VALID_PTR(ctx)); /* Flip the context */ CGContextTranslateCTM(ctx, 0, viewRect.size.height); CGContextScaleCTM(ctx, 1.0, -1.0); /* We handle the seamless mode as a special case. */ if (m_pMachineLogic->visualStateType() == UIVisualStateType_Seamless) { /* Clear the background (make the rect fully transparent): */ CGContextClearRect(ctx, viewRect); #ifdef OVERLAY_CLIPRECTS /* Enable overlay above the seamless mask: */ CGContextSetRGBFillColor(ctx, 0.0, 0.0, 5.0, 0.7); CGContextFillRect(ctx, viewRect); #endif /* OVERLAY_CLIPRECTS */ #ifdef COMP_WITH_SHADOW /* Enable shadows: */ CGContextSetShadow(ctx, CGSizeMake (10, -10), 10); CGContextBeginTransparencyLayer(ctx, NULL); #endif /* COMP_WITH_SHADOW */ /* Determine current visible region: */ RegionRects *pRgnRcts = ASMAtomicXchgPtrT(&mRegion, NULL, RegionRects*); if (pRgnRcts) { /* If visible region is determined: */ if (pRgnRcts->used > 0) { /* Add the clipping rects all at once (they are defined in SetVisibleRegion): */ CGContextBeginPath(ctx); CGContextAddRects(ctx, pRgnRcts->rcts, pRgnRcts->used); /* Now convert the path to a clipping path: */ CGContextClip(ctx); } /* Put back the visible region, free if we cannot (2+ SetVisibleRegion calls): */ if ( !ASMAtomicCmpXchgPtr(&mRegion, pRgnRcts, NULL) && !ASMAtomicCmpXchgPtr(&mRegionUnused, pRgnRcts, NULL)) { RTMemFree(pRgnRcts); pRgnRcts = NULL; } } /* If visible region is still determined: */ if (pRgnRcts && pRgnRcts->used > 0) { /* Create a subimage of the current view. * Currently this subimage is the whole screen. */ CGImageRef subImage; if (!m_pMachineView->pauseShot().isNull()) { CGImageRef pauseImg = ::darwinToCGImageRef(&m_pMachineView->pauseShot()); subImage = CGImageCreateWithImageInRect(pauseImg, CGRectMake(m_pMachineView->contentsX(), m_pMachineView->contentsY(), m_pMachineView->visibleWidth(), m_pMachineView->visibleHeight())); CGImageRelease(pauseImg); } else { #ifdef RT_ARCH_AMD64 /* Not sure who to blame, but it seems on 64bit there goes * something terrible wrong (on a second monitor) when directly * using CGImageCreateWithImageInRect without making a copy. We saw * something like this already with the scale mode. */ CGImageRef tmpImage = CGImageCreateWithImageInRect(m_image, CGRectMake(m_pMachineView->contentsX(), m_pMachineView->contentsY(), m_pMachineView->visibleWidth(), m_pMachineView->visibleHeight())); subImage = CGImageCreateCopy(tmpImage); CGImageRelease(tmpImage); #else /* RT_ARCH_AMD64 */ subImage = CGImageCreateWithImageInRect(m_image, CGRectMake(m_pMachineView->contentsX(), m_pMachineView->contentsY(), m_pMachineView->visibleWidth(), m_pMachineView->visibleHeight())); #endif /* !RT_ARCH_AMD64 */ } Assert(VALID_PTR(subImage)); /* In any case clip the drawing to the view window: */ CGContextClipToRect(ctx, viewRect); /* At this point draw the real vm image: */ CGContextDrawImage(ctx, ::darwinFlipCGRect(viewRect, viewRect.size.height), subImage); /* Release the subimage: */ CGImageRelease(subImage); } #ifdef COMP_WITH_SHADOW CGContextEndTransparencyLayer(ctx); #endif /* COMP_WITH_SHADOW */ #ifdef OVERLAY_CLIPRECTS if (pRgnRcts && pRgnRcts->used > 0) { CGContextBeginPath(ctx); CGContextAddRects(ctx, pRgnRcts->rcts, pRgnRcts->used); CGContextSetRGBStrokeColor(ctx, 1.0, 0.0, 0.0, 0.7); CGContextDrawPath(ctx, kCGPathStroke); } CGContextSetRGBStrokeColor(ctx, 0.0, 1.0, 0.0, 0.7); CGContextStrokeRect(ctx, viewRect); #endif /* OVERLAY_CLIPRECTS */ }
void CGContextBeginTransparencyLayer_wrap(CGContextRef c) { CGContextBeginTransparencyLayer(c, NULL); }