void BackingStore::incorporateUpdate(ShareableBitmap* bitmap, const UpdateInfo& updateInfo)
{
    if (!m_backend)
        m_backend = createBackend();

    scroll(updateInfo.scrollRect, updateInfo.scrollOffset);

    // Paint all update rects.
    IntPoint updateRectLocation = updateInfo.updateRectBounds.location();
    RefPtr<cairo_t> context = adoptRef(cairo_create(m_backend->surface()));
    GraphicsContext graphicsContext(context.get());
    for (const auto& updateRect : updateInfo.updateRects) {
        IntRect srcRect = updateRect;
        srcRect.move(-updateRectLocation.x(), -updateRectLocation.y());
#if PLATFORM(GTK)
        if (!m_webPageProxy.drawsBackground()) {
            const WebCore::Color color = m_webPageProxy.backgroundColor();
            if (color.hasAlpha())
                graphicsContext.clearRect(srcRect);
            if (color.alpha() > 0)
                graphicsContext.fillRect(srcRect, color, ColorSpaceDeviceRGB);
        }
#endif
        bitmap->paint(graphicsContext, deviceScaleFactor(), updateRect.location(), srcRect);
    }
}
void CoordinatedGraphicsScene::paintToGraphicsContext(PlatformGraphicsContext* platformContext, const Color& backgroundColor, bool drawsBackground)
{
    if (!m_textureMapper)
        m_textureMapper = TextureMapper::create();
    ASSERT(m_textureMapper->accelerationMode() == TextureMapper::SoftwareMode);
    syncRemoteContent();
    TextureMapperLayer* layer = rootLayer();

    if (!layer)
        return;

    GraphicsContext graphicsContext(platformContext);
    m_textureMapper->setGraphicsContext(&graphicsContext);
    m_textureMapper->beginPainting();

    IntRect clipRect = graphicsContext.clipBounds();
    if (drawsBackground)
        m_textureMapper->drawSolidColor(clipRect, TransformationMatrix(), backgroundColor);
    else
        m_textureMapper->drawSolidColor(clipRect, TransformationMatrix(), m_viewBackgroundColor);

    layer->paint();
    m_fpsCounter.updateFPSAndDisplay(m_textureMapper.get(), clipRect.location());
    m_textureMapper->endPainting();
    m_textureMapper->setGraphicsContext(0);
}
Beispiel #3
0
void LayerTextureUpdaterSkPicture::prepareToUpdate(const IntRect& contentRect, const IntSize& tileSize, int borderTexels, float contentsScale)
{
    SkCanvas* canvas = m_picture.beginRecording(contentRect.width(), contentRect.height());
    PlatformContextSkia platformContext(canvas);
    platformContext.setDeferred(true);
    GraphicsContext graphicsContext(&platformContext);
    paintContents(graphicsContext, contentRect, contentsScale);
    m_picture.endRecording();
}
Beispiel #4
0
void WKCACFLayer::display(PlatformGraphicsContext* context)
{
    if (!m_owner)
        return;

    CGContextSaveGState(context);

    CGRect layerBounds = bounds();
    if (m_owner->contentsOrientation() == WebCore::GraphicsLayer::CompositingCoordinatesTopDown) {
        CGContextScaleCTM(context, 1, -1);
        CGContextTranslateCTM(context, 0, -layerBounds.size.height);
    }

    if (m_owner->client()) {
        GraphicsContext graphicsContext(context);

        // It's important to get the clip from the context, because it may be significantly
        // smaller than the layer bounds (e.g. tiled layers)
        CGRect clipBounds = CGContextGetClipBoundingBox(context);
        IntRect clip(enclosingIntRect(clipBounds));
        m_owner->paintGraphicsLayerContents(graphicsContext, clip);
    }
#ifndef NDEBUG
    else {
        ASSERT_NOT_REACHED();

        // FIXME: ideally we'd avoid calling -setNeedsDisplay on a layer that is a plain color,
        // so CA never makes backing store for it (which is what -setNeedsDisplay will do above).
        CGContextSetRGBFillColor(context, 0.0f, 1.0f, 0.0f, 1.0f);
        CGContextFillRect(context, layerBounds);
    }
#endif

    if (m_owner->showRepaintCounter()) {
        char text[16]; // that's a lot of repaints
        _snprintf(text, sizeof(text), "%d", m_owner->incrementRepaintCount());

        CGContextSaveGState(context);
        CGContextSetRGBFillColor(context, 1.0f, 0.0f, 0.0f, 0.8f);
        
        CGRect aBounds = layerBounds;

        aBounds.size.width = 10 + 12 * strlen(text);
        aBounds.size.height = 25;
        CGContextFillRect(context, aBounds);
        
        CGContextSetRGBFillColor(context, 0.0f, 0.0f, 0.0f, 1.0f);

        CGContextSetTextMatrix(context, CGAffineTransformMakeScale(1.0f, -1.0f));
        CGContextSelectFont(context, "Helvetica", 25, kCGEncodingMacRoman);
        CGContextShowTextAtPoint(context, aBounds.origin.x + 3.0f, aBounds.origin.y + 20.0f, text, strlen(text));
        
        CGContextRestoreGState(context);        
    }

    CGContextRestoreGState(context);
}
Beispiel #5
0
void ChunkedUpdateDrawingArea::paintIntoUpdateChunk(UpdateChunk* updateChunk)
{
    QImage image(updateChunk->createImage());
    QPainter painter(&image);
    // Now paint into the backing store.
    GraphicsContext graphicsContext(&painter);
    graphicsContext.translate(-updateChunk->rect().x(), -updateChunk->rect().y());

    m_webPage->drawRect(graphicsContext, updateChunk->rect());
}
Beispiel #6
0
void SkPictureCanvasLayerTextureUpdater::prepareToUpdate(const IntRect& contentRect, const IntSize& /* tileSize */, int /* borderTexels */, float contentsScale, IntRect* resultingOpaqueRect)
{
    SkCanvas* canvas = m_picture.beginRecording(contentRect.width(), contentRect.height());
    PlatformContextSkia platformContext(canvas);
    platformContext.setDeferred(true);
    platformContext.setTrackOpaqueRegion(!m_layerIsOpaque);
    GraphicsContext graphicsContext(&platformContext);
    paintContents(graphicsContext, platformContext, contentRect, contentsScale);
    m_picture.endRecording();

    if (!m_layerIsOpaque)
        *resultingOpaqueRect = platformContext.opaqueRegion().asRect();
}
Beispiel #7
0
bool GraphicsLayerAndroid::paintContext(SkPicture* context,
                                        const IntRect& rect)
{
    SkAutoPictureRecord arp(context, rect.width(), rect.height());
    SkCanvas* canvas = arp.getRecordingCanvas();

    if (!canvas)
        return false;

    PlatformGraphicsContext platformContext(canvas);
    GraphicsContext graphicsContext(&platformContext);

    paintGraphicsLayerContents(graphicsContext, rect);
    return true;
}
Beispiel #8
0
void ChunkedUpdateDrawingArea::paintIntoUpdateChunk(UpdateChunk* updateChunk)
{
    RetainPtr<CGColorSpaceRef> colorSpace(AdoptCF, CGColorSpaceCreateDeviceRGB());
    RetainPtr<CGContextRef> bitmapContext(AdoptCF, CGBitmapContextCreate(updateChunk->data(), updateChunk->rect().width(), updateChunk->rect().height(), 8, updateChunk->rect().width() * 4, colorSpace.get(), kCGImageAlphaPremultipliedLast));

    // WebCore expects a flipped coordinate system.
    CGContextTranslateCTM(bitmapContext.get(), 0.0, updateChunk->rect().height());
    CGContextScaleCTM(bitmapContext.get(), 1.0, -1.0);

    // Now paint into the backing store.
    GraphicsContext graphicsContext(bitmapContext.get());
    graphicsContext.translate(-updateChunk->rect().x(), -updateChunk->rect().y());
    
    m_webPage->drawRect(graphicsContext, updateChunk->rect());
}
Beispiel #9
0
void LayerTextureUpdaterSkPicture::prepareToUpdate(const IntRect& contentRect, const IntSize& tileSize, int borderTexels)
{
    // Need to recreate FBO if tile-size changed.
    // Note that we cannot create the framebuffer here because this function does not run in compositor thread
    // and hence does not have access to compositor context.
    if (m_bufferSize != tileSize) {
        m_createFrameBuffer = true;
        m_bufferSize = tileSize;
    }

    SkCanvas* canvas = m_picture.beginRecording(contentRect.width(), contentRect.height());
    PlatformContextSkia platformContext(canvas);
    GraphicsContext graphicsContext(&platformContext);
    paintContents(graphicsContext, contentRect);
    m_picture.endRecording();
}
Beispiel #10
0
int main()
{  
	cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1000, 1000);
	cairo_t *g = cairo_create(surface);

	cairo_set_source_rgb(g, 0.75, 0.34, 0.0);

	CairoContext graphicsContext(g);
	draw(&graphicsContext, testData01);
	graphicsContext.stroke();

	cairo_surface_write_to_png(surface, "cairotest.png");
	
	cairo_surface_destroy(surface);
	cairo_destroy(g);  
	
	
	return 0;
}
Beispiel #11
0
FloatRect Path::strokeBoundingRect(StrokeStyleApplier* applier) const
{
    CGContextRef context = scratchContext();

    CGContextSaveGState(context);
    CGContextBeginPath(context);
    CGContextAddPath(context, platformPath());

    if (applier) {
        GraphicsContext graphicsContext(context);
        applier->strokeStyle(&graphicsContext);
    }

    CGContextReplacePathWithStrokedPath(context);
    CGRect box = CGContextIsPathEmpty(context) ? CGRectZero : CGContextGetPathBoundingBox(context);
    CGContextRestoreGState(context);

    return box;
}
void BackingStore::incorporateUpdate(ShareableBitmap* bitmap, const UpdateInfo& updateInfo)
{
    if (m_pixmap.isNull())
        m_pixmap = QPixmap(m_size);

    scroll(updateInfo.scrollRect, updateInfo.scrollOffset);

    IntPoint updateRectLocation = updateInfo.updateRectBounds.location();

    QPainter painter(&m_pixmap);
    GraphicsContext graphicsContext(&painter);

    // Paint all update rects.
    for (size_t i = 0; i < updateInfo.updateRects.size(); ++i) {
        IntRect updateRect = updateInfo.updateRects[i];
        IntRect srcRect = updateRect;
        srcRect.move(-updateRectLocation.x(), -updateRectLocation.y());
        bitmap->paint(graphicsContext, updateRect.location(), srcRect);
    }
}
void BackingStore::incorporateUpdate(ShareableBitmap* bitmap, const UpdateInfo& updateInfo)
{
    if (!m_backingStore)
#if PLATFORM(EFL)
        m_backingStore = WidgetBackingStoreCairo::create(EwkView::toEvasObject(toAPI(&m_webPageProxy)), size(), deviceScaleFactor());
#else
        m_backingStore = createBackingStoreForGTK(m_webPageProxy.viewWidget(), size(), deviceScaleFactor());
#endif

    scroll(updateInfo.scrollRect, updateInfo.scrollOffset);

    // Paint all update rects.
    IntPoint updateRectLocation = updateInfo.updateRectBounds.location();
    RefPtr<cairo_t> context(adoptRef(cairo_create(m_backingStore->cairoSurface())));
    GraphicsContext graphicsContext(context.get());
    for (size_t i = 0; i < updateInfo.updateRects.size(); ++i) {
        IntRect updateRect = updateInfo.updateRects[i];
        IntRect srcRect = updateRect;
        srcRect.move(-updateRectLocation.x(), -updateRectLocation.y());
        bitmap->paint(graphicsContext, deviceScaleFactor(), updateRect.location(), srcRect);
    }
}
Beispiel #14
0
void BackingStore::incorporateUpdate(ShareableBitmap* bitmap, const UpdateInfo& updateInfo)
{
    if (!m_backingStore)
        m_backingStore = WidgetBackingStore::create(m_webPageProxy->viewWidget(), size());

    scroll(updateInfo.scrollRect, updateInfo.scrollOffset);

    // Paint all update rects.
    IntPoint updateRectLocation = updateInfo.updateRectBounds.location();
    RefPtr<cairo_t> context(adoptRef(cairo_create(m_backingStore->cairoSurface())));
    GraphicsContext graphicsContext(context.get());
    for (size_t i = 0; i < updateInfo.updateRects.size(); ++i) {
        IntRect updateRect = updateInfo.updateRects[i];
        IntRect srcRect = updateRect;
        srcRect.move(-updateRectLocation.x(), -updateRectLocation.y());
        bitmap->paint(graphicsContext, updateRect.location(), srcRect);
    }

#if PLATFORM(EFL)
    // Update ewk_view with new backingStore image.
    ewk_view_image_data_set(m_webPageProxy->viewWidget(), cairo_image_surface_get_data(m_backingStore->cairoSurface()), m_size);
#endif
}
    virtual void drawInContext(PlatformGraphicsContext* context)
    {
        if (!m_owner)
            return;

        CGContextSaveGState(context);

        CGRect layerBounds = bounds();
        if (m_owner->contentsOrientation() == WebCore::GraphicsLayer::CompositingCoordinatesTopDown) {
            CGContextScaleCTM(context, 1, -1);
            CGContextTranslateCTM(context, 0, -layerBounds.size.height);
        }

        if (m_owner->client()) {
            GraphicsContext graphicsContext(context);

            // It's important to get the clip from the context, because it may be significantly
            // smaller than the layer bounds (e.g. tiled layers)
            CGRect clipBounds = CGContextGetClipBoundingBox(context);
            IntRect clip(enclosingIntRect(clipBounds));
            m_owner->paintGraphicsLayerContents(graphicsContext, clip);
        }
#ifndef NDEBUG
        else {
            ASSERT_NOT_REACHED();

            // FIXME: ideally we'd avoid calling -setNeedsDisplay on a layer that is a plain color,
            // so CA never makes backing store for it (which is what -setNeedsDisplay will do above).
            CGContextSetRGBFillColor(context, 0.0f, 1.0f, 0.0f, 1.0f);
            CGContextFillRect(context, layerBounds);
        }
#endif

        if (m_owner->showRepaintCounter()) {
            String text = String::format("%d", m_owner->incrementRepaintCount());;

            CGContextSaveGState(context);
            CGContextSetRGBFillColor(context, 1.0f, 0.0f, 0.0f, 0.8f);
            
            CGRect aBounds = layerBounds;

            aBounds.size.width = 10 + 12 * text.length();
            aBounds.size.height = 25;
            CGContextFillRect(context, aBounds);
            
            FontDescription desc;

            NONCLIENTMETRICS metrics;
            metrics.cbSize = sizeof(metrics);
            SystemParametersInfo(SPI_GETNONCLIENTMETRICS, metrics.cbSize, &metrics, 0);
            FontFamily family;
            family.setFamily(metrics.lfSmCaptionFont.lfFaceName);
            desc.setFamily(family);

            desc.setComputedSize(22);
            
            Font font = Font(desc, 0, 0);
            font.update(0);

            GraphicsContext cg(context);
            cg.setFillColor(Color::black, DeviceColorSpace);
            cg.drawText(font, TextRun(text), IntPoint(aBounds.origin.x + 3, aBounds.origin.y + 20));

            CGContextRestoreGState(context);        
        }

        CGContextRestoreGState(context);
    }
