Ejemplo n.º 1
0
IntRect enclosingIntRect(const LayoutRect& rect) {
  IntPoint location = flooredIntPoint(rect.minXMinYCorner());
  IntPoint maxPoint = ceiledIntPoint(rect.maxXMaxYCorner());

  return IntRect(location, maxPoint - location);
}
// The bounds of the GraphicsLayer created for a compositing layer is the union of the bounds of all the descendant
// RenderLayers that are rendered by the composited RenderLayer.
IntRect RenderLayerCompositor::calculateCompositedBounds(const RenderLayer* layer, const RenderLayer* ancestorLayer)
{
    if (!layer->isSelfPaintingLayer())
        return IntRect();

    IntRect boundingBoxRect, unionBounds;
    boundingBoxRect = unionBounds = layer->localBoundingBox();
    
    if (layer->renderer()->hasOverflowClip() || layer->renderer()->hasMask()) {
        int ancestorRelX = 0, ancestorRelY = 0;
        layer->convertToLayerCoords(ancestorLayer, ancestorRelX, ancestorRelY);
        boundingBoxRect.move(ancestorRelX, ancestorRelY);
        return boundingBoxRect;
    }

    if (RenderLayer* reflection = layer->reflectionLayer()) {
        if (!reflection->isComposited()) {
            IntRect childUnionBounds = calculateCompositedBounds(reflection, layer);
            unionBounds.unite(childUnionBounds);
        }
    }
    
    ASSERT(layer->isStackingContext() || (!layer->m_posZOrderList || layer->m_posZOrderList->size() == 0));

    if (Vector<RenderLayer*>* negZOrderList = layer->negZOrderList()) {
        size_t listSize = negZOrderList->size();
        for (size_t i = 0; i < listSize; ++i) {
            RenderLayer* curLayer = negZOrderList->at(i);
            if (!curLayer->isComposited()) {
                IntRect childUnionBounds = calculateCompositedBounds(curLayer, layer);
                unionBounds.unite(childUnionBounds);
            }
        }
    }

    if (Vector<RenderLayer*>* posZOrderList = layer->posZOrderList()) {
        size_t listSize = posZOrderList->size();
        for (size_t i = 0; i < listSize; ++i) {
            RenderLayer* curLayer = posZOrderList->at(i);
            if (!curLayer->isComposited()) {
                IntRect childUnionBounds = calculateCompositedBounds(curLayer, layer);
                unionBounds.unite(childUnionBounds);
            }
        }
    }

    if (Vector<RenderLayer*>* normalFlowList = layer->normalFlowList()) {
        size_t listSize = normalFlowList->size();
        for (size_t i = 0; i < listSize; ++i) {
            RenderLayer* curLayer = normalFlowList->at(i);
            if (!curLayer->isComposited()) {
                IntRect curAbsBounds = calculateCompositedBounds(curLayer, layer);
                unionBounds.unite(curAbsBounds);
            }
        }
    }

    if (layer->paintsWithTransform(PaintBehaviorNormal)) {
        TransformationMatrix* affineTrans = layer->transform();
        boundingBoxRect = affineTrans->mapRect(boundingBoxRect);
        unionBounds = affineTrans->mapRect(unionBounds);
    }

    int ancestorRelX = 0, ancestorRelY = 0;
    layer->convertToLayerCoords(ancestorLayer, ancestorRelX, ancestorRelY);
    unionBounds.move(ancestorRelX, ancestorRelY);

    return unionBounds;
}
Ejemplo n.º 3
0
 IntRect scrollableAreaBoundingBox() const override { return IntRect(); }
