Esempio n. 1
0
void GraphicsContext::drawImageBuffer(ImageBuffer* image, ColorSpace styleColorSpace, const IntRect& r, CompositeOperator op, BlendMode blendMode, bool useLowQualityScale)
{
    if (!image)
        return;
    drawImageBuffer(image, styleColorSpace, FloatRect(r), FloatRect(FloatPoint(), FloatSize(image->logicalSize())), op, blendMode, useLowQualityScale);
}
Esempio n. 2
0
FloatRect FloatRect::narrowPrecision(double x, double y, double width, double height)
{
    return FloatRect(narrowPrecisionToFloat(x), narrowPrecisionToFloat(y), narrowPrecisionToFloat(width), narrowPrecisionToFloat(height));
}
Esempio n. 3
0
	void rebuildBaseVert()
	{
		if (geo.w == 0 || geo.h == 0)
		{
			base.vert.clear();
			base.vert.commit();

			return;
		}

		const IntRect bgPos(2, 2, geo.w-4, geo.h-4);
		size_t count = 0;

		/* Stretched layer (1) */
		count += 1;

		/* Tiled layer (2) */
		base.bgTileQuads = TileQuads::twoDimCount(bgTileSrc.w, bgTileSrc.h, bgPos.w, bgPos.h);
		count += base.bgTileQuads;

		const Vec2 corOff(geo.w - 16, geo.h - 16);

		const Corners<FloatRect> cornerPos =
		{
			FloatRect(        0,        0, 16, 16 ), /* Top left */
			FloatRect( corOff.x,        0, 16, 16 ), /* Top right */
			FloatRect(        0, corOff.y, 16, 16 ), /* Bottom left */
			FloatRect( corOff.x, corOff.y, 16, 16 )  /* Bottom right */
		};

		const Vec2i sideLen(geo.w - 16*2, geo.h - 16*2);

		bool drawSidesLR = sideLen.x > 0;
		bool drawSidesTB = sideLen.y > 0;

		base.borderQuads = 0;
		base.borderQuads += 4; /* 4 corners */

		if (drawSidesLR)
			base.borderQuads += TileQuads::oneDimCount(32, sideLen.y) * 2;

		if (drawSidesTB)
			base.borderQuads += TileQuads::oneDimCount(32, sideLen.x) * 2;

		count += base.borderQuads;

		base.vert.resize(count);

		Vertex *vert = dataPtr(base.vert.vertices);
		size_t i = 0;

		/* Stretched background */
		i += Quad::setTexPosRect(&vert[i*4], bgStretchSrc, bgPos);

		/* Tiled background */
		i += TileQuads::build(bgTileSrc, bgPos, &vert[i*4]);

		/* Corners */
		i += Quad::setTexPosRect(&vert[i*4], cornerSrc.tl, cornerPos.tl);
		i += Quad::setTexPosRect(&vert[i*4], cornerSrc.tr, cornerPos.tr);
		i += Quad::setTexPosRect(&vert[i*4], cornerSrc.bl, cornerPos.bl);
		i += Quad::setTexPosRect(&vert[i*4], cornerSrc.br, cornerPos.br);

		/* Sides */
		if (drawSidesLR)
		{
			i += TileQuads::buildV(borderSrc.l, sideLen.y,        0,       16, &vert[i*4]);
			i += TileQuads::buildV(borderSrc.r, sideLen.y, corOff.x,       16, &vert[i*4]);
		}

		if (drawSidesTB)
		{
			i += TileQuads::buildH(borderSrc.t, sideLen.x,       16,        0, &vert[i*4]);
			i += TileQuads::buildH(borderSrc.b, sideLen.x,       16, corOff.y, &vert[i*4]);
		}

		base.vert.commit();
	}
Esempio n. 4
0
void RenderLineBreak::absoluteQuads(Vector<FloatQuad>& quads, bool* wasFixed) const
{
    if (!m_inlineBoxWrapper)
        return;
    quads.append(localToAbsoluteQuad(FloatRect(m_inlineBoxWrapper->topLeft(), m_inlineBoxWrapper->size()), 0 /* mode */, wasFixed));
}
Esempio n. 5
0
void Image::drawTiled(GraphicsContext& ctxt, const FloatRect& destRect, const FloatPoint& srcPoint, const FloatSize& scaledTileSize, const FloatSize& spacing, CompositeOperator op, BlendMode blendMode)
{    
    if (mayFillWithSolidColor()) {
        fillWithSolidColor(ctxt, destRect, solidColor(), op);
        return;
    }

    ASSERT(!isBitmapImage() || notSolidColor());

#if PLATFORM(IOS)
    FloatSize intrinsicTileSize = originalSize();
#else
    FloatSize intrinsicTileSize = size();
#endif
    if (hasRelativeWidth())
        intrinsicTileSize.setWidth(scaledTileSize.width());
    if (hasRelativeHeight())
        intrinsicTileSize.setHeight(scaledTileSize.height());

    FloatSize scale(scaledTileSize.width() / intrinsicTileSize.width(),
                    scaledTileSize.height() / intrinsicTileSize.height());

    FloatRect oneTileRect;
    FloatSize actualTileSize(scaledTileSize.width() + spacing.width(), scaledTileSize.height() + spacing.height());
    oneTileRect.setX(destRect.x() + fmodf(fmodf(-srcPoint.x(), actualTileSize.width()) - actualTileSize.width(), actualTileSize.width()));
    oneTileRect.setY(destRect.y() + fmodf(fmodf(-srcPoint.y(), actualTileSize.height()) - actualTileSize.height(), actualTileSize.height()));
    oneTileRect.setSize(scaledTileSize);
    
    // Check and see if a single draw of the image can cover the entire area we are supposed to tile.
    if (oneTileRect.contains(destRect) && !ctxt.drawLuminanceMask()) {
        FloatRect visibleSrcRect;
        visibleSrcRect.setX((destRect.x() - oneTileRect.x()) / scale.width());
        visibleSrcRect.setY((destRect.y() - oneTileRect.y()) / scale.height());
        visibleSrcRect.setWidth(destRect.width() / scale.width());
        visibleSrcRect.setHeight(destRect.height() / scale.height());
        draw(ctxt, destRect, visibleSrcRect, op, blendMode, ImageOrientationDescription());
        return;
    }

#if PLATFORM(IOS)
    // When using accelerated drawing on iOS, it's faster to stretch an image than to tile it.
    if (ctxt.isAcceleratedContext()) {
        if (size().width() == 1 && intersection(oneTileRect, destRect).height() == destRect.height()) {
            FloatRect visibleSrcRect;
            visibleSrcRect.setX(0);
            visibleSrcRect.setY((destRect.y() - oneTileRect.y()) / scale.height());
            visibleSrcRect.setWidth(1);
            visibleSrcRect.setHeight(destRect.height() / scale.height());
            draw(ctxt, destRect, visibleSrcRect, op, BlendModeNormal, ImageOrientationDescription());
            return;
        }
        if (size().height() == 1 && intersection(oneTileRect, destRect).width() == destRect.width()) {
            FloatRect visibleSrcRect;
            visibleSrcRect.setX((destRect.x() - oneTileRect.x()) / scale.width());
            visibleSrcRect.setY(0);
            visibleSrcRect.setWidth(destRect.width() / scale.width());
            visibleSrcRect.setHeight(1);
            draw(ctxt, destRect, visibleSrcRect, op, BlendModeNormal, ImageOrientationDescription());
            return;
        }
    }
#endif

    // Patterned images and gradients can use lots of memory for caching when the
    // tile size is large (<rdar://problem/4691859>, <rdar://problem/6239505>).
    // Memory consumption depends on the transformed tile size which can get
    // larger than the original tile if user zooms in enough.
#if PLATFORM(IOS)
    const float maxPatternTilePixels = 512 * 512;
#else
    const float maxPatternTilePixels = 2048 * 2048;
#endif
    FloatRect transformedTileSize = ctxt.getCTM().mapRect(FloatRect(FloatPoint(), scaledTileSize));
    float transformedTileSizePixels = transformedTileSize.width() * transformedTileSize.height();
    FloatRect currentTileRect = oneTileRect;
    if (transformedTileSizePixels > maxPatternTilePixels) {
        GraphicsContextStateSaver stateSaver(ctxt);
        ctxt.clip(destRect);

        currentTileRect.shiftYEdgeTo(destRect.y());
        float toY = currentTileRect.y();
        while (toY < destRect.maxY()) {
            currentTileRect.shiftXEdgeTo(destRect.x());
            float toX = currentTileRect.x();
            while (toX < destRect.maxX()) {
                FloatRect toRect(toX, toY, currentTileRect.width(), currentTileRect.height());
                FloatRect fromRect(toFloatPoint(currentTileRect.location() - oneTileRect.location()), currentTileRect.size());
                fromRect.scale(1 / scale.width(), 1 / scale.height());

                draw(ctxt, toRect, fromRect, op, BlendModeNormal, ImageOrientationDescription());
                toX += currentTileRect.width();
                currentTileRect.shiftXEdgeTo(oneTileRect.x());
            }
            toY += currentTileRect.height();
            currentTileRect.shiftYEdgeTo(oneTileRect.y());
        }
        return;
    }

    AffineTransform patternTransform = AffineTransform().scaleNonUniform(scale.width(), scale.height());
    FloatRect tileRect(FloatPoint(), intrinsicTileSize);
    drawPattern(ctxt, tileRect, patternTransform, oneTileRect.location(), spacing, op, destRect, blendMode);

#if PLATFORM(IOS)
    startAnimation(DoNotCatchUp);
#else
    startAnimation();
#endif
}
Esempio n. 6
0
FloatRect ChromeClientBlackBerry::pageRect()
{
    notImplemented();
    return FloatRect();
}
Esempio n. 7
0
void CCQuadCuller::cullOccludedQuads(CCQuadList& quadList, bool haveDamageRect, const FloatRect& damageRect, CCOverdrawCounts* overdrawMetrics)
{
    if (!quadList.size())
        return;

    CCQuadList culledList;
    culledList.reserveCapacity(quadList.size());

    Region opaqueCoverageThusFar;

    for (int i = quadList.size() - 1; i >= 0; --i) {
        CCDrawQuad* drawQuad = quadList[i].get();

        FloatRect floatTransformedRect = drawQuad->quadTransform().mapRect(FloatRect(drawQuad->quadRect()));
        if (haveDamageRect)
            floatTransformedRect.intersect(damageRect);
        // Inflate rect to be tested to stay conservative.
        IntRect transformedQuadRect(enclosingIntRect(floatTransformedRect));

        IntRect transformedVisibleQuadRect = rectSubtractRegion(opaqueCoverageThusFar, transformedQuadRect);
        bool keepQuad = !transformedVisibleQuadRect.isEmpty();

        // See if we can reduce the number of pixels to draw by reducing the size of the draw
        // quad - we do this by changing its visible rect.
        bool didReduceQuadSize = false;
        if (keepQuad) {
            if (transformedVisibleQuadRect != transformedQuadRect && drawQuad->isLayerAxisAlignedIntRect()) {
                drawQuad->setQuadVisibleRect(drawQuad->quadTransform().inverse().mapRect(transformedVisibleQuadRect));
                didReduceQuadSize = true;
            }

            // When adding rect to opaque region, deflate it to stay conservative.
            if (drawQuad->isLayerAxisAlignedIntRect() && !drawQuad->opaqueRect().isEmpty()) {
                FloatRect floatOpaqueRect = drawQuad->quadTransform().mapRect(FloatRect(drawQuad->opaqueRect()));
                opaqueCoverageThusFar.unite(Region(enclosedIntRect(floatOpaqueRect)));
            }

            culledList.append(quadList[i].release());
        }

        if (overdrawMetrics) {
            TRACE_EVENT("CCQuadCuller::cullOccludedQuads_OverdrawMetrics", 0, 0);
            // We compute the area of the transformed quad, as this should be in pixels.
            float area = quadArea(drawQuad->quadTransform().mapQuad(FloatQuad(drawQuad->quadRect())));
            if (keepQuad) {
                if (didReduceQuadSize) {
                    float visibleQuadRectArea = quadArea(drawQuad->quadTransform().mapQuad(FloatQuad(drawQuad->quadVisibleRect())));
                    overdrawMetrics->m_pixelsCulled += area - visibleQuadRectArea;
                    area = visibleQuadRectArea;
                }
                IntRect visibleOpaqueRect(drawQuad->quadVisibleRect());
                visibleOpaqueRect.intersect(drawQuad->opaqueRect());
                FloatQuad visibleOpaqueQuad = drawQuad->quadTransform().mapQuad(FloatQuad(visibleOpaqueRect));
                float opaqueArea = quadArea(visibleOpaqueQuad);
                overdrawMetrics->m_pixelsDrawnOpaque += opaqueArea;
                overdrawMetrics->m_pixelsDrawnTransparent += area - opaqueArea;
            } else
                overdrawMetrics->m_pixelsCulled += area;
        }
    }
    quadList.clear(); // Release anything that remains.

    culledList.reverse();
    quadList.swap(culledList);
}
Esempio n. 8
0
FloatRect screenRect(Widget* widget)
{
    return FloatRect(FloatPoint(), FloatSize(IntSize(BlackBerry::Platform::Graphics::Screen::primaryScreen()->size())));
}
Esempio n. 9
0
IntRect AffineTransform::mapRect(const IntRect &rect) const
{
    return enclosingIntRect(mapRect(FloatRect(rect)));
}
Esempio n. 10
0
void UIView::setRect(float left, float top, float width, float height)
{
	setRect(FloatRect(left, top, width, height));
}
Esempio n. 11
0
Game_Manager::Game_Manager(RenderWindow *app, View &view1, int screen_x, int screen_y)
    : m_view1(view1)
    , radio_icon(app, "resources/radioactive_icon.png", &view1)
    , food_icon(app, "resources/food_icon0.png", &view1)
    , metal_icon(app, "resources/iron_icon0.png", &view1)
    , radio_bar(app, "resources/radio_bar.png", &view1)
    , radio_bar_background(app, "resources/radio_bar_background.png", &view1)
    , radio_bar_grad(app, "resources/radio_bar_grad.png", &view1)
    , oxygen_bar(app, "resources/oxygen_bar.png", &view1)
    , oxygen_bar_background(app, "resources/oxygen_bar_background.png", &view1)
    , oxygen_bar_grad(app, "resources/oxygen_bar_grad.png", &view1)
    , head_icon(app, "resources/head_icon.png", &view1)
    , explosion(app, "resources/explosion.png", &view1)
    , background(app, "resources/background.png", &view1)
    , selection_border(app, "resources/selection_border.png", &view1)
    , goal_border(app, "resources/selection_border.png", &view1)
    , end_sprite(app, "resources/end.png", &view1)
    , bomb(app, "resources/bomb.png", &view1)
    , pause_sprite(app, "resources/pause.png", &view1)
    , info_sprite(app, "resources/info.png", &view1)
    , spriteTile0(app, "resources/invisible.png", &view1)
    , tile_size(384)
{

    //sounds
    buffer.loadFromFile("resources/explosion.ogg");

    sound.setBuffer(buffer);

    buffer_combat.loadFromFile("resources/combat.ogg");

    sound_combat.setBuffer(buffer_combat);

    monster_time.restart();

    //

    zoom = 1;
    zoom_rate = 10;
    zoom_change = ZOOM_NO_CHANGE;




    goal_border.add_color(255, 150, 50, 255);

    citizen_max = 10;
    monster_max = 10;
    citizen_number = citizen_max;
    food_number = 0;
    metal_number = 0;
    pause = false;
    clicked = false;
    glissor_on = false;
    info = true;
    cinematic_on = true;
    m_x_offset = tile_size * 2 + (tile_size / 2);
    m_y_offset = (tile_size / 2);
    oxygen_number = 1.0f;
    fail = false;

    m_app = app;
    m_app->setView(m_view1);

    m_screen_y = 1080;
    m_screen_x = 1920;

    m_view2.reset(FloatRect(0.0f, 0.0f, static_cast<float>(m_screen_x), static_cast<float>(m_screen_y)));
    m_view2.setViewport(FloatRect(0.0f, 0.0f, 1.0f, 1.0f));

    //init map
    for (size_t y = 0; y < 10; y++)
    {
        for (size_t x = 0; x < 5; x++)
        {

            my_map[y][x].setLevel(y);
            my_map[y][x].init_resources(m_app, &view1, x, y);

            if (y == 0)
            {            //surface

                my_map[y][x].setID(6 + x);
            }            
            else if(x >= 2 && x <5 && y == 4)
            {            //metro 3, 4, 5
                my_map[y][x].setID(1 + x);
            }
             else if(x >= 1 && x <4 && y == 6)
            {            //soutterrain

                my_map[y][x].setID(10 + x);
            }
             else if(x >= 2 && x <5 && y == 2)
            {            //egouts

                my_map[y][x].setID(12 + x);
            }
             else if (x >= 1 && x <4 && y == 5)
             {           

                 my_map[y][x].setID(24);
             }
             else if (x >= 0 && x <4 && y == 6)
             {

                 my_map[y][x].setID(24);
             }
             else if (x >= 0 && x <3 && y == 4)
             {            

                 my_map[y][x].setID(23);
             }
             else
            {
                my_map[y][x].setID(0);

            }
            // cout << my_map[y][x].isWalkable() << " ";
        }
     //   cout << endl;
    }

    //init sprites
    string path = "";
    for (int i = 0; i < 27; i++) {
        path = "resources/tile" + std::to_string(i) + ".png";
        sprites.push_back(My_Sprite{ m_app, path, &m_view1 });
        //      std::cout << path << endl;

    }

    //character in first case
    for (int i = 0; i < citizen_max; i++)
    {
        character1.push_back(Character{ m_app, &m_view1, i });
        citizen_state.push_back(true);
        character1[i].setPosition(2, 0);
    }
    citizen_number_text.init(app, "Still alive: ", 35, 1);
    metal_number_text.init(app, "Metal: ", 35, 1);
    food_number_text.init(app, "Foods: ", 35, 1);



    //monsters on surface
    for (int i = 0; i < monster_max; i++)
    {
        monster_state.push_back(true);
        monster1.push_back(Monster{ m_app, &m_view1, i });
    }
    citizen_number_text.init(app, "Still alive: ", 35, 1);

    //all the buttons

    buttons.push_back(Button{ m_app, "Dig", 0, 0, 0, 0, &m_view1 });
    buttons.push_back(Button{ m_app, "Move", 0, 0, 0, 0, &m_view1 });//button of the glissor
    buttons.push_back(Button{ m_app, 0, 0, 0, 0, &m_view1 });
    buttons.push_back(Button{ m_app, "Take resources", 0, 0, 0, 0, &m_view1 });//button of the ressources

    //buttons of buildings
    buttons.push_back(Button{ m_app, "resources/workshop_icon.png", true, 0, 0, 0, 0, &m_view2 });//button of the ressources
    buttons.push_back(Button{ m_app, "resources/electricity_icon.png", true, 0, 0, 0, 0, &m_view2 });//button of the ressources
    buttons.push_back(Button{ m_app, "resources/farm_icon.png", true, 0, 0, 0, 0, &m_view2 });//button of the ressources
    buttons.push_back(Button{ m_app, "resources/armory_icon.png", true, 0, 0, 0, 0, &m_view2 });//button of the ressources
    buttons.push_back(Button{ m_app, "resources/oxygen_icon.png", true, 0, 0, 0, 0, &m_view2 });//button of the ressources
    buttons.push_back(Button{ m_app, "resources/bunker_icon.png", true, 0, 0, 0, 0, &m_view2 });//button of the ressources


    glissor1.push_back(Glissor{ m_app, 0, 0, 0, 0, &m_view1 });
 
    update(0);
    cinematic_init();
    oxygen_clock.restart();
}
Esempio n. 12
0
void UIView::drawItself(GraphicsDevice* renderer, const mat4& transform )
{
	// Invisible UIView, stop rendering itself or children
	if(!m_visible)
	{
		return;
	}

	if(m_clipContents)
	{
		renderer->pushClippingRect(FloatRect(mRect.left,mRect.top,mRect.width, mRect.height));
	}

	mat4 absoluteTransform = mat4::identity;

	mat4 localTransform = mat4::translate(position) * mat4::rotatey(rotation_y) * mat4::rotatex(rotation_x);

	absoluteTransform = transform * localTransform;

	// Tel
	draw(renderer, absoluteTransform);


	for(std::size_t i = 0; i < components.size(); ++i)
	{
		components[i]->onRender(renderer, this, absoluteTransform);
	}

	if(m_clipContents)
	{
		renderer->popClippingRect();
	}

	// -- Pre Render Step (Before Children)
	preRender(renderer);
	
	// clip the overflowing children
	if(m_clipChildren)
	{
		if(getContext()->transformPointerCoordinates)
		{
			renderer->pushClippingRect(FloatRect(mRect.left / getContext()->targetWindowSize.x,mRect.top / getContext()->targetWindowSize.y,mRect.width / getContext()->targetWindowSize.x, mRect.height / getContext()->targetWindowSize.y), true);
		}
		else
		{
			renderer->pushClippingRect(FloatRect(mRect.left,mRect.top,mRect.width, mRect.height));
		}
	}

	// Let children render as well
	for(std::vector<UIView*>::const_iterator it = m_children.begin(); it != m_children.end(); it++)
	{
		(*it)->drawItself(renderer, absoluteTransform);
	}

	if(m_clipChildren)
		renderer->popClippingRect();

	// -- Post Render Step (After Children)
	postRender(renderer);
}
Esempio n. 13
0
void GraphicsContext::drawImageBuffer(ImageBuffer* image, ColorSpace styleColorSpace, const FloatRect& dest)
{
    if (!image)
        return;
    drawImageBuffer(image, styleColorSpace, dest, FloatRect(IntRect(IntPoint(), image->logicalSize())));
}
Esempio n. 14
0
void GraphicsContext::drawImageBuffer(ImageBuffer* image, ColorSpace styleColorSpace, const IntPoint& dest, const IntRect& srcRect, CompositeOperator op, BlendMode blendMode)
{
    drawImageBuffer(image, styleColorSpace, FloatRect(IntRect(dest, srcRect.size())), FloatRect(srcRect), op, blendMode);
}
Esempio n. 15
0
void GraphicsContext::drawImageBuffer(ImageBuffer* image, ColorSpace styleColorSpace, const IntRect& dest, const IntRect& srcRect, CompositeOperator op, bool useLowQualityScale)
{
    drawImageBuffer(image, styleColorSpace, FloatRect(dest), srcRect, op, useLowQualityScale);
}
bool RenderSVGResourceFilter::applyResource(RenderObject* object, RenderStyle*, GraphicsContext*& context, unsigned short resourceMode)
{
    ASSERT(object);
    ASSERT(context);
#ifndef NDEBUG
    ASSERT(resourceMode == ApplyToDefaultMode);
#else
    UNUSED_PARAM(resourceMode);
#endif

    // Returning false here, to avoid drawings onto the context. We just want to
    // draw the stored filter output, not the unfiltered object as well.
    if (m_filter.contains(object)) {
        FilterData* filterData = m_filter.get(object);
        if (filterData->builded)
            return false;

        delete m_filter.take(object); // Oops, have to rebuild, go through normal code path
    }

    OwnPtr<FilterData> filterData(new FilterData);
    FloatRect targetBoundingBox = object->objectBoundingBox();

    SVGFilterElement* filterElement = static_cast<SVGFilterElement*>(node());
    filterData->boundaries = filterElement->filterBoundingBox(targetBoundingBox);
    if (filterData->boundaries.isEmpty())
        return false;

    // Determine absolute transformation matrix for filter. 
    AffineTransform absoluteTransform;
    SVGImageBufferTools::calculateTransformationToOutermostSVGCoordinateSystem(object, absoluteTransform);
    if (!absoluteTransform.isInvertible())
        return false;

    // Eliminate shear of the absolute transformation matrix, to be able to produce unsheared tile images for feTile.
    filterData->shearFreeAbsoluteTransform = AffineTransform(absoluteTransform.xScale(), 0, 0, absoluteTransform.yScale(), absoluteTransform.e(), absoluteTransform.f());

    // Determine absolute boundaries of the filter and the drawing region.
    FloatRect absoluteFilterBoundaries = filterData->shearFreeAbsoluteTransform.mapRect(filterData->boundaries);
    FloatRect drawingRegion = object->strokeBoundingBox();
    drawingRegion.intersect(filterData->boundaries);
    FloatRect absoluteDrawingRegion = filterData->shearFreeAbsoluteTransform.mapRect(drawingRegion);

    // Create the SVGFilter object.
    bool primitiveBoundingBoxMode = filterElement->primitiveUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX;
    filterData->filter = SVGFilter::create(filterData->shearFreeAbsoluteTransform, absoluteDrawingRegion, targetBoundingBox, filterData->boundaries, primitiveBoundingBoxMode);

    // Create all relevant filter primitives.
    filterData->builder = buildPrimitives(filterData->filter.get());
    if (!filterData->builder)
        return false;

    // Calculate the scale factor for the use of filterRes.
    // Also see http://www.w3.org/TR/SVG/filters.html#FilterEffectsRegion
    FloatSize scale(1, 1);
    if (filterElement->hasAttribute(SVGNames::filterResAttr)) {
        scale.setWidth(filterElement->filterResX() / absoluteFilterBoundaries.width());
        scale.setHeight(filterElement->filterResY() / absoluteFilterBoundaries.height());
    }

    if (scale.isEmpty())
        return false;

    // Determine scale factor for filter. The size of intermediate ImageBuffers shouldn't be bigger than kMaxFilterSize.
    FloatRect tempSourceRect = absoluteDrawingRegion;
    tempSourceRect.scale(scale.width(), scale.height());
    fitsInMaximumImageSize(tempSourceRect.size(), scale);

    // Set the scale level in SVGFilter.
    filterData->filter->setFilterResolution(scale);

    FilterEffect* lastEffect = filterData->builder->lastEffect();
    if (!lastEffect)
        return false;

    RenderSVGResourceFilterPrimitive::determineFilterPrimitiveSubregion(lastEffect, filterData->filter.get());
    FloatRect subRegion = lastEffect->maxEffectRect();
    // At least one FilterEffect has a too big image size,
    // recalculate the effect sizes with new scale factors.
    if (!fitsInMaximumImageSize(subRegion.size(), scale)) {
        filterData->filter->setFilterResolution(scale);
        RenderSVGResourceFilterPrimitive::determineFilterPrimitiveSubregion(lastEffect, filterData->filter.get());
    }

    // If the drawingRegion is empty, we have something like <g filter=".."/>.
    // Even if the target objectBoundingBox() is empty, we still have to draw the last effect result image in postApplyResource.
    if (drawingRegion.isEmpty()) {
        ASSERT(!m_filter.contains(object));
        filterData->savedContext = context;
        m_filter.set(object, filterData.leakPtr());
        return false;
    }

    absoluteDrawingRegion.scale(scale.width(), scale.height());

    OwnPtr<ImageBuffer> sourceGraphic;
    if (!SVGImageBufferTools::createImageBuffer(absoluteDrawingRegion, absoluteDrawingRegion, sourceGraphic, ColorSpaceLinearRGB)) {
        ASSERT(!m_filter.contains(object));
        filterData->savedContext = context;
        m_filter.set(object, filterData.leakPtr());
        return false;
    }
    
    GraphicsContext* sourceGraphicContext = sourceGraphic->context();
    ASSERT(sourceGraphicContext);
  
    sourceGraphicContext->translate(-absoluteDrawingRegion.x(), -absoluteDrawingRegion.y());
    if (scale.width() != 1 || scale.height() != 1)
        sourceGraphicContext->scale(scale);

    sourceGraphicContext->concatCTM(filterData->shearFreeAbsoluteTransform);
    sourceGraphicContext->clearRect(FloatRect(FloatPoint(), absoluteDrawingRegion.size()));
    filterData->sourceGraphicBuffer = sourceGraphic.release();
    filterData->savedContext = context;

    context = sourceGraphicContext;

    ASSERT(!m_filter.contains(object));
    m_filter.set(object, filterData.leakPtr());

    return true;
}
Esempio n. 17
0
void GraphicsContext::clip(const IntRect& rect)
{
    clip(FloatRect(rect));
}
Esempio n. 18
0
TextStream& operator<<(TextStream& ts, const LayoutRect& rect)
{
    return ts << FloatRect(rect);
}
Esempio n. 19
0
LayoutRect RenderedPosition::absoluteRect(int* extraWidthToEndOfLine) const
{
    if (isNull())
        return LayoutRect();

    LayoutRect localRect = m_renderer->localCaretRect(m_inlineBox, m_offset, extraWidthToEndOfLine);
    return localRect == LayoutRect() ? LayoutRect() : m_renderer->localToAbsoluteQuad(FloatRect(localRect)).enclosingBoundingBox();
}
Esempio n. 20
0
FloatRect screenAvailableRect(Widget* w)
{
    QRect r = QApplication::desktop()->availableGeometry(screenNumber(w));
    return FloatRect(r.x(), r.y(), r.width(), r.height());
}
Esempio n. 21
0
void RenderLineBreak::absoluteRects(Vector<IntRect>& rects, const LayoutPoint& accumulatedOffset) const
{
    if (!m_inlineBoxWrapper)
        return;
    rects.append(enclosingIntRect(FloatRect(accumulatedOffset + m_inlineBoxWrapper->topLeft(), m_inlineBoxWrapper->size())));
}
Esempio n. 22
0
void GraphicsSurface::platformPaintToTextureMapper(TextureMapper* textureMapper, const FloatRect& targetRect, const TransformationMatrix& transform, float opacity, BitmapTexture* mask)
{
    TransformationMatrix adjustedTransform = transform;
    adjustedTransform.multiply(TransformationMatrix::rectToRect(FloatRect(FloatPoint::zero(), m_size), targetRect));
    static_cast<TextureMapperGL*>(textureMapper)->drawTexture(platformGetTextureID(), 0, m_size, targetRect, adjustedTransform, opacity, mask);
}
Esempio n. 23
0
IntRect GraphicsContext::clipBounds() const
{
    double x1, x2, y1, y2;
    cairo_clip_extents(platformContext()->cr(), &x1, &y1, &x2, &y2);
    return enclosingIntRect(FloatRect(x1, y1, x2 - x1, y2 - y1));
}
Esempio n. 24
0
void RenderPath::setPath(const Path& newPath)
{
    m_path = newPath;
    m_strokeBbox = FloatRect();
    m_fillBBox = FloatRect();
}
Esempio n. 25
0
bool RenderSVGResourceFilter::applyResource(RenderObject* object, RenderStyle*, GraphicsContext*& context, unsigned short resourceMode)
{
    ASSERT(object);
    ASSERT(context);
#ifndef NDEBUG
    ASSERT(resourceMode == ApplyToDefaultMode);
#else
    UNUSED_PARAM(resourceMode);
#endif

    // Returning false here, to avoid drawings onto the context. We just want to
    // draw the stored filter output, not the unfiltered object as well.
    if (m_filter.contains(object)) {
        FilterData* filterData = m_filter.get(object);
        if (filterData->builded)
            return false;

        delete m_filter.take(object); // Oops, have to rebuild, go through normal code path
    }

    OwnPtr<FilterData> filterData(new FilterData);
    filterData->builder = buildPrimitives();
    if (!filterData->builder)
        return false;

    FloatRect paintRect = object->strokeBoundingBox();

    // Calculate the scale factor for the use of filterRes.
    // Also see http://www.w3.org/TR/SVG/filters.html#FilterEffectsRegion
    SVGFilterElement* filterElement = static_cast<SVGFilterElement*>(node());
    filterData->boundaries = filterElement->filterBoundingBox(object->objectBoundingBox());
    if (filterData->boundaries.isEmpty())
        return false;

    FloatSize scale(1.0f, 1.0f);
    if (filterElement->hasAttribute(SVGNames::filterResAttr)) {
        scale.setWidth(filterElement->filterResX() / filterData->boundaries.width());
        scale.setHeight(filterElement->filterResY() / filterData->boundaries.height());
    }

    if (scale.isEmpty())
        return false;

    // clip sourceImage to filterRegion
    FloatRect clippedSourceRect = paintRect;
    clippedSourceRect.intersect(filterData->boundaries);

    // scale filter size to filterRes
    FloatRect tempSourceRect = clippedSourceRect;

    // scale to big sourceImage size to kMaxFilterSize
    tempSourceRect.scale(scale.width(), scale.height());
    fitsInMaximumImageSize(tempSourceRect.size(), scale);

    // prepare Filters
    bool primitiveBoundingBoxMode = filterElement->primitiveUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX;
    filterData->filter = SVGFilter::create(paintRect, filterData->boundaries, primitiveBoundingBoxMode);
    filterData->filter->setFilterResolution(scale);

    FilterEffect* lastEffect = filterData->builder->lastEffect();
    if (!lastEffect)
        return false;
    
    lastEffect->calculateEffectRect(filterData->filter.get());
    // At least one FilterEffect has a too big image size,
    // recalculate the effect sizes with new scale factors.
    if (!fitsInMaximumImageSize(filterData->filter->maxImageSize(), scale)) {
        filterData->filter->setFilterResolution(scale);
        lastEffect->calculateEffectRect(filterData->filter.get());
    }

    clippedSourceRect.scale(scale.width(), scale.height());

    // Draw the content of the current element and it's childs to a imageBuffer to get the SourceGraphic.
    // The size of the SourceGraphic is clipped to the size of the filterRegion.
    IntRect bufferRect = enclosingIntRect(clippedSourceRect);
    OwnPtr<ImageBuffer> sourceGraphic(ImageBuffer::create(bufferRect.size(), LinearRGB));
    
    if (!sourceGraphic.get())
        return false;

    GraphicsContext* sourceGraphicContext = sourceGraphic->context();
    sourceGraphicContext->translate(-clippedSourceRect.x(), -clippedSourceRect.y());
    sourceGraphicContext->scale(scale);
    sourceGraphicContext->clearRect(FloatRect(FloatPoint(), paintRect.size()));
    filterData->sourceGraphicBuffer = sourceGraphic.release();
    filterData->savedContext = context;

    context = sourceGraphicContext;

    ASSERT(!m_filter.contains(object));
    m_filter.set(object, filterData.leakPtr());

    return true;
}
Esempio n. 26
0
FloatRect RenderPath::drawMarkersIfNeeded(GraphicsContext* context, const FloatRect& rect, const Path& path) const
{
    Document* doc = document();

    SVGElement* svgElement = static_cast<SVGElement*>(element());
    ASSERT(svgElement && svgElement->document() && svgElement->isStyled());

    SVGStyledElement* styledElement = static_cast<SVGStyledElement*>(svgElement);
    const SVGRenderStyle* svgStyle = style()->svgStyle();

    AtomicString startMarkerId(SVGURIReference::getTarget(svgStyle->startMarker()));
    AtomicString midMarkerId(SVGURIReference::getTarget(svgStyle->midMarker()));
    AtomicString endMarkerId(SVGURIReference::getTarget(svgStyle->endMarker()));

    SVGResourceMarker* startMarker = getMarkerById(doc, startMarkerId);
    SVGResourceMarker* midMarker = getMarkerById(doc, midMarkerId);
    SVGResourceMarker* endMarker = getMarkerById(doc, endMarkerId);

    if (!startMarker && !startMarkerId.isEmpty())
        svgElement->document()->accessSVGExtensions()->addPendingResource(startMarkerId, styledElement);
    else if (startMarker)
        startMarker->addClient(styledElement);

    if (!midMarker && !midMarkerId.isEmpty())
        svgElement->document()->accessSVGExtensions()->addPendingResource(midMarkerId, styledElement);
    else if (midMarker)
        midMarker->addClient(styledElement);

    if (!endMarker && !endMarkerId.isEmpty())
        svgElement->document()->accessSVGExtensions()->addPendingResource(endMarkerId, styledElement);
    else if (endMarker)
        endMarker->addClient(styledElement);

    if (!startMarker && !midMarker && !endMarker)
        return FloatRect();

    double strokeWidth = KSVGPainterFactory::cssPrimitiveToLength(this, svgStyle->strokeWidth(), 1.0);
    DrawMarkersData data(context, startMarker, midMarker, strokeWidth);

    path.apply(&data, drawStartAndMidMarkers);

    data.previousMarkerData.marker = endMarker;
    data.previousMarkerData.type = End;
    drawMarkerWithData(context, data.previousMarkerData);

    // We know the marker boundaries, only after they're drawn!
    // Otherwhise we'd need to do all the marker calculation twice
    // once here (through paint()) and once in absoluteClippedOverflowRect().
    FloatRect bounds;

    if (startMarker)
        bounds.unite(startMarker->cachedBounds());

    if (midMarker)
        bounds.unite(midMarker->cachedBounds());

    if (endMarker)
        bounds.unite(endMarker->cachedBounds());

    return bounds;
}
Esempio n. 27
0
void RenderView::absoluteQuads(Vector<FloatQuad>& quads)
{
    quads.append(FloatRect(0, 0, m_layer->width(), m_layer->height()));
}
Esempio n. 28
0
void GraphicsContext::drawImage(Image* image, ColorSpace styleColorSpace, const IntRect& dest, const IntRect& srcRect, CompositeOperator op, RespectImageOrientationEnum shouldRespectImageOrientation, bool useLowQualityScale)
{
    drawImage(image, styleColorSpace, FloatRect(dest), srcRect, op, shouldRespectImageOrientation, useLowQualityScale);
}
Esempio n. 29
0
	void rebuildCursorVert()
	{
		const IntRect rect = cursorRect->toIntRect();
		const CursorSrc &src = cursorSrc;

		cursorVertArrayDirty = true;

		if (rect.w <= 0 || rect.h <= 0)
		{
			cursorVert.clear();
			return;
		}

		const Vec2 corOff(rect.w - 4, rect.h - 4);

		const Corners<FloatRect> cornerPos =
		{
			FloatRect(        0,        0, 4, 4 ), /* Top left */
			FloatRect( corOff.x,        0, 4, 4 ), /* Top right */
			FloatRect(        0, corOff.y, 4, 4 ), /* Bottom left */
			FloatRect( corOff.x, corOff.y, 4, 4 )  /* Bottom right */
		};

		const Vec2i sideLen(rect.w - 4*2, rect.h - 4*2);

		const Sides<FloatRect> sidePos =
		{
		    FloatRect(        0,        4,         4, sideLen.y ), /* Left */
		    FloatRect( corOff.x,        4,         4, sideLen.y ), /* Right */
		    FloatRect(        4,        0, sideLen.x,         4 ), /* Top */
		    FloatRect(        4, corOff.y, sideLen.x,         4 )  /* Bottom */
		};

		const FloatRect bgPos(4, 4, sideLen.x, sideLen.y);

		bool drawSidesLR = rect.h > 8;
		bool drawSidesTB = rect.w > 8;
		bool drawBg = drawSidesLR && drawSidesTB;

		size_t quads = 0;
		quads += 4; /* 4 corners */

		if (drawSidesLR)
			quads += 2;

		if (drawSidesTB)
			quads += 2;

		if (drawBg)
			quads += 1;

		cursorVert.resize(quads);
		Vertex *vert = dataPtr(cursorVert.vertices);
		size_t i = 0;

		i += Quad::setTexPosRect(&vert[i*4], src.corners.tl, cornerPos.tl);
		i += Quad::setTexPosRect(&vert[i*4], src.corners.tr, cornerPos.tr);
		i += Quad::setTexPosRect(&vert[i*4], src.corners.bl, cornerPos.bl);
		i += Quad::setTexPosRect(&vert[i*4], src.corners.br, cornerPos.br);

		if (drawSidesLR)
		{
			i += Quad::setTexPosRect(&vert[i*4], src.border.l, sidePos.l);
			i += Quad::setTexPosRect(&vert[i*4], src.border.r, sidePos.r);
		}

		if (drawSidesTB)
		{
			i += Quad::setTexPosRect(&vert[i*4], src.border.t, sidePos.t);
			i += Quad::setTexPosRect(&vert[i*4], src.border.b, sidePos.b);
		}

		if (drawBg)
			Quad::setTexPosRect(&vert[i*4], src.bg, bgPos);
	}
Esempio n. 30
0
void GraphicsContext::drawImageBuffer(ImageBuffer* image, ColorSpace styleColorSpace, const IntPoint& p, CompositeOperator op, BlendMode blendMode)
{
    if (!image)
        return;
    drawImageBuffer(image, styleColorSpace, FloatRect(IntRect(p, image->logicalSize())), FloatRect(FloatPoint(), FloatSize(image->logicalSize())), op, blendMode);
}