Beispiel #16
0
void QWidget::scroll( int dx, int dy, const QRect& r )
{
    if ( testWState( WState_BlockUpdates ) && !children() )
	return;
    bool valid_rect = r.isValid();
    QRect sr = valid_rect?r:rect();
    int x1, y1, x2, y2, w=sr.width(), h=sr.height();
    if ( dx > 0 ) {
	x1 = sr.x();
	x2 = x1+dx;
	w -= dx;
    } else {
	x2 = sr.x();
	x1 = x2-dx;
	w += dx;
    }
    if ( dy > 0 ) {
	y1 = sr.y();
	y2 = y1+dy;
	h -= dy;
    } else {
	y2 = sr.y();
	y1 = y2-dy;
	h += dy;
    }

    if ( dx == 0 && dy == 0 )
	return;

    QSize s( qt_screen->width(), qt_screen->height() );
    QRegion alloc = valid_rect ? paintableRegion() : allocatedRegion();

    QRegion dAlloc = alloc;
    QPoint td1 = qt_screen->mapToDevice( QPoint(0,0), s );
    QPoint td2 = qt_screen->mapToDevice( QPoint(dx,dy), s );
    dAlloc.translate( td2.x()-td1.x(), td2.y()-td1.y() );

    QRegion scrollRegion( alloc & dAlloc );

    if ( w > 0 && h > 0 ) {
	QGfx * mygfx=graphicsContext( FALSE );
	mygfx->setClipDeviceRegion( scrollRegion );
	mygfx->scroll(x2,y2,w,h,x1,y1);
	delete mygfx;
    }

    paintable_region_dirty = TRUE;

    QPoint gpos = mapToGlobal( QPoint() );

    if ( !valid_rect && children() ) {	// scroll children
	setChildrenAllocatedDirty();
	QPoint pd( dx, dy );
	QObjectListIt it(*children());
	register QObject *object;
	while ( it ) {				// move all children
	    object = it.current();
	    if ( object->isWidgetType() ) {
		QWidget *w = (QWidget *)object;
		QPoint oldp = w->pos();
		QRect  r( w->pos() + pd, w->size() );
		w->crect = r;
		w->updateRequestedRegion( gpos + w->pos() );
		QMoveEvent e( r.topLeft(), oldp );
		QApplication::sendEvent( w, &e );
	    }
	    ++it;
	}
    }

    QSize ds( qt_screen->deviceWidth(), qt_screen->deviceHeight() );
    scrollRegion = qt_screen->mapFromDevice( scrollRegion, ds );
    scrollRegion.translate( -gpos.x(), -gpos.y() );

    QRegion update( sr );
    update -= scrollRegion;
    if ( dx ) {
	int x = x2 == sr.x() ? sr.x()+w : sr.x();
	update |= QRect( x, sr.y(), QABS(dx), sr.height() );
    }
    if ( dy ) {
	int y = y2 == sr.y() ? sr.y()+h : sr.y();
	update |= QRect( sr.x(), y, sr.width(), QABS(dy) );
    }
    repaint( update, !testWFlags(WRepaintNoErase) );
    if ( !valid_rect && children() )
	paint_children( this, update, FALSE );
}