Ejemplo n.º 4
0
bool RenderThemeApollo::paintMenuListButton(RenderObject * o, const RenderObject::PaintInfo& paintInfo, const IntRect& r) 
{
    paintInfo.context->save();

#if 0 // old "move-to" "line-to" code
    paintInfo.context->setStrokeThickness(1);
    paintInfo.context->setStrokeStyle(SolidStroke);
    
    IntRect bounds = IntRect(r.x() + o->style()->borderLeftWidth(),
                             r.y() + o->style()->borderTopWidth(),
                             r.width() - o->style()->borderLeftWidth() - o->style()->borderRightWidth(),
                             r.height() - o->style()->borderTopWidth() - o->style()->borderBottomWidth());

    float fontScale = o->style()->fontSize() / baseFontSize;
    float centerY = bounds.y() + bounds.height() / 2.0;
    float arrowHeight = baseArrowHeight * fontScale;
    float arrowWidth = baseArrowWidth * fontScale;
    float leftEdge = bounds.right() - arrowPaddingRight - arrowWidth;
    float spaceBetweenArrows = baseSpaceBetweenArrows * fontScale;

    Color buttonColor = o->style()->color();
    if ( o->node()->hovered() )
    {
        buttonColor = Color( 0xff, 0xb5, 0x31 );
    }
    paintInfo.context->setFillColor(buttonColor);
    paintInfo.context->setStrokeColor(buttonColor);

    FloatPoint arrow1[3];
    arrow1[0] = FloatPoint(leftEdge, centerY - spaceBetweenArrows / 2.0);
    arrow1[1] = FloatPoint(leftEdge + arrowWidth, centerY - spaceBetweenArrows / 2.0);
    arrow1[2] = FloatPoint(leftEdge + arrowWidth / 2.0, centerY - spaceBetweenArrows / 2.0 - arrowHeight);

    // Draw the top arrow
    paintInfo.context->drawConvexPolygon(3, arrow1, true);

    FloatPoint arrow2[3];
    arrow2[0] = FloatPoint(leftEdge, centerY + spaceBetweenArrows / 2.0);
    arrow2[1] = FloatPoint(leftEdge + arrowWidth, centerY + spaceBetweenArrows / 2.0);
    arrow2[2] = FloatPoint(leftEdge + arrowWidth / 2.0, centerY + spaceBetweenArrows / 2.0 + arrowHeight);

    // Draw the bottom arrow
    paintInfo.context->drawConvexPolygon(3, arrow2, true);

    Color leftSeparatorColor(0, 0, 0, 40);
    Color rightSeparatorColor(255, 255, 255, 40);
    int separatorSpace = 2;
    int leftEdgeOfSeparator = static_cast<int>(leftEdge - arrowPaddingLeft); // FIXME: Round?

    // Draw the separator to the left of the arrows
    paintInfo.context->setStrokeColor(leftSeparatorColor);
    paintInfo.context->drawLine(IntPoint(leftEdgeOfSeparator, bounds.y()),
                                IntPoint(leftEdgeOfSeparator, bounds.bottom()));

    paintInfo.context->setStrokeColor(rightSeparatorColor);
    paintInfo.context->drawLine(IntPoint(leftEdgeOfSeparator + separatorSpace, bounds.y()),
                                IntPoint(leftEdgeOfSeparator + separatorSpace, bounds.bottom()));

// Debug
//    paintInfo.context->fillRect( r, Color( 0xff, 0x00, 0xff ) );
#endif

    RefPtr<Image> image = Image::loadPlatformResource( "popupStates" );
    
    IntSize stateOffset( 0, 0 );
    if ( !isEnabled( o ) )
    {
        stateOffset = IntSize( 0, 66 ); 
    }
    else if ( isPressed( o ) )
    {
        stateOffset = IntSize( 0, 44 ); 
    }
    else if ( isHovered( o ) )
    {
        stateOffset = IntSize( 0, 22 ); 
    }
    IntSize focusOffset = IntSize( 0, 88 );
    const bool nodeIsFocused = isFocused( o );

    IntRect destRect( 0, 0, 0, 0 );
    IntRect srcRect( 0, 0, 0, 0 );
    IntRect focusRingSrcRect( 0, 0, 0, 0 );

    int leftSideCornerDestWidth        = 5;
    int rightSideCornerDestWidth    = 22;
    int cornerDestHeight            = 4;

    // top left
    srcRect = IntRect( 0, 0, 5, 4 );
    destRect = IntRect( r.x(), r.y(), leftSideCornerDestWidth, cornerDestHeight );
    focusRingSrcRect = getFocusRingSrcRect( srcRect, focusOffset );    
    srcRect.move( stateOffset );
    paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); 
    if ( nodeIsFocused ) 
        paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, focusRingSrcRect ); 

    // top right
    srcRect = IntRect( 22, 0, 22, 4 );
    destRect = IntRect( r.x() + (r.width() - rightSideCornerDestWidth), r.y(), rightSideCornerDestWidth, cornerDestHeight );
    focusRingSrcRect = getFocusRingSrcRect( srcRect, focusOffset );    
    srcRect.move( stateOffset );
    paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); 
    if ( nodeIsFocused ) 
        paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, focusRingSrcRect ); 

    // bottom left
    srcRect = IntRect( 0, 18, 5, 4 );
    destRect = IntRect( r.x(), r.y() + (r.height() - cornerDestHeight), leftSideCornerDestWidth, cornerDestHeight );
    focusRingSrcRect = getFocusRingSrcRect( srcRect, focusOffset );    
    srcRect.move( stateOffset );
    paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); 
    if ( nodeIsFocused ) 
        paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, focusRingSrcRect ); 

    // bottom right
    srcRect = IntRect( 22, 18, 22, 4 );
    destRect = IntRect( r.x() + (r.width() - rightSideCornerDestWidth), r.y() + (r.height() - cornerDestHeight), rightSideCornerDestWidth, cornerDestHeight );
    focusRingSrcRect = getFocusRingSrcRect( srcRect, focusOffset );    
    srcRect.move( stateOffset );
    paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); 
    if ( nodeIsFocused ) 
        paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, focusRingSrcRect ); 

    // top edge
    srcRect = IntRect( 6, 0, 14, 4 );
    destRect = IntRect( r.x() + leftSideCornerDestWidth, r.y(), (r.width() - (leftSideCornerDestWidth + rightSideCornerDestWidth)), cornerDestHeight );
    focusRingSrcRect = getFocusRingSrcRect( srcRect, focusOffset );    
    srcRect.move( stateOffset );
    paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); 
    if ( nodeIsFocused ) 
        paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, focusRingSrcRect ); 

    // bottom edge
    srcRect = IntRect( 6, 18, 14, 4 );
    destRect = IntRect( r.x() + leftSideCornerDestWidth, r.y() + (r.height() - cornerDestHeight), (r.width() - (leftSideCornerDestWidth + rightSideCornerDestWidth)), cornerDestHeight );
    focusRingSrcRect = getFocusRingSrcRect( srcRect, focusOffset );    
    srcRect.move( stateOffset );
    paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); 
    if ( nodeIsFocused ) 
        paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, focusRingSrcRect ); 

    // left edge
    srcRect = IntRect( 0, 6, 5, 11 );
    destRect = IntRect( r.x(), r.y() + cornerDestHeight , leftSideCornerDestWidth, (r.height() - (2 * cornerDestHeight)) );
    focusRingSrcRect = getFocusRingSrcRect( srcRect, focusOffset );    
    srcRect.move( stateOffset );
    paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); 
    if ( nodeIsFocused ) 
        paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, focusRingSrcRect ); 

    // right edge
    srcRect = IntRect( 22, 6, 22, 11 );
    focusRingSrcRect = getFocusRingSrcRect( srcRect, focusOffset );    
    destRect = IntRect( r.x() + (r.width() - rightSideCornerDestWidth), r.y() + cornerDestHeight , rightSideCornerDestWidth, (r.height() - (2 * cornerDestHeight)) );
    srcRect.move( stateOffset );
    paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); 
    if ( nodeIsFocused ) 
        paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, focusRingSrcRect ); 

    // center
    srcRect = IntRect( 6, 6, 11, 11 );
    destRect = IntRect( r.x() + leftSideCornerDestWidth, r.y() + cornerDestHeight , r.width() - (leftSideCornerDestWidth + rightSideCornerDestWidth), (r.height() - (2 * cornerDestHeight)) );
    srcRect.move( stateOffset );
    paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); 

    // down arrow
    srcRect = IntRect( 45, 5, 5, 12 );
    destRect = IntRect( r.x() + (r.width() - 13), r.y() + ((r.height() / 2) - ( 12/2 )), 5, 12 );
    srcRect.move( stateOffset );
    paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); 


    paintInfo.context->restore();
    return true; 
}
ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, Blob* blob, int sx, int sy, int sw, int sh, ExceptionState& exceptionState)
{
    if (!sw || !sh) {
        exceptionState.throwDOMException(IndexSizeError, String::format("The source %s provided is 0.", sw ? "height" : "width"));
        return ScriptPromise();
    }
    ImageBitmapLoader* loader = ImageBitmapFactories::ImageBitmapLoader::create(from(eventTarget), IntRect(sx, sy, sw, sh), scriptState);
    ScriptPromise promise = loader->promise();
    from(eventTarget).addLoader(loader);
    loader->loadBlobAsync(eventTarget.executionContext(), blob);
    return promise;
}
Ejemplo n.º 6
0
IntRect CoordinatedGraphicsLayer::tiledBackingStoreContentsRect()
{
    return IntRect(0, 0, size().width(), size().height());
}
Ejemplo n.º 7
0
IntRect Deserializer::ReadIntRect()
{
    int data[4];
    Read(data, sizeof data);
    return IntRect(data);
}
Ejemplo n.º 8
0
void GraphicsContext::drawImageBuffer(ImageBuffer* image, ColorSpace styleColorSpace, const IntPoint& dest, const IntRect& srcRect, CompositeOperator op)
{
    drawImageBuffer(image, styleColorSpace, IntRect(dest, srcRect.size()), srcRect, op);
}
Ejemplo n.º 9
0
IntRect GraphicsContext::clipBounds() const
{
    ASSERT_NOT_REACHED();
    return IntRect();
}
Ejemplo n.º 10
0
void GraphicsContext::drawImageBuffer(ImageBuffer* image, ColorSpace styleColorSpace, const IntPoint& p, CompositeOperator op)
{
    drawImageBuffer(image, styleColorSpace, p, IntRect(0, 0, -1, -1), op);
}
Ejemplo n.º 11
0
void GraphicsContext::drawImageBuffer(ImageBuffer* image, ColorSpace styleColorSpace, const IntRect& r, CompositeOperator op, bool useLowQualityScale)
{
    drawImageBuffer(image, styleColorSpace, r, IntRect(0, 0, -1, -1), op, useLowQualityScale);
}
Ejemplo n.º 12
0
void GraphicsContext::drawImage(Image* image, ColorSpace styleColorSpace, const IntPoint& dest, const IntRect& srcRect, CompositeOperator op, RespectImageOrientationEnum shouldRespectImageOrientation)
{
    drawImage(image, styleColorSpace, IntRect(dest, srcRect.size()), srcRect, op, shouldRespectImageOrientation);
}
Ejemplo n.º 13
0
void GraphicsContext::drawImage(Image* image, ColorSpace styleColorSpace, const IntRect& r, CompositeOperator op, RespectImageOrientationEnum shouldRespectImageOrientation, bool useLowQualityScale)
{
    drawImage(image, styleColorSpace, r, IntRect(0, 0, -1, -1), op, shouldRespectImageOrientation, useLowQualityScale);
}
Ejemplo n.º 14
0
void GraphicsContext::drawImage(Image* image, ColorSpace styleColorSpace, const IntPoint& p, CompositeOperator op, RespectImageOrientationEnum shouldRespectImageOrientation)
{
    drawImage(image, styleColorSpace, p, IntRect(0, 0, -1, -1), op, shouldRespectImageOrientation);
}
Ejemplo n.º 15
0
// Widgets are always placed on integer boundaries, so rounding the size is actually
// the desired behavior. This function is here because it's otherwise seldom what we
// want to do with a LayoutRect.
static inline IntRect roundedIntRect(const LayoutRect& rect)
{
    return IntRect(roundedIntPoint(rect.location()), roundedIntSize(rect.size()));
}
Ejemplo n.º 16
0
Archivo: Font.cpp Proyecto: Sonkun/SFML
IntRect Font::findGlyphRect(Page& page, unsigned int width, unsigned int height) const
{
    // Find the line that fits well the glyph
    Row* row = NULL;
    float bestRatio = 0;
    for (std::vector<Row>::iterator it = page.rows.begin(); it != page.rows.end() && !row; ++it)
    {
        float ratio = static_cast<float>(height) / it->height;

        // Ignore rows that are either too small or too high
        if ((ratio < 0.7f) || (ratio > 1.f))
            continue;

        // Check if there's enough horizontal space left in the row
        if (width > page.texture.getSize().x - it->width)
            continue;

        // Make sure that this new row is the best found so far
        if (ratio < bestRatio)
            continue;

        // The current row passed all the tests: we can select it
        row = &*it;
        bestRatio = ratio;
    }

    // If we didn't find a matching row, create a new one (10% taller than the glyph)
    if (!row)
    {
        int rowHeight = height + height / 10;
        while ((page.nextRow + rowHeight >= page.texture.getSize().y) || (width >= page.texture.getSize().x))
        {
            // Not enough space: resize the texture if possible
            unsigned int textureWidth  = page.texture.getSize().x;
            unsigned int textureHeight = page.texture.getSize().y;
            if ((textureWidth * 2 <= Texture::getMaximumSize()) && (textureHeight * 2 <= Texture::getMaximumSize()))
            {
                // Make the texture 2 times bigger
                Image newImage;
                newImage.create(textureWidth * 2, textureHeight * 2, Color(255, 255, 255, 0));
                newImage.copy(page.texture.copyToImage(), 0, 0);
                page.texture.loadFromImage(newImage);
            }
            else
            {
                // Oops, we've reached the maximum texture size...
                err() << "Failed to add a new character to the font: the maximum texture size has been reached" << std::endl;
                return IntRect(0, 0, 2, 2);
            }
        }

        // We can now create the new row
        page.rows.push_back(Row(page.nextRow, rowHeight));
        page.nextRow += rowHeight;
        row = &page.rows.back();
    }

    // Find the glyph's rectangle on the selected row
    IntRect rect(row->width, row->top, width, height);

    // Update the row informations
    row->width += width;

    return rect;
}
Ejemplo n.º 17
0
bool CoordinatedGraphicsLayer::imageBackingVisible()
{
    ASSERT(m_coordinatedImageBacking);
    return tiledBackingStoreVisibleRect().intersects(IntRect(contentsRect()));
}
Ejemplo n.º 18
0
IntRect ChromeClientBlackBerry::windowResizerRect() const
{
    notImplemented();
    return IntRect();
}
Ejemplo n.º 19
0
void CoordinatedTile::resize(const IntSize& newSize)
{
    m_rect = IntRect(m_rect.location(), newSize);
    m_dirtyRect = m_rect;
}
Ejemplo n.º 20
0
static inline IntRect
RoundOut(Rect r)
{
  r.RoundOut();
  return IntRect(r.x, r.y, r.width, r.height);
}
Ejemplo n.º 21
0
bool RenderThemeApollo::paintButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r)
{
    RefPtr<Image> image = Image::loadPlatformResource( "htmlButtonStates" );
    
    IntSize stateOffset( 0, 0 );
    if ( !isEnabled( o ) )
    {
        stateOffset = IntSize( 0, 66 ); 
    }
    else if ( isPressed( o ) )
    {
        stateOffset = IntSize( 0, 44 ); 
    }
    else if ( isHovered( o ) )
    {
        stateOffset = IntSize( 0, 22 ); 
    }
    IntSize focusOffset = IntSize( 0, 88 );
    const bool nodeIsFocused = isFocused( o );

    IntRect destRect( 0, 0, 0, 0 );
    IntRect srcRect( 0, 0, 0, 0 );
    IntRect focusRingSrcRect( 0, 0, 0, 0 );

    int cornerDestWidth        = 6;
    int cornerDestHeight    = 5;

    // top left
    srcRect = IntRect( 0, 0, 6, 5 );
    destRect = IntRect( r.x(), r.y(), cornerDestWidth, cornerDestHeight );
    focusRingSrcRect = getFocusRingSrcRect( srcRect, focusOffset );    
    srcRect.move( stateOffset );
    i.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); 
    if ( nodeIsFocused ) 
        i.context->drawImage( image.get(), DeviceColorSpace, destRect, focusRingSrcRect ); 

    // top right
    srcRect = IntRect( 18, 0, 6, 5 );
    destRect = IntRect( r.x() + (r.width() - cornerDestWidth), r.y(), cornerDestWidth, cornerDestHeight );
    focusRingSrcRect = getFocusRingSrcRect( srcRect, focusOffset );    
    srcRect.move( stateOffset );
    i.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); 
    if ( nodeIsFocused ) 
        i.context->drawImage( image.get(), DeviceColorSpace, destRect, focusRingSrcRect ); 

    // bottom left
    srcRect = IntRect( 0, 17, 6, 5 );
    destRect = IntRect( r.x(), r.y() + (r.height() - cornerDestHeight), cornerDestWidth, cornerDestHeight );
    focusRingSrcRect = getFocusRingSrcRect( srcRect, focusOffset );    
    srcRect.move( stateOffset );
    i.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); 
    if ( nodeIsFocused ) 
        i.context->drawImage( image.get(), DeviceColorSpace, destRect, focusRingSrcRect ); 

    // bottom right
    srcRect = IntRect( 18, 17, 6, 5 );
    destRect = IntRect( r.x() + (r.width() - cornerDestWidth), r.y() + (r.height() - cornerDestHeight), cornerDestWidth, cornerDestHeight );
    focusRingSrcRect = getFocusRingSrcRect( srcRect, focusOffset );    
    srcRect.move( stateOffset );
    i.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); 
    if ( nodeIsFocused ) 
        i.context->drawImage( image.get(), DeviceColorSpace, destRect, focusRingSrcRect ); 

    // top edge
    srcRect = IntRect( 7, 0, 8, 5 );
    destRect = IntRect( r.x() + cornerDestWidth, r.y(), (r.width() - (2 * cornerDestWidth)), cornerDestHeight );
    focusRingSrcRect = getFocusRingSrcRect( srcRect, focusOffset );    
    srcRect.move( stateOffset );
    i.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); 
    if ( nodeIsFocused ) 
        i.context->drawImage( image.get(), DeviceColorSpace, destRect, focusRingSrcRect ); 

    // bottom edge
    srcRect = IntRect( 7, 17, 8, 5 );
    destRect = IntRect( r.x() + cornerDestWidth, r.y() + (r.height() - cornerDestHeight), (r.width() - (2 * cornerDestWidth)), cornerDestHeight );
    focusRingSrcRect = getFocusRingSrcRect( srcRect, focusOffset );    
    srcRect.move( stateOffset );
    i.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); 
    if ( nodeIsFocused ) 
        i.context->drawImage( image.get(), DeviceColorSpace, destRect, focusRingSrcRect ); 


    // left edge
    srcRect = IntRect( 0, 6, 6, 8 );
    destRect = IntRect( r.x(), r.y() + cornerDestHeight, cornerDestWidth, (r.height() - (2 * cornerDestHeight)) );
    focusRingSrcRect = getFocusRingSrcRect( srcRect, focusOffset );    
    srcRect.move( stateOffset );
    i.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); 
    if ( nodeIsFocused ) 
        i.context->drawImage( image.get(), DeviceColorSpace, destRect, focusRingSrcRect ); 

    // right edge
    srcRect = IntRect( 18, 6, 6, 8 );
    destRect = IntRect( r.x() + (r.width() - cornerDestWidth), r.y() + cornerDestHeight , cornerDestWidth, (r.height() - (2 * cornerDestHeight)) );
    focusRingSrcRect = getFocusRingSrcRect( srcRect, focusOffset );    
    srcRect.move( stateOffset );
    i.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); 
    if ( nodeIsFocused ) 
        i.context->drawImage( image.get(), DeviceColorSpace, destRect, focusRingSrcRect ); 

    // center
    srcRect = IntRect( 7, 6, 8, 8 );
    destRect = IntRect( r.x() + cornerDestWidth, r.y() + cornerDestHeight , r.width() - (2 * cornerDestWidth), (r.height() - (2 * cornerDestHeight)) );
    srcRect.move( stateOffset );
    i.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); 

    return false;
}
Ejemplo n.º 22
0
void
BasicCompositor::BeginFrame(const nsIntRegion& aInvalidRegion,
                            const gfx::Rect *aClipRectIn,
                            const gfx::Rect& aRenderBounds,
                            gfx::Rect *aClipRectOut /* = nullptr */,
                            gfx::Rect *aRenderBoundsOut /* = nullptr */)
{
  mWidgetSize = mWidget->GetClientSize();
  IntRect intRect = gfx::IntRect(IntPoint(), mWidgetSize);
  Rect rect = Rect(0, 0, intRect.width, intRect.height);

  // Sometimes the invalid region is larger than we want to draw.
  nsIntRegion invalidRegionSafe;
  invalidRegionSafe.And(aInvalidRegion, intRect);

  IntRect invalidRect = invalidRegionSafe.GetBounds();
  mInvalidRect = IntRect(invalidRect.x, invalidRect.y, invalidRect.width, invalidRect.height);
  mInvalidRegion = invalidRegionSafe;

  if (aRenderBoundsOut) {
    *aRenderBoundsOut = Rect();
  }

  if (mInvalidRect.width <= 0 || mInvalidRect.height <= 0) {
    return;
  }

  if (mTarget) {
    // If we have a copy target, then we don't have a widget-provided mDrawTarget (currently). Use a dummy
    // placeholder so that CreateRenderTarget() works.
    mDrawTarget = gfxPlatform::GetPlatform()->ScreenReferenceDrawTarget();
  } else {
    mDrawTarget = mWidget->StartRemoteDrawingInRegion(mInvalidRegion);
  }
  if (!mDrawTarget) {
    return;
  }

  // Setup an intermediate render target to buffer all compositing. We will
  // copy this into mDrawTarget (the widget), and/or mTarget in EndFrame()
  RefPtr<CompositingRenderTarget> target = CreateRenderTarget(mInvalidRect, INIT_MODE_CLEAR);
  if (!target) {
    if (!mTarget) {
      mWidget->EndRemoteDrawingInRegion(mDrawTarget, mInvalidRegion);
    }
    return;
  }
  SetRenderTarget(target);

  // We only allocate a surface sized to the invalidated region, so we need to
  // translate future coordinates.
  mRenderTarget->mDrawTarget->SetTransform(Matrix::Translation(-invalidRect.x,
                                                               -invalidRect.y));

  gfxUtils::ClipToRegion(mRenderTarget->mDrawTarget, invalidRegionSafe);

  if (aRenderBoundsOut) {
    *aRenderBoundsOut = rect;
  }

  if (aClipRectIn) {
    mRenderTarget->mDrawTarget->PushClipRect(*aClipRectIn);
  } else {
    mRenderTarget->mDrawTarget->PushClipRect(rect);
    if (aClipRectOut) {
      *aClipRectOut = rect;
    }
  }
}
Ejemplo n.º 23
0
ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, Blob* blob, ExceptionState& exceptionState)
{
    ImageBitmapLoader* loader = ImageBitmapFactories::ImageBitmapLoader::create(from(eventTarget), IntRect(), scriptState);
    ScriptPromise promise = loader->promise();
    from(eventTarget).addLoader(loader);
    loader->loadBlobAsync(eventTarget.executionContext(), blob);
    return promise;
}
void Sprite::SetFullImageRect()
{
    if (texture_)
        SetImageRect(IntRect(0, 0, texture_->GetWidth(), texture_->GetHeight()));
}
Ejemplo n.º 25
0
void ChromeClientImpl::setWindowRect(const FloatRect& r)
{
    if (m_webView->client())
        m_webView->client()->setWindowRect(IntRect(r));
}
Ejemplo n.º 26
0
void Light::SetupShadowViews(Camera* mainCamera, Vector<AutoPtr<ShadowView> >& shadowViews, size_t& useIndex)
{
    size_t numViews = NumShadowViews();
    if (!numViews)
        return;

    if (shadowViews.Size() < useIndex + numViews)
        shadowViews.Resize(useIndex + numViews);

    int numVerticalSplits = (lightType == LIGHT_POINT || (lightType == LIGHT_DIRECTIONAL && NumShadowSplits() > 2)) ? 2 : 1;
    int actualShadowMapSize = shadowRect.Height() / numVerticalSplits;

    for (size_t i = 0; i < numViews; ++i)
    {
        if (!shadowViews[useIndex + i])
            shadowViews[useIndex + i] = new ShadowView();

        ShadowView* view = shadowViews[useIndex + i].Get();
        view->Clear();
        view->light = this;
        Camera& shadowCamera = view->shadowCamera;

        switch (lightType)
        {
        case LIGHT_DIRECTIONAL:
            {
                IntVector2 topLeft(shadowRect.left, shadowRect.top);
                if (i & 1)
                    topLeft.x += actualShadowMapSize;
                if (i & 2)
                    topLeft.y += actualShadowMapSize;
                view->viewport = IntRect(topLeft.x, topLeft.y, topLeft.x + actualShadowMapSize, topLeft.y + actualShadowMapSize);

                float splitStart = Max(mainCamera->NearClip(), (i == 0) ? 0.0f : ShadowSplit(i - 1));
                float splitEnd = Min(mainCamera->FarClip(), ShadowSplit(i));
                float extrusionDistance = mainCamera->FarClip();
                
                // Calculate initial position & rotation
                shadowCamera.SetTransform(mainCamera->WorldPosition() - extrusionDistance * WorldDirection(), WorldRotation());

                // Calculate main camera shadowed frustum in light's view space
                Frustum splitFrustum = mainCamera->WorldSplitFrustum(splitStart, splitEnd);
                const Matrix3x4& lightView = shadowCamera.ViewMatrix();
                Frustum lightViewFrustum = splitFrustum.Transformed(lightView);

                // Fit the frustum inside a bounding box
                BoundingBox shadowBox;
                shadowBox.Define(lightViewFrustum);

                // If shadow camera is far away from the frustum, can bring it closer for better depth precision
                /// \todo The minimum distance is somewhat arbitrary
                float minDistance = mainCamera->FarClip() * 0.25f;
                if (shadowBox.min.z > minDistance)
                {
                    float move = shadowBox.min.z - minDistance;
                    shadowCamera.Translate(Vector3(0.0f, 0.f, move));
                    shadowBox.min.z -= move,
                    shadowBox.max.z -= move;
                }

                shadowCamera.SetOrthographic(true);
                shadowCamera.SetFarClip(shadowBox.max.z);

                Vector3 center = shadowBox.Center();
                Vector3 size = shadowBox.Size();
                shadowCamera.SetOrthoSize(Vector2(size.x, size.y));
                shadowCamera.SetZoom(1.0f);

                // Center shadow camera to the view space bounding box
                Vector3 pos(shadowCamera.WorldPosition());
                Quaternion rot(shadowCamera.WorldRotation());
                Vector3 adjust(center.x, center.y, 0.0f);
                shadowCamera.Translate(rot * adjust, TS_WORLD);

                // Snap to whole texels
                {
                    Vector3 viewPos(rot.Inverse() * shadowCamera.WorldPosition());
                    float invSize = 1.0f / actualShadowMapSize;
                    Vector2 texelSize(size.x * invSize, size.y * invSize);
                    Vector3 snap(-fmodf(viewPos.x, texelSize.x), -fmodf(viewPos.y, texelSize.y), 0.0f);
                    shadowCamera.Translate(rot * snap, TS_WORLD);
                }
            }
            break;

        case LIGHT_POINT:
            {
                static const Quaternion pointLightFaceRotations[] = {
                    Quaternion(0.0f, 90.0f, 0.0f),
                    Quaternion(0.0f, -90.0f, 0.0f),
                    Quaternion(-90.0f, 0.0f, 0.0f),
                    Quaternion(90.0f, 0.0f, 0.0f),
                    Quaternion(0.0f, 0.0f, 0.0f),
                    Quaternion(0.0f, 180.0f, 0.0f)
                };

                IntVector2 topLeft(shadowRect.left, shadowRect.top);
                if (i & 1)
                    topLeft.y += actualShadowMapSize;
                topLeft.x += ((unsigned)i >> 1) * actualShadowMapSize;
                view->viewport = IntRect(topLeft.x, topLeft.y, topLeft.x + actualShadowMapSize, topLeft.y + actualShadowMapSize);

                shadowCamera.SetTransform(WorldPosition(), pointLightFaceRotations[i]);
                shadowCamera.SetFov(90.0f);
                // Adjust zoom to avoid edge sampling artifacts (there is a matching adjustment in the shadow sampling)
                shadowCamera.SetZoom(0.99f);
                shadowCamera.SetFarClip(Range());
                shadowCamera.SetNearClip(Range() * 0.01f);
                shadowCamera.SetOrthographic(false);
                shadowCamera.SetAspectRatio(1.0f);
            }
            break;

        case LIGHT_SPOT:
            view->viewport = shadowRect;
            shadowCamera.SetTransform(WorldPosition(), WorldRotation());
            shadowCamera.SetFov(fov);
            shadowCamera.SetZoom(1.0f);
            shadowCamera.SetFarClip(Range());
            shadowCamera.SetNearClip(Range() * 0.01f);
            shadowCamera.SetOrthographic(false);
            shadowCamera.SetAspectRatio(1.0f);
            break;
        }
    }

    // Setup shadow matrices now as camera positions have been finalized
    if (lightType != LIGHT_POINT)
    {
        shadowMatrices.Resize(numViews);
        
        for (size_t i = 0; i < numViews; ++i)
        {
            ShadowView* view = shadowViews[useIndex + i].Get();

            Camera& shadowCamera = view->shadowCamera;
            float width = (float)shadowMap->Width();
            float height = (float)shadowMap->Height();
            Vector3 offset((float)view->viewport.left / width, (float)view->viewport.top / height, 0.0f);
            Vector3 scale(0.5f * (float)view->viewport.Width() / width, 0.5f * (float)view->viewport.Height() / height, 1.0f);

            offset.x += scale.x;
            offset.y += scale.y;
            scale.y = -scale.y;

            // OpenGL has different depth range
            #ifdef TURSO3D_OPENGL
            offset.z = 0.5f;
            scale.z = 0.5f;
            #endif
            
            Matrix4 texAdjust(Matrix4::IDENTITY);
            texAdjust.SetTranslation(offset);
            texAdjust.SetScale(scale);

            shadowMatrices[i] = texAdjust * shadowCamera.ProjectionMatrix() * shadowCamera.ViewMatrix();
        }
    }
    else
    {
        // Point lights use an extra constant instead
        shadowMatrices.Clear();

        Vector2 textureSize((float)shadowMap->Width(), (float)shadowMap->Height());
        pointShadowParameters = Vector4(actualShadowMapSize / textureSize.x, actualShadowMapSize / textureSize.y,
            (float)shadowRect.left / textureSize.x, (float)shadowRect.top / textureSize.y);
    }

    // Calculate shadow mapping constants
    Camera& shadowCamera = shadowViews[useIndex]->shadowCamera;
    float nearClip = shadowCamera.NearClip();
    float farClip = shadowCamera.FarClip();
    float q = farClip / (farClip - nearClip);
    float r = -q * nearClip;
    shadowParameters = Vector4(0.5f / (float)shadowMap->Width(), 0.5f / (float)shadowMap->Height(), q, r);
    
    useIndex += numViews;
}
Ejemplo n.º 27
0
 IntRect scrollCornerRect() const override { return IntRect(); }
void FEComposite::platformApplySoftware()
{
    FilterEffect* in = inputEffect(0);
    FilterEffect* in2 = inputEffect(1);

    if (m_type == FECOMPOSITE_OPERATOR_ARITHMETIC) {
        Uint8ClampedArray* dstPixelArray = createPremultipliedImageResult();
        if (!dstPixelArray)
            return;

        IntRect effectADrawingRect = requestedRegionOfInputImageData(in->absolutePaintRect());
        RefPtr<Uint8ClampedArray> srcPixelArray = in->asPremultipliedImage(effectADrawingRect);

        IntRect effectBDrawingRect = requestedRegionOfInputImageData(in2->absolutePaintRect());
        in2->copyPremultipliedImage(dstPixelArray, effectBDrawingRect);

        platformArithmeticSoftware(srcPixelArray.get(), dstPixelArray, m_k1, m_k2, m_k3, m_k4);
        return;
    }

    ImageBuffer* resultImage = createImageBufferResult();
    if (!resultImage)
        return;
    GraphicsContext* filterContext = resultImage->context();

    ImageBuffer* imageBuffer = in->asImageBuffer();
    ImageBuffer* imageBuffer2 = in2->asImageBuffer();
    ASSERT(imageBuffer);
    ASSERT(imageBuffer2);

    switch (m_type) {
    case FECOMPOSITE_OPERATOR_OVER:
        filterContext->drawImageBuffer(imageBuffer2, ColorSpaceDeviceRGB, drawingRegionOfInputImage(in2->absolutePaintRect()));
        filterContext->drawImageBuffer(imageBuffer, ColorSpaceDeviceRGB, drawingRegionOfInputImage(in->absolutePaintRect()));
        break;
    case FECOMPOSITE_OPERATOR_IN: {
        // Applies only to the intersected region.
        IntRect destinationRect = in->absolutePaintRect();
        destinationRect.intersect(in2->absolutePaintRect());
        destinationRect.intersect(absolutePaintRect());
        if (destinationRect.isEmpty())
            break;
        IntPoint destinationPoint(destinationRect.x() - absolutePaintRect().x(), destinationRect.y() - absolutePaintRect().y());
        IntRect sourceRect(IntPoint(destinationRect.x() - in->absolutePaintRect().x(),
                                    destinationRect.y() - in->absolutePaintRect().y()), destinationRect.size());
        IntRect source2Rect(IntPoint(destinationRect.x() - in2->absolutePaintRect().x(),
                                     destinationRect.y() - in2->absolutePaintRect().y()), destinationRect.size());
        filterContext->drawImageBuffer(imageBuffer2, ColorSpaceDeviceRGB, destinationPoint, source2Rect);
        filterContext->drawImageBuffer(imageBuffer, ColorSpaceDeviceRGB, destinationPoint, sourceRect, CompositeSourceIn);
        break;
    }
    case FECOMPOSITE_OPERATOR_OUT:
        filterContext->drawImageBuffer(imageBuffer, ColorSpaceDeviceRGB, drawingRegionOfInputImage(in->absolutePaintRect()));
        filterContext->drawImageBuffer(imageBuffer2, ColorSpaceDeviceRGB, drawingRegionOfInputImage(in2->absolutePaintRect()), IntRect(IntPoint(), imageBuffer2->logicalSize()), CompositeDestinationOut);
        break;
    case FECOMPOSITE_OPERATOR_ATOP:
        filterContext->drawImageBuffer(imageBuffer2, ColorSpaceDeviceRGB, drawingRegionOfInputImage(in2->absolutePaintRect()));
        filterContext->drawImageBuffer(imageBuffer, ColorSpaceDeviceRGB, drawingRegionOfInputImage(in->absolutePaintRect()), IntRect(IntPoint(), imageBuffer->logicalSize()), CompositeSourceAtop);
        break;
    case FECOMPOSITE_OPERATOR_XOR:
        filterContext->drawImageBuffer(imageBuffer2, ColorSpaceDeviceRGB, drawingRegionOfInputImage(in2->absolutePaintRect()));
        filterContext->drawImageBuffer(imageBuffer, ColorSpaceDeviceRGB, drawingRegionOfInputImage(in->absolutePaintRect()), IntRect(IntPoint(), imageBuffer->logicalSize()), CompositeXOR);
        break;
    default:
        break;
    }
}
ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, HTMLCanvasElement* canvas, int sx, int sy, int sw, int sh, ExceptionState& exceptionState)
{
    // This variant does not work in worker threads.
    ASSERT(eventTarget.toDOMWindow());

    if (!canvas->originClean()) {
        exceptionState.throwSecurityError("The canvas element provided is tainted with cross-origin data.");
        return ScriptPromise();
    }
    if (!sw || !sh) {
        exceptionState.throwDOMException(IndexSizeError, String::format("The source %s provided is 0.", sw ? "height" : "width"));
        return ScriptPromise();
    }

    // FIXME: make ImageBitmap creation asynchronous crbug.com/258082
    return fulfillImageBitmap(scriptState, canvas->isPaintable() ? ImageBitmap::create(canvas, IntRect(sx, sy, sw, sh)) : nullptr);
}
Ejemplo n.º 30
0
IntRect PageClientImpl::windowToScreen(const IntRect& rect)
{
    return IntRect(convertWidgetPointToScreenPoint(m_viewWidget, rect.location()), rect.size());
}