Ejemplo n.º 1
0
void TileGrid::drawTileMapContents(CGContextRef context, CGRect layerBounds) const
{
    CGContextSetRGBFillColor(context, 0.3, 0.3, 0.3, 1);
    CGContextFillRect(context, layerBounds);

    CGFloat scaleFactor = layerBounds.size.width / m_controller.bounds().width();

    CGFloat contextScale = scaleFactor / m_scale;
    CGContextScaleCTM(context, contextScale, contextScale);

    for (TileMap::const_iterator it = m_tiles.begin(), end = m_tiles.end(); it != end; ++it) {
        const TileInfo& tileInfo = it->value;
        PlatformCALayer* tileLayer = tileInfo.layer.get();

        CGFloat red = 1;
        CGFloat green = 1;
        CGFloat blue = 1;
        CGFloat alpha = 1;
        if (tileInfo.hasStaleContent) {
            red = 0.25;
            green = 0.125;
            blue = 0;
        } else if (m_controller.shouldAggressivelyRetainTiles() && tileInfo.cohort != VisibleTileCohort) {
            red = 0.8;
            green = 0.8;
            blue = 0.8;
        }

        TileCohort newestCohort = newestTileCohort();
        TileCohort oldestCohort = oldestTileCohort();

        if (!m_controller.shouldAggressivelyRetainTiles() && tileInfo.cohort != VisibleTileCohort && newestCohort > oldestCohort)
            alpha = 1 - (static_cast<float>((newestCohort - tileInfo.cohort)) / (newestCohort - oldestCohort));

        CGContextSetRGBFillColor(context, red, green, blue, alpha);

        if (tileLayer->superlayer()) {
            CGContextSetLineWidth(context, 0.5 / contextScale);
            CGContextSetRGBStrokeColor(context, 0, 0, 0, 1);
        } else {
            CGContextSetLineWidth(context, 1 / contextScale);
            CGContextSetRGBStrokeColor(context, 0.2, 0.1, 0.9, 1);
        }

        CGRect frame = CGRectMake(tileLayer->position().x(), tileLayer->position().y(), tileLayer->bounds().size().width(), tileLayer->bounds().size().height());
        CGContextFillRect(context, frame);
        CGContextStrokeRect(context, frame);

        CGContextSetRGBFillColor(context, 0, 0, 0, 0.5);

        String repaintCount = String::number(m_tileRepaintCounts.get(tileLayer));

        CGContextSaveGState(context);

        tileLayer->drawTextAtPoint(context, frame.origin.x + 64, frame.origin.y + 192, CGSizeMake(3, -3), 58,
                                   repaintCount.ascii().data(), repaintCount.length());

        CGContextRestoreGState(context);
    }
}
Ejemplo n.º 2
0
void PlatformCALayer::drawRepaintIndicator(CGContextRef context, PlatformCALayer* platformCALayer, int repaintCount, CGColorRef customBackgroundColor)
{
    char text[16]; // that's a lot of repaints
    snprintf(text, sizeof(text), "%d", repaintCount);
    
    CGRect indicatorBox = platformCALayer->bounds();

    CGContextSaveGState(context);

    indicatorBox.size.width = 12 + 10 * strlen(text);
    indicatorBox.size.height = 27;
    
    CGContextSetAlpha(context, 0.5f);
    CGContextBeginTransparencyLayerWithRect(context, indicatorBox, 0);
    
    if (customBackgroundColor)
        CGContextSetFillColorWithColor(context, customBackgroundColor);
    else
        CGContextSetRGBFillColor(context, 0, 0.5f, 0.25f, 1);
    
    CGContextFillRect(context, indicatorBox);
    
    if (platformCALayer->acceleratesDrawing())
        CGContextSetRGBFillColor(context, 1, 0, 0, 1);
    else
        CGContextSetRGBFillColor(context, 1, 1, 1, 1);
    
    platformCALayer->drawTextAtPoint(context, indicatorBox.origin.x + 5, indicatorBox.origin.y + 22, CGSizeMake(1, -1), 22, text, strlen(text));
    
    CGContextEndTransparencyLayer(context);
    CGContextRestoreGState(context);
}
void PlatformCALayer::drawRepaintIndicator(CGContextRef context, PlatformCALayer* platformCALayer, int repaintCount, CGColorRef customBackgroundColor)
{
    char text[16]; // that's a lot of repaints
    snprintf(text, sizeof(text), "%d", repaintCount);

    CGRect indicatorBox = platformCALayer->bounds();
    indicatorBox.size.width = 12 + 10 * strlen(text);
    indicatorBox.size.height = 27;
    CGContextSaveGState(context);

    CGContextSetAlpha(context, 0.5f);
    CGContextBeginTransparencyLayerWithRect(context, indicatorBox, 0);

    if (customBackgroundColor)
        CGContextSetFillColorWithColor(context, customBackgroundColor);
    else
        CGContextSetRGBFillColor(context, 0, 0.5f, 0.25f, 1);

    CGContextFillRect(context, indicatorBox);

    if (platformCALayer->acceleratesDrawing())
        CGContextSetRGBFillColor(context, 1, 0, 0, 1);
    else
        CGContextSetRGBFillColor(context, 1, 1, 1, 1);

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
    CGContextSetTextMatrix(context, CGAffineTransformMakeScale(1, -1));
    CGContextSelectFont(context, "Helvetica", 22, kCGEncodingMacRoman);
    CGContextShowTextAtPoint(context, indicatorBox.origin.x + 5, indicatorBox.origin.y + 22, text, strlen(text));
#pragma clang diagnostic pop

    CGContextEndTransparencyLayer(context);
    CGContextRestoreGState(context);
}
void drawSkewedCoordinateSystem(CGContextRef context)
{
    // alpha is 22.5 degrees and beta is 15 degrees.
    float alpha = M_PI/8, beta = M_PI/12;
    CGAffineTransform skew;
    // Create a rectangle that is 72 units on a side
    // with its origin at (0,0).
    CGRect r = CGRectMake(0, 0, 72, 72);
    
    CGContextTranslateCTM(context, 144, 144);
    // Draw the coordinate axes untransformed.
    drawCoordinateAxes(context);
    // Fill the rectangle.
    CGContextFillRect(context, r);

    // Create an affine transform that skews the coordinate system,
    // skewing the x-axis by alpha radians and the y-axis by beta radians. 
    skew = CGAffineTransformMake(1, tan(alpha), tan(beta), 1, 0, 0);
    // Apply that transform to the context coordinate system.
    CGContextConcatCTM(context, skew);

    // Set the fill and stroke color to a dark blue.
    CGContextSetRGBStrokeColor(context, 0.11, 0.208, 0.451, 1);
    CGContextSetRGBFillColor(context, 0.11, 0.208, 0.451, 1);
    
    // Draw the coordinate axes again, now transformed.
    drawCoordinateAxes(context);
    // Set the fill color again but with a partially transparent alpha.
    CGContextSetRGBFillColor(context, 0.11, 0.208, 0.451, 0.7);
    // Fill the rectangle in the transformed coordinate system.
    CGContextFillRect(context, r);
}
Ejemplo n.º 5
0
/*
OvalsDrawEventHandler : Handles the draw events for the "Ovals" window.

Parameter DescriptionsinHandler : A reference to the current handler call chain. This is passed to your handler so that you can call CallNextEventHandler if you need to.
inEvent : The event that triggered this call.
inUserData : The application-specific data you passed in to InstallEventHandler.
*/
OSStatus OvalsDrawEventHandler (EventHandlerCallRef inHandler, EventRef inEvent, void* inUserData) {
	OSStatus status = eventNotHandledErr;
	CGContextRef context;
    CGRect r;
	
	//CallNextEventHandler in order to make sure the default handling of the inEvent 
	// (drawing the white background) happens
	status = CallNextEventHandler( inHandler, inEvent );
	require_noerr(status, CantCallNextEventHandler);
	
	// Get the CGContextRef
	status = GetEventParameter (inEvent, 
								kEventParamCGContextRef, 
								typeCGContextRef, 
								NULL, 
								sizeof (CGContextRef),
								NULL,
								&context);
	require_noerr(status, CantGetEventParameter);
	
	// Draw the outer oval in the left portion of the window
    r.size.height = 210;
    r.origin.x = 20;
    r.origin.y = 20;
    r.size.width = 210;
    frameOval(context, r);
	
	// Draw the inner oval in the left portion of the window
    r.size.height = 145;
    r.origin.x = 75;
    r.origin.y = 55;
    r.size.width = 100;
    frameOval(context, r);
	
    /* Set the fill color to green. */
    CGContextSetRGBFillColor(context, 0, 1, 0, 1);
	
	// Draw and fill the outter oval in the right portion of the window
    r.size.height = 210;
    r.origin.x = 270;
    r.origin.y = 20;
    r.size.width = 210;
    paintOval(context, r);
	
    /* Set the fill color to yellow. */
    CGContextSetRGBFillColor(context, 1, 1, 0, 1);
	
	// Draw and fill the inner oval in the right portion of the window
    r.size.height = 145;
    r.origin.x = 325;
    r.origin.y = 55;
    r.size.width = 100;
    paintOval(context, r);

CantCallNextEventHandler:
CantGetEventParameter:
		
		return status;
}
Ejemplo n.º 6
0
void drawRoundedRect(CGContextRef context, CGRect rrect)
{
    // Drawing with a white stroke color
    CGContextSetRGBStrokeColor(context, 0.3, 0.3, 0.3, 1.0);
    CGContextSetRGBFillColor(context, 0.3, 0.3, 0.3, 1.0);
    
    // Add Rect to the current path, then stroke it
    //            CGContextAddRect(context, CGRectMake(10.0, 190.0, 290.0, 73.0));
    
    
    CGContextSetLineWidth(context, 1);
    CGFloat radius = 10.0;
    
    CGFloat minx = CGRectGetMinX(rrect), midx = CGRectGetMidX(rrect), maxx = CGRectGetMaxX(rrect);
    CGFloat miny = CGRectGetMinY(rrect), midy = CGRectGetMidY(rrect), maxy = CGRectGetMaxY(rrect);
    
    // Next, we will go around the rectangle in the order given by the figure below.
    //       minx    midx    maxx
    // miny    2       3       4
    // midy   1 9              5
    // maxy    8       7       6
    // Which gives us a coincident start and end point, which is incidental to this technique, but still doesn't
    // form a closed path, so we still need to close the path to connect the ends correctly.
    // Thus we start by moving to point 1, then adding arcs through each pair of points that follows.
    // You could use a similar tecgnique to create any shape with rounded corners.
    
    // Start at 1
    CGContextMoveToPoint(context, minx, midy);
    // Add an arc through 2 to 3
    CGContextAddArcToPoint(context, minx, miny, midx, miny, radius);
    // Add an arc through 4 to 5
    CGContextAddArcToPoint(context, maxx, miny, maxx, midy, radius);
    // Add an arc through 6 to 7
    CGContextAddArcToPoint(context, maxx, maxy, midx, maxy, radius);
    // Add an arc through 8 to 9
    CGContextAddArcToPoint(context, minx, maxy, minx, midy, radius);
    // Close the path
    CGContextClosePath(context);
    // Fill & stroke the path
    CGContextDrawPath(context, kCGPathFillStroke);
    
    CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 0.0);
    CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
    
    CGContextMoveToPoint(context, minx, midy);
    // Add an arc through 2 to 3
    CGContextAddArcToPoint(context, minx, miny, midx, miny, radius);
    // Add an arc through 4 to 5
    CGContextAddArcToPoint(context, maxx, miny, maxx, midy, radius);
    // Add an arc through 6 to 7
    CGContextAddArcToPoint(context, maxx, maxy, midx, maxy, radius);
    // Add an arc through 8 to 9
    CGContextAddArcToPoint(context, minx, maxy, minx, midy, radius);
    // Close the path
    CGContextClosePath(context);
    // Fill & stroke the path
    CGContextDrawPath(context, kCGPathFillStroke);
}
Ejemplo n.º 7
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);
}
Ejemplo n.º 8
0
void MacDock::overlay(const QString& text)
{
	if (text.isEmpty()) {
		overlayed = false;
		RestoreApplicationDockTileImage();
		return;
	}

	// Create the context
	CGContextRef context = BeginCGContextForApplicationDockTile();

	if (!overlayed) {
		overlayed = true;

		// Add some subtle drop down shadow
		// FIXME: Disabled because 10.2 doesn't support it
		//CGSize s = { 2.0, -4.0 };
		//CGContextSetShadow(context,s,5.0);
	}

	// Draw a circle
	CGContextBeginPath(context);
	CGContextAddArc(context, 95.0, 95.0, 25.0, 0.0, 2 * M_PI, true);
	CGContextClosePath(context);
	CGContextSetRGBFillColor(context, 1, 0.0, 0.0, 1);
	CGContextFillPath(context);

	// Set the clipping path to the same circle
	CGContextBeginPath(context);
	CGContextAddArc(context, 95.0, 95.0, 25.0, 0.0, 2 * M_PI, true);
	CGContextClip(context);

	// Remove drop shadow
	// FIXME: Disabled because 10.2 doesn't support it
	//CGSize s = { 0.0, -0.0 };
	//CGContextSetShadowWithColor(context, s, 0, NULL);

	// Select the appropriate font
	CGContextSelectFont(context,DOCK_FONT_NAME, DOCK_FONT_SIZE, kCGEncodingMacRoman);
	CGContextSetRGBFillColor(context, 1, 1, 1, 1);

	// Draw the text invisible
	CGPoint begin = CGContextGetTextPosition(context);
	CGContextSetTextDrawingMode(context, kCGTextInvisible);	
	CGContextShowTextAtPoint(context, begin.x, begin.y, text.toStdString().c_str(), text.length());
	CGPoint end = CGContextGetTextPosition(context);

	// Draw the text
	CGContextSetTextDrawingMode(context, kCGTextFill);	
	CGContextShowTextAtPoint(context, 95 - (end.x - begin.x)/2, 95 - 8, text.toStdString().c_str(), text.length());
	
	// Cleanup
	CGContextFlush(context);
	EndCGContextForApplicationDockTile(context);
}
DRAW_TEST_F(CGContextFlush, FillFlush, WhiteBackgroundTest<>) {
    CGContextRef context = GetDrawingContext();
    CGRect bounds = GetDrawingBounds();
    _CGContextPushBeginDraw(context);

    CGContextSetRGBFillColor(context, 1, 0, 0, 1);
    CGContextFillRect(context, bounds);

    // Flush the red fill rect
    CGContextFlush(context);

    CGContextSetRGBFillColor(context, 0, 0, 1, 1);
    CGContextFillRect(context, CGRectMake(0, 0, 300, 300));

    // We should still have red & blue rectangle should not show up.
    unsigned char* dataPtr = static_cast<unsigned char*>(CGBitmapContextGetData(context));
    ASSERT_NE(dataPtr, nullptr);

    // Validate only the red fill rect is executed.
    EXPECT_EQ(dataPtr[0], 0x00);
    EXPECT_EQ(dataPtr[1], 0x00);
    EXPECT_EQ(dataPtr[2], 0xff);
    EXPECT_EQ(dataPtr[3], 0xff);

    CGContextFlush(context);

    // We should now see the blue fill rect
    EXPECT_EQ(dataPtr[0], 0xff);
    EXPECT_EQ(dataPtr[1], 0x00);
    EXPECT_EQ(dataPtr[2], 0x00);
    EXPECT_EQ(dataPtr[3], 0xff);

    // Add some extra drawings
    CGContextClearRect(context, CGRectMake(100, 100, 200, 300));

    CGPoint center = _CGRectGetCenter(bounds);

    CGMutablePathRef concentricCirclesPath = CGPathCreateMutable();

    CGPathAddEllipseInRect(concentricCirclesPath, nullptr, _CGRectCenteredOnPoint({ 50, 50 }, center));
    CGPathAddEllipseInRect(concentricCirclesPath, nullptr, _CGRectCenteredOnPoint({ 100, 100 }, center));
    CGPathAddEllipseInRect(concentricCirclesPath, nullptr, _CGRectCenteredOnPoint({ 150, 150 }, center));
    CGPathAddEllipseInRect(concentricCirclesPath, nullptr, _CGRectCenteredOnPoint({ 200, 200 }, center));

    CGContextSetRGBFillColor(context, 1.0, 0.0, 0.0, 0.5);
    CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0);

    CGContextAddPath(context, concentricCirclesPath);
    CGContextDrawPath(context, kCGPathFillStroke);

    CGPathRelease(concentricCirclesPath);

    _CGContextPopEndDraw(context);
}
Ejemplo n.º 10
0
void drawMetaDataText (CGContextRef myContext, CGRect contextRect, CFURLRef url)
{
    float w, h;
    w = contextRect.size.width;
    h = contextRect.size.height;
    
    
	
	//Lets pull some metadata!
	
	struct metaData struct_metaData;
    
    bzero(struct_metaData.Title, 1024);
    bzero(struct_metaData.Header, 1024);
//    bzero(struct_metaData.Expdata, 1024);
//    bzero(struct_metaData.Resolution, 1024);
//    bzero(struct_metaData.JrnlTitle, 1024);
//    bzero(struct_metaData.JrnlRef, 1024);
//    bzero(struct_metaData.Keywds, 4000);
//    bzero(struct_metaData.JrnlAuthor, 4000);
    
	
	exportMetaData(url, &struct_metaData);
	
	
	int wraplength = 50;
	int colLength = wraplength+5;
    int rowLength = 10;
	int textposX = 5;
	int textposY = 10;
    
    int calc_textposX = textposX;
	int calc_textposY = textposY;
    
    
    CGContextSetRGBFillColor (myContext, 1, 1, 1, 1);
    
    
    CGContextSelectFont (myContext, "Helvetica", 20, kCGEncodingMacRoman);
	
    CGContextSetCharacterSpacing (myContext, 1);
    CGContextSetTextDrawingMode (myContext, kCGTextFill);
    
    CGContextSetRGBFillColor(myContext, 0, 0, 0, 1);
    
    if(struct_metaData.Title[0] != 0){
        calcRectangle("Title: ", struct_metaData.Title, rowLength, colLength, wraplength, &calc_textposX, &calc_textposY);
        drawRoundedRect(myContext, calc_textposX, calc_textposY);
    }
	
    DrawText("Title: ", struct_metaData.Title, myContext,  rowLength, colLength, wraplength, &textposX, &textposY);
    
}
Ejemplo n.º 11
0
void PlatformCALayer::drawRepaintIndicator(CGContextRef context, PlatformCALayer* platformCALayer, int repaintCount, CGColorRef customBackgroundColor)
{
    char text[16]; // that's a lot of repaints
    snprintf(text, sizeof(text), "%d", repaintCount);
    
    FloatRect indicatorBox = platformCALayer->bounds();\
    indicatorBox.setLocation( { 1, 1 } );
    indicatorBox.setSize(FloatSize(12 + 10 * strlen(text), 27));

    CGContextStateSaver stateSaver(context);
    
    CGContextSetAlpha(context, 0.5f);
    CGContextBeginTransparencyLayerWithRect(context, indicatorBox, 0);
    
    if (customBackgroundColor)
        CGContextSetFillColorWithColor(context, customBackgroundColor);
    else
        CGContextSetRGBFillColor(context, 0, 0.5f, 0.25f, 1);
    
    if (platformCALayer->isOpaque())
        CGContextFillRect(context, indicatorBox);
    else {
        Path boundsPath;
        boundsPath.moveTo(indicatorBox.maxXMinYCorner());
        boundsPath.addLineTo(indicatorBox.maxXMaxYCorner());
        boundsPath.addLineTo(indicatorBox.minXMaxYCorner());

        const float cornerChunk = 8;
        boundsPath.addLineTo(FloatPoint(indicatorBox.x(), indicatorBox.y() + cornerChunk));
        boundsPath.addLineTo(FloatPoint(indicatorBox.x() + cornerChunk, indicatorBox.y()));
        boundsPath.closeSubpath();

        CGContextAddPath(context, boundsPath.platformPath());
        CGContextFillPath(context);
    }

    if (platformCALayer->owner()->isUsingDisplayListDrawing(platformCALayer)) {
        CGContextSetRGBStrokeColor(context, 0, 0, 0, 0.65);
        CGContextSetLineWidth(context, 2);
        CGContextStrokeRect(context, indicatorBox);
    }

    if (platformCALayer->acceleratesDrawing())
        CGContextSetRGBFillColor(context, 1, 0, 0, 1);
    else
        CGContextSetRGBFillColor(context, 1, 1, 1, 1);
    
    platformCALayer->drawTextAtPoint(context, indicatorBox.x() + 5, indicatorBox.y() + 22, CGSizeMake(1, -1), 22, text, strlen(text));
    
    CGContextEndTransparencyLayer(context);
}
Ejemplo n.º 12
0
bool MCTileCacheCoreGraphicsCompositor_CompositeRect(void *p_context, int32_t p_x, int32_t p_y, uint32_t p_color)
{
	MCTileCacheCoreGraphicsCompositorContext *self;
	self = (MCTileCacheCoreGraphicsCompositorContext *)p_context;
	
	// IM-2013-08-23: [[ RefactorGraphics ]] Use MCGPixelUnpackNative to fix color swap issues
	uint8_t r, g, b, a;
	MCGPixelUnpackNative(p_color, r, g, b, a);
	
	CGFloat t_red, t_green, t_blue, t_alpha;
	t_red = r / 255.0;
	t_green = g / 255.0;
	t_blue = b / 255.0;
	t_alpha = a / 255.0;
	
	if (t_alpha != 1.0)
	{
		t_red /= t_alpha;
		t_green /= t_alpha;
		t_blue /= t_alpha;
	}
	
	CGContextSetRGBFillColor(self -> cgcontext, t_red, t_green, t_blue, t_alpha);
	CGContextFillRect(self -> cgcontext, CGRectMake(p_x, self -> viewport_height - (p_y + self -> tile_size), self -> tile_size, self -> tile_size));
	
	return true;
}
Ejemplo n.º 13
0
FX_BOOL CFX_QuartzDeviceDriver::FillRect(const FX_RECT*         rect,
        FX_ARGB                   fillArgb,
        int                       alphaFlag	   ,
        void*                     iccTransform ,
        int						blend_type )
{
    CGBlendMode mode = GetCGBlendMode(blend_type);
    if (mode != kCGBlendModeNormal) {
        CGContextSetBlendMode(_context, mode);
    }
    CGRect rect_fx = CGRectMake(rect->left, rect->top, rect->Width(), rect->Height());
    CGRect rect_usr = CGRectApplyAffineTransform(rect_fx, _foxitDevice2User);
    FX_INT32 a, r, g, b;
    ArgbDecode(fillArgb, a, r, g, b);
    CGContextSetRGBFillColor(_context,
                             r / 255.f,
                             g / 255.f,
                             b / 255.f,
                             a / 255.f);
    CGContextFillRect(_context, rect_usr);
    if (mode != kCGBlendModeNormal) {
        CGContextSetBlendMode(_context, kCGBlendModeNormal);
    }
    return TRUE;
}
void doRotatedEllipses(CGContextRef context)
{
	int i, totreps = 144;
	float  tint = 1.0, tintIncrement = 1.0/totreps;
	// Create a new transform consisting of a 45 degrees rotation.
	CGAffineTransform theTransform = CGAffineTransformMakeRotation(M_PI/4);
	// Apply a scale to the transform just created.
	theTransform = CGAffineTransformScale(theTransform, 1, 2);
	// Place the first ellipse at a good location.
	CGContextTranslateCTM(context, 100., 100.);
	
	for(i=0 ; i < totreps ; i++){
		// Make a snapshot the coordinate system.
		CGContextSaveGState(context);
			// Set up the coordinate system for the rotated ellipse.
			CGContextConcatCTM(context, theTransform);
			CGContextBeginPath(context);
			CGContextAddArc(context, 0., 0., 45., 0., 2*M_PI, 0); 
			// Set the fill color for this instance of the ellipse.
			CGContextSetRGBFillColor(context, tint, 0., 0., 1.0);
			CGContextDrawPath(context, kCGPathFill);
		// Restore the coordinate system to that of the snapshot.
		CGContextRestoreGState(context);
		// Compute the next tint color.
		tint -= tintIncrement;
		// Move over by 1 unit in x for the next ellipse.
		CGContextTranslateCTM(context, 1.0, 0.0);
	}
}
DRAW_TEST_F(CGImageDrawing, DrawAContextIntoAnImage, UIKitMimicTest<>) {
    // This test will create a bitmap context, draw some entity into the context, then create a image out of the bitmap context.
    // Thereafter it will draw the image into the Canvas context

    static woc::unique_cf<CGColorSpaceRef> rgbColorSpace(CGColorSpaceCreateDeviceRGB());
    // Create a bitmap context to draw the Image into
    woc::unique_cf<CGContextRef> contextImage(CGBitmapContextCreate(
        nullptr, 10, 10, 8, 4 * 10 /* bytesPerRow = bytesPerPixel*width*/, rgbColorSpace.get(), kCGImageAlphaPremultipliedFirst));
    ASSERT_NE(contextImage, nullptr);

    CGContextSetRGBFillColor(contextImage.get(), 1.0, 0.0, 0.0, 1.0);
    CGContextFillRect(contextImage.get(), { 0, 0, 10, 10 });

    // Create the image out of the bitmap context
    woc::unique_cf<CGImageRef> image(CGBitmapContextCreateImage(contextImage.get()));
    ASSERT_NE(image, nullptr);

    CGContextRef context = GetDrawingContext();
    CGRect bounds = GetDrawingBounds();

    CGAffineTransform flip = CGAffineTransformMakeScale(1, -1);
    CGAffineTransform shift = CGAffineTransformTranslate(flip, 0, bounds.size.height * -1);
    CGContextConcatCTM(context, shift);

    // draw the image
    CGContextDrawImage(context, bounds, image.get());
}
Ejemplo n.º 16
0
static void quartzgen_path(GVJ_t *job, int filled)
{
	CGContextRef context = (CGContextRef)job->context;
	
	/* set up colors */
	if (filled)
		CGContextSetRGBFillColor(context, job->obj->fillcolor.u.RGBA [0], job->obj->fillcolor.u.RGBA [1], job->obj->fillcolor.u.RGBA [2], job->obj->fillcolor.u.RGBA [3]);
	CGContextSetRGBStrokeColor(context, job->obj->pencolor.u.RGBA [0], job->obj->pencolor.u.RGBA [1], job->obj->pencolor.u.RGBA [2], job->obj->pencolor.u.RGBA [3]);
	
	/* set up line style */
	const CGFloat *segments;
	size_t segment_count;
	switch (job->obj->pen) {
	case PEN_DASHED:
		segments = dashed;
		segment_count = sizeof(dashed)/sizeof(CGFloat);
		break;
	case PEN_DOTTED:
		segments = dotted;
		segment_count = sizeof(dotted)/sizeof(CGFloat);
		break;
	default:
		segments = NULL;
		segment_count = 0;
		break;
	}
	CGContextSetLineDash(context, 0.0, segments, segment_count);

	/* set up line width */
	CGContextSetLineWidth(context, job->obj->penwidth); // *job->scale.x);
	
	/* draw the path */
	CGContextDrawPath(context, filled ? kCGPathFillStroke : kCGPathStroke);
}
Ejemplo n.º 17
0
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);
}
Ejemplo n.º 18
0
void drawRoundedRect(CGContextRef context, int x, int y){
    
    struct CGRect cgRect;
	struct CGPoint cgPoint;
	cgRect.size.width = 640;
	cgRect.size.height = y+30;
	cgPoint.x = 0;
	cgPoint.y = 5;
	cgRect.origin = cgPoint;
    
    
    //printf("Drawing %f, %f, %f, %f", cgPoint.x, cgPoint.y, cgRect.size.width, cgRect.size.height);
    
    
    CGContextBeginPath(context);
    
    float ovalWidth = 10;
    float ovalHeight = 10;
    
    float fw, fh;
    // If the width or height of the corner oval is zero, then it reduces to a right angle,
    // so instead of a rounded rectangle we have an ordinary one.
    if (ovalWidth == 0 || ovalHeight == 0) {
        CGContextAddRect(context, cgRect);
        return;
    }
    
    //  Save the context's state so that the translate and scale can be undone with a call
    //  to CGContextRestoreGState.
    CGContextSaveGState(context);
    
    //  Translate the origin of the contex to the lower left corner of the rectangle.
    CGContextTranslateCTM(context, CGRectGetMinX(cgRect), CGRectGetMinY(cgRect));
    
    //Normalize the scale of the context so that the width and height of the arcs are 1.0
    CGContextScaleCTM(context, ovalWidth, ovalHeight);
    
    // Calculate the width and height of the rectangle in the new coordinate system.
    fw = CGRectGetWidth(cgRect) / ovalWidth;
    fh = CGRectGetHeight(cgRect) / ovalHeight;
    
    // CGContextAddArcToPoint adds an arc of a circle to the context's path (creating the rounded
    // corners).  It also adds a line from the path's last point to the begining of the arc, making
    // the sides of the rectangle.
    CGContextMoveToPoint(context, fw, fh/2);  // Start at lower right corner
    CGContextAddArcToPoint(context, fw, fh, fw/2, fh, 1);  // Top right corner
    CGContextAddArcToPoint(context, 0, fh, 0, fh/2, 1); // Top left corner
    CGContextAddArcToPoint(context, 0, 0, fw/2, 0, 1); // Lower left corner
    CGContextAddArcToPoint(context, fw, 0, fw, fh/2, 1); // Back to lower right
    
    // Close the path
    CGContextClosePath(context);
    
    CGContextSetRGBFillColor (context, 1, 1, 1, 0.7);
    
    CGContextFillPath(context);
    
    CGContextRestoreGState(context);
    
}
DRAW_TEST_P(CGContextFillMode, OverlappedEllipses) {
    CGContextRef context = GetDrawingContext();
    CGRect bounds = GetDrawingBounds();
    bounds = CGRectInset(bounds, 16.f, 16.f);
    CGFloat width = bounds.size.width;
    CGFloat height = bounds.size.height;
    CGFloat xstart = bounds.origin.x;
    CGFloat ystart = bounds.origin.y;

    CGPathDrawingMode fillMode = GetParam();

    CGMutablePathRef leftCircles = CGPathCreateMutable();

    CGPathMoveToPoint(leftCircles, NULL, xstart + .25 * width + .4 * height, ystart + .5 * height);
    CGPathAddArc(leftCircles, NULL, xstart + .25 * width, ystart + .5 * height, .4 * height, 0, M_PI, true);
    CGPathAddArc(leftCircles, NULL, xstart + .25 * width, ystart + .5 * height, .4 * height, M_PI, 0, true);

    CGPathMoveToPoint(leftCircles, NULL, xstart + .25 * width + .3 * height, ystart + .5 * height);
    CGPathAddArc(leftCircles, NULL, xstart + .25 * width, ystart + .5 * height, .3 * height, 0, M_PI, true);
    CGPathAddArc(leftCircles, NULL, xstart + .25 * width, ystart + .5 * height, .3 * height, M_PI, 0, true);

    CGPathMoveToPoint(leftCircles, NULL, xstart + .25 * width + .2 * height, ystart + .5 * height);
    CGPathAddArc(leftCircles, NULL, xstart + .25 * width, ystart + .5 * height, .2 * height, 0, M_PI, true);
    CGPathAddArc(leftCircles, NULL, xstart + .25 * width, ystart + .5 * height, .2 * height, M_PI, 0, true);

    CGPathMoveToPoint(leftCircles, NULL, xstart + .25 * width + .1 * height, ystart + .5 * height);
    CGPathAddArc(leftCircles, NULL, xstart + .25 * width, ystart + .5 * height, .1 * height, 0, M_PI, true);
    CGPathAddArc(leftCircles, NULL, xstart + .25 * width, ystart + .5 * height, .1 * height, M_PI, 0, true);

    CGPathCloseSubpath(leftCircles);

    CGMutablePathRef rightCircles = CGPathCreateMutable();

    CGPathMoveToPoint(rightCircles, NULL, xstart + .75 * width + .4 * height, ystart + .5 * height);
    CGPathAddArc(rightCircles, NULL, xstart + .75 * width, ystart + .5 * height, .4 * height, 0, M_PI, false);
    CGPathAddArc(rightCircles, NULL, xstart + .75 * width, ystart + .5 * height, .4 * height, M_PI, 0, false);

    CGPathMoveToPoint(rightCircles, NULL, xstart + .75 * width + .3 * height, ystart + .5 * height);
    CGPathAddArc(rightCircles, NULL, xstart + .75 * width, ystart + .5 * height, .3 * height, 0, M_PI, true);
    CGPathAddArc(rightCircles, NULL, xstart + .75 * width, ystart + .5 * height, .3 * height, M_PI, 0, true);

    CGPathMoveToPoint(rightCircles, NULL, xstart + .75 * width + .2 * height, ystart + .5 * height);
    CGPathAddArc(rightCircles, NULL, xstart + .75 * width, ystart + .5 * height, .2 * height, 0, M_PI, false);
    CGPathAddArc(rightCircles, NULL, xstart + .75 * width, ystart + .5 * height, .2 * height, M_PI, 0, false);

    CGPathMoveToPoint(rightCircles, NULL, xstart + .75 * width + .1 * height, ystart + .5 * height);
    CGPathAddArc(rightCircles, NULL, xstart + .75 * width, ystart + .5 * height, .1 * height, 0, M_PI, true);
    CGPathAddArc(rightCircles, NULL, xstart + .75 * width, ystart + .5 * height, .1 * height, M_PI, 0, true);

    CGPathCloseSubpath(rightCircles);

    CGContextAddPath(context, leftCircles);
    CGContextAddPath(context, rightCircles);
    CGContextSetRGBFillColor(context, 0, 0, 1, 1);
    CGContextSetRGBStrokeColor(context, 1, 0, 0, 1);
    CGContextDrawPath(context, fillMode);

    CGPathRelease(leftCircles);
    CGPathRelease(rightCircles);
}
Ejemplo n.º 20
0
void drawTextWithSpacing(GraphicsContext* graphicsContext, const SimpleFontData* font, const wxColour& color, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point)
{
    graphicsContext->save();
    
    wxGCDC* dc = static_cast<wxGCDC*>(graphicsContext->platformContext());

    wxFont* wxfont = font->getWxFont();
    graphicsContext->setFillColor(graphicsContext->fillColor(), ColorSpaceDeviceRGB);

    CGContextRef cgContext = static_cast<CGContextRef>(dc->GetGraphicsContext()->GetNativeContext());

    CGFontRef cgFont = font->platformData().cgFont();
    
    CGContextSetFont(cgContext, cgFont);

    CGContextSetFontSize(cgContext, wxfont->GetPointSize());

    CGFloat red, green, blue, alpha;
    graphicsContext->fillColor().getRGBA(red, green, blue, alpha);
    CGContextSetRGBFillColor(cgContext, red, green, blue, alpha);

    CGAffineTransform matrix = CGAffineTransformIdentity;
    matrix.b = -matrix.b;
    matrix.d = -matrix.d;
    
    CGContextSetTextMatrix(cgContext, matrix);

    CGContextSetTextPosition(cgContext, point.x(), point.y());
    
    CGContextShowGlyphsWithAdvances(cgContext, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs);
    
    if (cgFont)
        CGFontRelease(cgFont);
    graphicsContext->restore();
}
Ejemplo n.º 21
0
    bool setBrush(const GiContext* ctx)
    {
        bool changed = !_ctxused[1];
        
        if (ctx && ctx->hasFillColor())
        {
            if (_gictx.getFillColor() != ctx->getFillColor()) {
                _gictx.setFillColor(ctx->getFillColor());
                changed = true;
            }
        }
        if (!ctx) ctx = &_gictx;
        if (ctx->hasFillColor() && changed)
        {
            _ctxused[1] = true;
            
            GiColor color = ctx->getFillColor();
            if (gs())
                color = gs()->calcPenColor(color);
            CGContextSetRGBFillColor(getContext(), 
                                     toFloat(color.r), toFloat(color.g),
                                     toFloat(color.b), toFloat(color.a));
        }

        return ctx->hasFillColor();
    }
Ejemplo n.º 22
0
void MacVegaPrinterListener::SetClipRect(const OpRect& clip)
{
	CGContextRestoreGState(m_ctx);
	CGContextSaveGState(m_ctx);
	CGContextClipToRect(m_ctx, CGRectMake(clip.x, m_winHeight-(clip.y+clip.height), clip.width, clip.height));
	CGContextSetRGBFillColor(m_ctx, m_red, m_green, m_blue, m_alpha);
	CGContextSetRGBStrokeColor(m_ctx, m_red, m_green, m_blue, m_alpha);
}
Ejemplo n.º 23
0
void map_bkg_rectangle(MapGC *mgc, MapSettings *settings,
		       int x, int y, int width, int height)
{
  if (FALSE);
#ifdef HAVE_CAIRO
  else if (mgc->cairo_cr)
    {
      cairo_set_operator(mgc->cairo_cr, CAIRO_OPERATOR_OVER);
      cairo_set_source_rgba(mgc->cairo_cr, .937, .937, .937, .8);
      cairo_rectangle(mgc->cairo_cr, x, y, width, height);
      cairo_fill(mgc->cairo_cr);
      cairo_set_operator(mgc->cairo_cr, CAIRO_OPERATOR_SOURCE);
    }
#endif
#ifdef HAVE_GTK
  else if (mgc->gtk_drawable)
    {
      gdk_gc_set_function(mgc->gtk_gc, GDK_OR);
      gdk_gc_set_foreground(mgc->gtk_gc, &settings->textback);
      gdk_draw_rectangle(mgc->gtk_drawable, mgc->gtk_gc, TRUE,
			 x, y, width, height);
      gdk_gc_set_function(mgc->gtk_gc, GDK_COPY);
    }
#endif
#ifdef HAVE_QT
  else if (mgc->qt_painter)
    {
      qt_bkg_rectangle(mgc->qt_painter, settings,
		       x, y, width, height);
    }
#endif
#ifdef HAVE_QUARTZ
  else if (mgc->quartz_gc)
    {
      CGContextSetRGBFillColor(mgc->quartz_gc, .937, .937, .937, 1.);
      //gdk_gc_set_function(mgc->gtk_gc, GDK_OR);
      //gdk_gc_set_foreground(mgc->gtk_gc, &settings->textback);
      //gdk_draw_rectangle(mgc->gtk_drawable, mgc->gtk_gc, TRUE,
      //		 x, y, width, height);
      //gdk_gc_set_function(mgc->gtk_gc, GDK_COPY);
    }
#endif
#ifdef WIN32
  else if (mgc->win_dc)
    {
      COLORREF color = RGB(0xa5, 0xa6, 0xa5);
      HBRUSH brush = CreateSolidBrush(color);
      HBRUSH oldBrush = SelectObject(mgc->win_dc, brush);
      SetROP2(mgc->win_dc, R2_MERGEPEN);
      win32_setpen(mgc, 4, color);
      Rectangle(mgc->win_dc, x, y, x + width, y + height);
      SetROP2(mgc->win_dc, R2_COPYPEN);
      SelectObject(mgc->win_dc, oldBrush);
      DeleteObject(brush);
    }
#endif
}
Ejemplo n.º 24
0
void MacVegaPrinterListener::SetColor(UINT8 red, UINT8 green, UINT8 blue, UINT8 alpha)
{
	m_red=((float)red)/255.0;
	m_green=((float)green)/255.0;
	m_blue=((float)blue)/255.0;
	m_alpha=((float)alpha)/255.0;
	CGContextSetRGBFillColor(m_ctx, m_red, m_green, m_blue, m_alpha);
	CGContextSetRGBStrokeColor(m_ctx, m_red, m_green, m_blue, m_alpha);
}
Ejemplo n.º 25
0
// -----------------------------------------------------------------------------
//	HITestViewDraw
// -----------------------------------------------------------------------------
//	Here's the fun stuff.  Draw a red box when not hilighted, a blue box 
//	when hilighted.
//
OSStatus HITestViewDraw(
	EventRef				inEvent,
	HITestViewData*			inData )
{
	OSStatus				err;
	HIRect					bounds;
	CGContextRef			context;
        float				red, green, blue;
        
	err = GetEventParameter( inEvent, kEventParamCGContextRef, typeCGContextRef,
			NULL, sizeof( CGContextRef ), NULL, &context );
	require_noerr( err, ParameterMissing );

	err = HIViewGetBounds( inData->view, &bounds );
	
        red = inData->red;
	green = inData->green;
	blue = inData->blue;
        
	switch ( GetControlHilite( inData->view ) )
	{
		case kControlNoPart:
			CGContextSetRGBFillColor( context, red, green, blue, 0.25 );
			CGContextSetRGBStrokeColor( context, red, green, blue, 1 );
			break;
		
		// Handle synthetic highlights, too
		case kControlInactivePart:
		case kControlDisabledPart:
			CGContextSetRGBFillColor( context, red, green, blue, 0.10 );
			CGContextSetRGBStrokeColor( context, red, green, blue, 0.10 );
			break;
		
		default:
			CGContextSetRGBFillColor( context, 0, 0, 1, 0.25 );
			CGContextSetRGBStrokeColor( context, 0, 0, 1, 1 );
			break;
	}
	CGContextFillRect( context, bounds );
	CGContextStrokeRect( context, bounds );

ParameterMissing:
	return err;
}
Ejemplo n.º 26
0
FX_BOOL CQuartz2D::drawGraphicsString(void*                 graphics,
                                      void*                 font,
                                      FX_FLOAT              fontSize,
                                      FX_WORD*              glyphIndices,
                                      CGPoint*           glyphPositions,
                                      FX_INT32              charsCount,
                                      FX_ARGB               argb,
                                      CFX_AffineMatrix*     matrix )
{
    if (!graphics) {
        return FALSE;
    }
    CGContextRef context = (CGContextRef) graphics;
    CGContextSetFont(context, (CGFontRef)font);
    CGContextSetFontSize(context, fontSize);
    if (matrix) {
        CGAffineTransform m = CGContextGetTextMatrix(context);
        m = CGAffineTransformConcat(m,
                                    CGAffineTransformMake(matrix->a,
                                            matrix->b,
                                            matrix->c,
                                            matrix->d,
                                            matrix->e,
                                            matrix->f));
        CGContextSetTextMatrix(context, m);
    }
    FX_INT32 a, r, g, b;
    ArgbDecode(argb, a, r, g, b);
    CGContextSetRGBFillColor(context,
                             r / 255.f,
                             g / 255.f,
                             b / 255.f,
                             a / 255.f);
    CGContextSaveGState(context);
#if CGFLOAT_IS_DOUBLE
    CGPoint* glyphPositionsCG = new CGPoint[charsCount];
    if (!glyphPositionsCG) {
        return FALSE;
    }
    for (int index = 0; index < charsCount; ++index) {
        glyphPositionsCG[index].x = glyphPositions[index].x;
        glyphPositionsCG[index].y = glyphPositions[index].y;
    }
#else
    CGPoint* glyphPositionsCG = (CGPoint*)glyphPositions;
#endif
    CGContextShowGlyphsAtPositions(context,
                                   (CGGlyph *) glyphIndices,
                                   glyphPositionsCG,
                                   charsCount);
#if CGFLOAT_IS_DOUBLE
    delete[] glyphPositionsCG;
#endif
    CGContextRestoreGState(context);
    return TRUE;
}
Ejemplo n.º 27
0
static void Quartz_SetFill(int fill, double gamma, NewDevDesc *dd)
{
    QuartzDesc *xd = (QuartzDesc*)dd->deviceSpecific;
    xd->fill = fill;
    CGContextSetRGBFillColor( GetContext(xd), 
			      (float)R_RED(fill)/255.0, 
			      (float)R_GREEN(fill)/255.0, 
			      (float)R_BLUE(fill)/255.0, 
			      (float)R_ALPHA(fill)/255.0);
}
Ejemplo n.º 28
0
void CFX_QuartzDeviceDriver::setFillInfo(FX_ARGB argb)
{
    FX_INT32 a, r, g, b;
    ArgbDecode(argb, a, r, g, b);
    CGContextSetRGBFillColor(_context,
                             r / 255.f,
                             g / 255.f,
                             b / 255.f,
                             a / 255.f);
}
Ejemplo n.º 29
0
//-----------------------------------------------------------------------------
void CGDrawContext::setFillColor (const CColor& color)
{
	if (currentState.fillColor == color)
		return;

	if (cgContext)
		CGContextSetRGBFillColor (cgContext, color.red/255.f, color.green/255.f, color.blue/255.f, color.alpha/255.f);

	CDrawContext::setFillColor (color);
}
Ejemplo n.º 30
0
DRAW_TEST_F(CGContextFlush, FillFlushMultipleDrawingCounters, WhiteBackgroundTest<>) {
    CGContextRef context = GetDrawingContext();
    CGRect bounds = GetDrawingBounds();
    static int sDrawCount = 5;

    for (int i = 0; i < sDrawCount; ++i) {
        _CGContextPushBeginDraw(context);
    }

    CGContextSetRGBFillColor(context, 1, 0, 0, 1);
    CGContextFillRect(context, bounds);

    for (int i = 0; i < sDrawCount; ++i) {
        // Multiple flushes should work.
        CGContextFlush(context);
    }

    // Add some extra drawings
    CGContextClearRect(context, bounds);

    // We should still have red & clear should not of been executed.
    unsigned char* dataPtr = static_cast<unsigned char*>(CGBitmapContextGetData(context));
    ASSERT_NE(dataPtr, nullptr);

    // Validate only the red fill rect is executed.
    EXPECT_EQ(dataPtr[0], 0x00);
    EXPECT_EQ(dataPtr[1], 0x00);
    EXPECT_EQ(dataPtr[2], 0xff);
    EXPECT_EQ(dataPtr[3], 0xff);

    for (int i = 0; i < 3; ++i) {
        // Multiple flushes should work.
        CGContextFlush(context);
    }

    // validate clear
    EXPECT_EQ(dataPtr[0], 0x00);
    EXPECT_EQ(dataPtr[1], 0x00);
    EXPECT_EQ(dataPtr[2], 0x00);
    EXPECT_EQ(dataPtr[3], 0x00);

    CGContextSetRGBStrokeColor(context, 0, 1, 0, 1);
    CGContextStrokeRect(context, CGRectMake(100, 100, 200, 300));

    // Still should be clear.
    EXPECT_EQ(dataPtr[0], 0x00);
    EXPECT_EQ(dataPtr[1], 0x00);
    EXPECT_EQ(dataPtr[2], 0x00);
    EXPECT_EQ(dataPtr[3], 0x00);

    for (int i = 0; i < sDrawCount; ++i) {
        _CGContextPopEndDraw(context);
    }
}