VirtualBox

Changeset 31214 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Jul 29, 2010 2:01:00 PM (14 years ago)
Author:
vboxsync
Message:

FE/Qt4-OSX: Quartz2D for scaling mode.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/runtime
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBufferQuartz2D.cpp

    r30111 r31214  
    158158     * Debug.app is a nice tool to see which parts of the screen are
    159159     * updated.*/
    160 
    161160    Assert(m_image);
    162161
     
    167166    /* Get the context of this window from Qt */
    168167    CGContextRef ctx = ::darwinToCGContextRef(viewport);
    169     Assert(VALID_PTR (ctx));
     168    Assert(VALID_PTR(ctx));
    170169
    171170    /* Flip the context */
     
    240239#endif
    241240    }
     241    else if (   m_pMachineLogic->visualStateType() == UIVisualStateType_Scale
     242             && m_scaledSize.isValid())
     243    {
     244        /* Here we paint if we didn't care about any masks */
     245
     246        /* Create a subimage of the current view in the size
     247         * of the bounding box of the current paint event */
     248        QRect qir = aEvent->rect();
     249        CGRect ir = ::darwinToCGRect(qir);
     250        CGRect is = CGRectMake(qir.x() + m_pMachineView->contentsX(), qir.y() + m_pMachineView->contentsY(), qir.width(), qir.height());
     251        ir = ::darwinFlipCGRect(ir, CGRectGetHeight(viewRect));
     252        double iw = 1.0;
     253        double ih = 1.0;
     254        CGImageRef subImage = 0;
     255        if (!m_pMachineView->pauseShot().isNull())
     256        {
     257            /* The pause image is already scaled. Maybe we should change that,
     258             * to have a more uniform behavior and the different
     259             * implementations use there own scaling algorithm. */
     260            CGImageRef pauseImg = ::darwinToCGImageRef(&m_pMachineView->pauseShot());
     261            subImage = CGImageCreateWithImageInRect(pauseImg, is);
     262            CGImageRelease(pauseImg);
     263        }
     264        else
     265        {
     266            /* Scale all values needed for the image drawing. */
     267            iw = (double)CGImageGetWidth(m_image) / m_scaledSize.width();
     268            ih = (double)CGImageGetHeight(m_image) / m_scaledSize.height();
     269            is.origin.x = (double)(is.origin.x * iw);
     270            is.origin.y = (double)(is.origin.y * ih);
     271            is.size.width = (double)(is.size.width * iw);
     272            is.size.height = (double)(is.size.height * ih);
     273            ir.origin.x = (double)(ir.origin.x * iw);
     274            ir.origin.y = (double)(ir.origin.y * ih);
     275            ir.size.width = (double)(ir.size.width * iw);
     276            ir.size.height = (double)(ir.size.height * ih);
     277            subImage = CGImageCreateWithImageInRect(m_image, is);
     278        }
     279        if (subImage)
     280        {
     281            /* For more performance we set a clipping path of the regions given
     282             * by this paint event. */
     283            QVector<QRect> a = aEvent->region().rects();
     284            if (!a.isEmpty())
     285            {
     286                CGContextBeginPath(ctx);
     287                /* Add all region rects to the current context as path components */
     288                for (int i = 0; i < a.size(); ++i)
     289                    CGContextAddRect(ctx, ::darwinFlipCGRect(::darwinToCGRect(a.at(i)), CGRectGetHeight(viewRect)));
     290                /* Now convert the path to a clipping path. */
     291                CGContextClip(ctx);
     292            }
     293
     294            /* In any case clip the drawing to the view window */
     295            CGContextClipToRect(ctx, viewRect);
     296            /* Turn the high interpolation quality on. */
     297            CGContextSetInterpolationQuality(ctx, kCGInterpolationHigh);
     298            CGContextScaleCTM(ctx, 1.0 / iw, 1.0 / ih);
     299            /* Draw the image. */
     300            CGContextDrawImage(ctx, ir, subImage);
     301            CGImageRelease(subImage);
     302        }
     303    }
    242304    else
    243305    {
     
    247309         * of the bounding box of the current paint event */
    248310        QRect ir = aEvent->rect();
    249         QRect is = QRect (ir.x() + m_pMachineView->contentsX(), ir.y() + m_pMachineView->contentsY(), ir.width(), ir.height());
    250         CGImageRef subImage;
     311        QRect is = QRect(ir.x() + m_pMachineView->contentsX(), ir.y() + m_pMachineView->contentsY(), ir.width(), ir.height());
     312        CGImageRef subImage = 0;
    251313        if (!m_pMachineView->pauseShot().isNull())
    252314        {
     
    257319        else
    258320            subImage = CGImageCreateWithImageInRect(m_image, ::darwinToCGRect(is));
    259         Assert(VALID_PTR(subImage));
    260         /* Ok, for more performance we set a clipping path of the
    261          * regions given by this paint event. */
    262         QVector<QRect> a = aEvent->region().rects();
    263         if (!a.isEmpty())
    264         {
    265             CGContextBeginPath (ctx);
    266             /* Add all region rects to the current context as path components */
    267             for (int i = 0; i < a.size(); ++i)
    268                 CGContextAddRect(ctx, ::darwinFlipCGRect(::darwinToCGRect(a[i]), viewRect.size.height));
    269             /* Now convert the path to a clipping path. */
    270             CGContextClip(ctx);
    271         }
    272 
    273         /* In any case clip the drawing to the view window */
    274         CGContextClipToRect(ctx, viewRect);
    275         /* At this point draw the real vm image */
    276         CGContextDrawImage(ctx, ::darwinFlipCGRect(::darwinToCGRect (ir), viewRect.size.height), subImage);
    277 
    278         CGImageRelease(subImage);
     321        if (subImage)
     322        {
     323            /* Ok, for more performance we set a clipping path of the
     324             * regions given by this paint event. */
     325            QVector<QRect> a = aEvent->region().rects();
     326            if (!a.isEmpty())
     327            {
     328                CGContextBeginPath (ctx);
     329                /* Add all region rects to the current context as path components */
     330                for (int i = 0; i < a.size(); ++i)
     331                    CGContextAddRect(ctx, ::darwinFlipCGRect(::darwinToCGRect(a[i]), viewRect.size.height));
     332                /* Now convert the path to a clipping path. */
     333                CGContextClip(ctx);
     334            }
     335
     336            /* In any case clip the drawing to the view window */
     337            CGContextClipToRect(ctx, viewRect);
     338
     339            /* At this point draw the real vm image */
     340            CGContextDrawImage(ctx, ::darwinFlipCGRect(::darwinToCGRect(ir), viewRect.size.height), subImage);
     341            CGImageRelease(subImage);
     342        }
    279343    }
    280344}
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineViewScale.cpp

    r30848 r31214  
    1818 */
    1919
    20 /* Global includes */
    21 #include <QDesktopWidget>
    22 #include <QMainWindow>
    23 #include <QTimer>
    24 
    2520/* Local includes */
    2621#include "VBoxGlobal.h"
     
    3126#include "UIFrameBuffer.h"
    3227#include "UIFrameBufferQImage.h"
     28#ifdef VBOX_GUI_USE_QUARTZ2D
     29# include "UIFrameBufferQuartz2D.h"
     30#endif /* VBOX_GUI_USE_QUARTZ2D */
     31
     32/* Global includes */
     33#include <QDesktopWidget>
     34#include <QMainWindow>
     35#include <QTimer>
    3336
    3437UIMachineViewScale::UIMachineViewScale(  UIMachineWindow *pMachineWindow
     
    198201                                (pPaintEvent->height() + 10 /* 10 pixels right to cover y shift */ + 10 /* 10 pixels right to cover yRatio*10 */) * yRatio);
    199202
     203//            viewport()->repaint((int)(pPaintEvent->x()  /* 10 pixels left to cover xRatio*10 */ * xRatio),
     204//                                (int)(pPaintEvent->y()  /* 10 pixels left to cover yRatio*10 */ * yRatio),
     205//                                (int)(pPaintEvent->width()  /* 10 pixels right to cover x shift */  /* 10 pixels right to cover xRatio*10 */ * xRatio) + 2,
     206//                                (int)(pPaintEvent->height()  /* 10 pixels right to cover y shift */  /* 10 pixels right to cover yRatio*10 */ * yRatio) + 2);
     207            pEvent->accept();
    200208            return true;
    201209        }
     
    255263    switch (vboxGlobal().vmRenderMode())
    256264    {
     265#ifdef VBOX_GUI_USE_QUARTZ2D
     266        case VBoxDefs::Quartz2DMode:
     267            /* Indicate that we are doing all drawing stuff ourself: */
     268            viewport()->setAttribute(Qt::WA_PaintOnScreen);
     269            m_pFrameBuffer = new UIFrameBufferQuartz2D(this);
     270            break;
     271#endif /* VBOX_GUI_USE_QUARTZ2D */
    257272        default:
    258273#ifdef VBOX_GUI_USE_QIMAGE
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette