bool RenderThemeAndroid::paintButton(RenderObject* obj, const PaintInfo& info, const IntRect& rect) { // If it is a disabled button, simply paint it to the master picture. Node* node = obj->node(); Element* formControlElement = static_cast<Element*>(node); if (formControlElement) { android::WebFrame* webFrame = getWebFrame(node); if (webFrame) { GraphicsContext *context = info.context; IntRect innerrect = IntRect(rect.x() + paddingButton, rect.y() + paddingButton, rect.width() - 2 * paddingButton, rect.height() - 2 * paddingButton); IntSize cornerrect = IntSize(cornerButton, cornerButton); Color bg, bright, dark, medium; if (formControlElement->isEnabledFormControl()) { bg = Color(defaultBgColor); bright = Color(defaultBgBright); dark = Color(defaultBgDark); medium = Color(defaultBgMedium); } else { bg = Color(disabledBgColor); bright = Color(disabledBgBright); dark = Color(disabledBgDark); medium = Color(disabledBgMedium); } context->save(); context->clip( IntRect(innerrect.x(), innerrect.y(), innerrect.width(), 1)); context->fillRoundedRect(innerrect, cornerrect, cornerrect, cornerrect, cornerrect, bright, context->fillColorSpace()); context->restore(); context->save(); context->clip(IntRect(innerrect.x(), innerrect.y() + innerrect.height() - 1, innerrect.width(), 1)); context->fillRoundedRect(innerrect, cornerrect, cornerrect, cornerrect, cornerrect, dark, context->fillColorSpace()); context->restore(); context->save(); context->clip(IntRect(innerrect.x(), innerrect.y() + 1, innerrect.width(), innerrect.height() - 2)); context->fillRoundedRect(innerrect, cornerrect, cornerrect, cornerrect, cornerrect, bg, context->fillColorSpace()); context->restore(); context->setStrokeColor(medium, context->strokeColorSpace()); context->setStrokeThickness(1.0f); context->drawLine(IntPoint(innerrect.x(), innerrect.y() + cornerButton), IntPoint(innerrect.x(), innerrect.y() + innerrect.height() - cornerButton)); context->drawLine(IntPoint(innerrect.x() + innerrect.width(), innerrect.y() + cornerButton), IntPoint(innerrect.x() + innerrect.width(), innerrect.y() + innerrect.height() - cornerButton)); } } // We always return false so we do not request to be redrawn. return false; }
void RenderEmbeddedObject::paintReplaced(const PaintInfo& paintInfo, const LayoutPoint& paintOffset) { if (!showsUnavailablePluginIndicator()) return; if (paintInfo.phase == PaintPhaseSelection) return; FloatRect contentRect; Path path; FloatRect replacementTextRect; Font font; TextRun run(""); float textWidth; if (!getReplacementTextGeometry(paintOffset, contentRect, path, replacementTextRect, font, run, textWidth)) return; GraphicsContext* context = paintInfo.context; GraphicsContextStateSaver stateSaver(*context); context->clip(contentRect); context->setAlphaAsFloat(replacementTextRoundedRectOpacity); context->setFillColor(Color::white); context->fillPath(path); const FontMetrics& fontMetrics = font.fontMetrics(); float labelX = roundf(replacementTextRect.location().x() + (replacementTextRect.size().width() - textWidth) / 2); float labelY = roundf(replacementTextRect.location().y() + (replacementTextRect.size().height() - fontMetrics.height()) / 2 + fontMetrics.ascent()); TextRunPaintInfo runInfo(run); runInfo.bounds = replacementTextRect; context->setAlphaAsFloat(replacementTextTextOpacity); context->setFillColor(Color::black); context->drawBidiText(font, runInfo, FloatPoint(labelX, labelY)); }
ImageBitmap::ImageBitmap(HTMLVideoElement* video, const IntRect& cropRect) : m_imageElement(nullptr) , m_cropRect(cropRect) , m_bitmapOffset(IntPoint()) { IntSize playerSize; if (video->webMediaPlayer()) playerSize = video->webMediaPlayer()->naturalSize(); IntRect videoRect = IntRect(IntPoint(), playerSize); IntRect srcRect = intersection(cropRect, videoRect); IntRect dstRect(IntPoint(), srcRect.size()); OwnPtr<ImageBuffer> buf = ImageBuffer::create(videoRect.size()); if (!buf) return; GraphicsContext* c = buf->context(); c->clip(dstRect); c->translate(-srcRect.x(), -srcRect.y()); video->paintCurrentFrameInContext(c, videoRect); m_bitmap = buf->copyImage(DontCopyBackingStore); m_bitmapRect = IntRect(IntPoint(std::max(0, -cropRect.x()), std::max(0, -cropRect.y())), srcRect.size()); ScriptWrappable::init(this); }
void FindIndicator::draw(GraphicsContext& graphicsContext, const IntRect& dirtyRect) { for (size_t i = 0; i < m_textRects.size(); ++i) { FloatRect textRect = m_textRects[i]; textRect.move(leftBorderThickness, topBorderThickness); graphicsContext.save(); FloatRect outerPathRect = inflateRect(textRect, horizontalOutsetToCenterOfLightBorder, verticalOutsetToCenterOfLightBorder); graphicsContext.setShadow(FloatSize(shadowOffsetX, shadowOffsetY), shadowBlurRadius, shadowColor(), ColorSpaceSRGB); graphicsContext.addPath(pathWithRoundedRect(outerPathRect, cornerRadius)); graphicsContext.setFillColor(lightBorderColor(), ColorSpaceDeviceRGB); graphicsContext.fillPath(); graphicsContext.restore(); graphicsContext.save(); FloatRect innerPathRect = inflateRect(textRect, horizontalPaddingInsideLightBorder, verticalPaddingInsideLightBorder); graphicsContext.clip(pathWithRoundedRect(innerPathRect, cornerRadius)); RefPtr<Gradient> gradient = Gradient::create(FloatPoint(innerPathRect.x(), innerPathRect.y()), FloatPoint(innerPathRect.x(), innerPathRect.bottom())); gradient->addColorStop(0, gradientLightColor()); gradient->addColorStop(1, gradientDarkColor()); graphicsContext.setFillGradient(gradient); graphicsContext.fillRect(outerPathRect); graphicsContext.restore(); graphicsContext.save(); graphicsContext.translate(FloatSize(roundf(leftBorderThickness), roundf(topBorderThickness) + m_contentImage->bounds().height())); graphicsContext.scale(FloatSize(1, -1)); m_contentImage->paint(&graphicsContext, m_contentImage->bounds()); graphicsContext.restore(); } }
void RenderEmbeddedObject::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOffset) { if (!pluginCrashedOrWasMissing()) return; if (paintInfo.phase == PaintPhaseSelection) return; GraphicsContext* context = paintInfo.context; if (context->paintingDisabled()) return; FloatRect contentRect; Path path; FloatRect replacementTextRect; Font font; TextRun run(""); float textWidth; if (!getReplacementTextGeometry(paintOffset, contentRect, path, replacementTextRect, font, run, textWidth)) return; GraphicsContextStateSaver stateSaver(*context); context->clip(contentRect); context->setAlpha(m_missingPluginIndicatorIsPressed ? replacementTextPressedRoundedRectOpacity : replacementTextRoundedRectOpacity); context->setFillColor(m_missingPluginIndicatorIsPressed ? replacementTextRoundedRectPressedColor() : Color::white, style()->colorSpace()); context->fillPath(path); const FontMetrics& fontMetrics = font.fontMetrics(); float labelX = roundf(replacementTextRect.location().x() + (replacementTextRect.size().width() - textWidth) / 2); float labelY = roundf(replacementTextRect.location().y() + (replacementTextRect.size().height() - fontMetrics.height()) / 2 + fontMetrics.ascent()); context->setAlpha(m_missingPluginIndicatorIsPressed ? replacementTextPressedTextOpacity : replacementTextTextOpacity); context->setFillColor(Color::black, style()->colorSpace()); context->drawBidiText(font, run, FloatPoint(labelX, labelY)); }
void HTMLCanvasPainter::paintReplaced(const PaintInfo& paintInfo, const LayoutPoint& paintOffset) { GraphicsContext* context = paintInfo.context; LayoutRect contentRect = m_renderHTMLCanvas.contentBoxRect(); contentRect.moveBy(paintOffset); LayoutRect paintRect = m_renderHTMLCanvas.replacedContentRect(); paintRect.moveBy(paintOffset); bool clip = !contentRect.contains(paintRect); if (clip) { context->save(); context->clip(contentRect); } // FIXME: InterpolationNone should be used if ImageRenderingOptimizeContrast is set. // See bug for more details: crbug.com/353716. InterpolationQuality interpolationQuality = m_renderHTMLCanvas.style()->imageRendering() == ImageRenderingOptimizeContrast ? InterpolationLow : CanvasDefaultInterpolationQuality; if (m_renderHTMLCanvas.style()->imageRendering() == ImageRenderingPixelated) interpolationQuality = InterpolationNone; InterpolationQuality previousInterpolationQuality = context->imageInterpolationQuality(); context->setImageInterpolationQuality(interpolationQuality); toHTMLCanvasElement(m_renderHTMLCanvas.node())->paint(context, paintRect); context->setImageInterpolationQuality(previousInterpolationQuality); if (clip) context->restore(); }
void AcceleratedCompositingContext::paintContents(const GraphicsLayer*, GraphicsContext& context, GraphicsLayerPaintingPhase, const FloatRect& rectToPaint) { context.save(); context.clip(rectToPaint); core(&m_webView)->mainFrame().view()->paint(&context, enclosingIntRect(rectToPaint)); context.restore(); }
void WebPage::drawRect(GraphicsContext& graphicsContext, const IntRect& rect) { graphicsContext.save(); graphicsContext.clip(rect); m_mainFrame->coreFrame()->view()->paint(&graphicsContext, rect); graphicsContext.restore(); }
void RenderVideo::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOffset) { MediaPlayer* mediaPlayer = mediaElement()->player(); bool displayingPoster = videoElement()->shouldDisplayPosterImage(); if (!displayingPoster && !mediaPlayer) return; LayoutRect rect = videoBox(); if (rect.isEmpty()) return; rect.moveBy(paintOffset); LayoutRect contentRect = contentBoxRect(); contentRect.moveBy(paintOffset); GraphicsContext* context = paintInfo.context; bool clip = !contentRect.contains(rect); if (clip) { context->save(); context->clip(contentRect); } if (displayingPoster) paintIntoRect(context, rect); else if ((document().view() && document().view()->paintBehavior() & PaintBehaviorFlattenCompositingLayers) || !acceleratedRenderingInUse()) mediaPlayer->paint(context, pixelSnappedIntRect(rect)); if (clip) context->restore(); }
void FindIndicator::draw(GraphicsContext& graphicsContext, const IntRect& /*dirtyRect*/) { #if ENABLE(LEGACY_FIND_INDICATOR_STYLE) for (size_t i = 0; i < m_textRectsInSelectionRectCoordinates.size(); ++i) { FloatRect textRect = m_textRectsInSelectionRectCoordinates[i]; textRect.move(leftBorderThickness, topBorderThickness); FloatRect outerPathRect = inflateRect(textRect, horizontalOutsetToCenterOfLightBorder, verticalOutsetToCenterOfLightBorder); FloatRect innerPathRect = inflateRect(textRect, horizontalPaddingInsideLightBorder, verticalPaddingInsideLightBorder); { GraphicsContextStateSaver stateSaver(graphicsContext); graphicsContext.setShadow(FloatSize(shadowOffsetX, shadowOffsetY), shadowBlurRadius, shadowColor(), ColorSpaceSRGB); graphicsContext.setFillColor(lightBorderColor(), ColorSpaceDeviceRGB); graphicsContext.fillPath(pathWithRoundedRect(outerPathRect, cornerRadius)); } { GraphicsContextStateSaver stateSaver(graphicsContext); graphicsContext.clip(pathWithRoundedRect(innerPathRect, cornerRadius)); RefPtr<Gradient> gradient = Gradient::create(FloatPoint(innerPathRect.x(), innerPathRect.y()), FloatPoint(innerPathRect.x(), innerPathRect.maxY())); gradient->addColorStop(0, gradientLightColor()); gradient->addColorStop(1, gradientDarkColor()); graphicsContext.setFillGradient(gradient.releaseNonNull()); graphicsContext.fillRect(outerPathRect); } { GraphicsContextStateSaver stateSaver(graphicsContext); graphicsContext.translate(FloatSize(roundf(leftBorderThickness), roundf(topBorderThickness))); IntRect contentImageRect = enclosingIntRect(m_textRectsInSelectionRectCoordinates[i]); m_contentImage->paint(graphicsContext, m_contentImageScaleFactor, contentImageRect.location(), contentImageRect); } } #else for (auto& textRect : m_textRectsInSelectionRectCoordinates) { FloatRect blurRect = textRect; blurRect.move(flatShadowBlurRadius + flatStyleHorizontalBorder, flatShadowBlurRadius + flatStyleVerticalBorder); FloatRect outerPathRect = inflateRect(blurRect, flatStyleHorizontalBorder, flatStyleVerticalBorder); { GraphicsContextStateSaver stateSaver(graphicsContext); graphicsContext.setShadow(FloatSize(), flatRimShadowBlurRadius, flatRimShadowColor(), ColorSpaceSRGB); graphicsContext.setFillColor(flatHighlightColor(), ColorSpaceSRGB); graphicsContext.fillRect(outerPathRect); graphicsContext.setShadow(FloatSize(flatShadowOffsetX, flatShadowOffsetY), flatShadowBlurRadius, flatDropShadowColor(), ColorSpaceSRGB); graphicsContext.fillRect(outerPathRect); } { GraphicsContextStateSaver stateSaver(graphicsContext); graphicsContext.translate(FloatSize(flatShadowBlurRadius + flatStyleHorizontalBorder, flatShadowBlurRadius + flatStyleVerticalBorder)); IntRect contentImageRect = enclosingIntRect(textRect); m_contentImage->paint(graphicsContext, m_contentImageScaleFactor, contentImageRect.location(), contentImageRect); } } #endif }
void TextureMapperImageBuffer::beginClip(const TransformationMatrix& matrix, const FloatRect& rect) { GraphicsContext* context = currentContext(); if (!context) return; #if ENABLE(3D_RENDERING) TransformationMatrix previousTransform = context->get3DTransform(); #else AffineTransform previousTransform = context->getCTM(); #endif context->save(); #if ENABLE(3D_RENDERING) context->concat3DTransform(matrix); #else context->concatCTM(matrix.toAffineTransform()); #endif context->clip(rect); #if ENABLE(3D_RENDERING) context->set3DTransform(previousTransform); #else context->setCTM(previousTransform); #endif }
GraphicsContext* FilterEffectRendererHelper::beginFilterEffect(GraphicsContext* oldContext) { ASSERT(m_renderLayer); FilterEffectRenderer* filter = m_renderLayer->filterRenderer(); filter->allocateBackingStoreIfNeeded(); // Paint into the context that represents the SourceGraphic of the filter. GraphicsContext* sourceGraphicsContext = filter->inputContext(); if (!sourceGraphicsContext || !FilterEffect::isFilterSizeValid(filter->absoluteFilterRegion())) { // Disable the filters and continue. m_haveFilterEffect = false; return oldContext; } m_savedGraphicsContext = oldContext; // Translate the context so that the contents of the layer is captuterd in the offscreen memory buffer. sourceGraphicsContext->save(); // FIXME: can we just use sourceImageRect for everything, and get rid of // m_repaintRect? FloatPoint offset = filter->sourceImageRect().location(); sourceGraphicsContext->translate(-offset.x(), -offset.y()); sourceGraphicsContext->clearRect(m_repaintRect); sourceGraphicsContext->clip(m_repaintRect); return sourceGraphicsContext; }
void CanvasRenderingContext2D::clip() { GraphicsContext* c = drawingContext(); if (!c) return; c->clip(state().m_path); clearPathForDashboardBackwardCompatibilityMode(); }
void PrintContext::spoolRect(GraphicsContext& ctx, const IntRect& rect) { // FIXME: Not correct for vertical text. ctx.save(); ctx.translate(-rect.x(), -rect.y()); ctx.clip(rect); m_frame->view()->paintContents(&ctx, rect); ctx.restore(); }
GraphicsContext* ThreadSafeCoordinatedSurface::beginPaint(const IntRect& rect) { ASSERT(m_imageBuffer); GraphicsContext* graphicsContext = m_imageBuffer->context(); graphicsContext->save(); graphicsContext->clip(rect); graphicsContext->translate(rect.x(), rect.y()); return graphicsContext; }
void RenderEmbeddedObject::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOffset) { if (!showsUnavailablePluginIndicator()) return; if (paintInfo.phase == PaintPhaseSelection) return; GraphicsContext* context = paintInfo.context; if (context->paintingDisabled()) return; FloatRect contentRect; FloatRect indicatorRect; FloatRect replacementTextRect; FloatRect arrowRect; FontCascade font; TextRun run(""); float textWidth; if (!getReplacementTextGeometry(paintOffset, contentRect, indicatorRect, replacementTextRect, arrowRect, font, run, textWidth)) return; Path background; background.addRoundedRect(indicatorRect, FloatSize(replacementTextRoundedRectRadius, replacementTextRoundedRectRadius)); GraphicsContextStateSaver stateSaver(*context); context->clip(contentRect); context->setFillColor(m_unavailablePluginIndicatorIsPressed ? replacementTextRoundedRectPressedColor() : replacementTextRoundedRectColor(), style().colorSpace()); context->fillPath(background); Path strokePath; FloatRect strokeRect(indicatorRect); strokeRect.inflate(1); strokePath.addRoundedRect(strokeRect, FloatSize(replacementTextRoundedRectRadius + 1, replacementTextRoundedRectRadius + 1)); context->setStrokeColor(unavailablePluginBorderColor(), style().colorSpace()); context->setStrokeThickness(2); context->strokePath(strokePath); const FontMetrics& fontMetrics = font.fontMetrics(); float labelX = roundf(replacementTextRect.location().x() + replacementTextRoundedRectLeftTextMargin); float labelY = roundf(replacementTextRect.location().y() + (replacementTextRect.size().height() - fontMetrics.height()) / 2 + fontMetrics.ascent() + replacementTextRoundedRectTopTextMargin); context->setFillColor(replacementTextColor(), style().colorSpace()); context->drawBidiText(font, run, FloatPoint(labelX, labelY)); if (shouldUnavailablePluginMessageBeButton(document(), m_pluginUnavailabilityReason)) { arrowRect.inflate(-replacementArrowCirclePadding); context->beginTransparencyLayer(1.0); context->setFillColor(replacementTextColor(), style().colorSpace()); context->fillEllipse(arrowRect); context->setCompositeOperation(CompositeClear); drawReplacementArrow(context, arrowRect); context->endTransparencyLayer(); } }
void CanvasRenderingContext2D::clip() { GraphicsContext* c = drawingContext(); if (!c) return; c->clip(m_path); #if ENABLE(DASHBOARD_SUPPORT) clearPathForDashboardBackwardCompatibilityMode(); #endif }
void GradientImage::draw(GraphicsContext& destContext, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator compositeOp, BlendMode blendMode, ImageOrientationDescription) { GraphicsContextStateSaver stateSaver(destContext); destContext.setCompositeOperation(compositeOp, blendMode); destContext.clip(destRect); destContext.translate(destRect.x(), destRect.y()); if (destRect.size() != srcRect.size()) destContext.scale(FloatSize(destRect.width() / srcRect.width(), destRect.height() / srcRect.height())); destContext.translate(-srcRect.x(), -srcRect.y()); destContext.fillRect(FloatRect(FloatPoint(), size()), *m_gradient.get()); }
virtual void paint(GraphicsContext& context, const IntRect& contentRect) { double paintStart = currentTime(); context.clearRect(contentRect); context.clip(contentRect); m_owner->paintGraphicsLayerContents(context, contentRect); double paintEnd = currentTime(); double pixelsPerSec = (contentRect.width() * contentRect.height()) / (paintEnd - paintStart); PlatformBridge::histogramCustomCounts("Renderer4.AccelContentPaintDurationMS", (paintEnd - paintStart) * 1000, 0, 120, 30); PlatformBridge::histogramCustomCounts("Renderer4.AccelContentPaintMegapixPerSecond", pixelsPerSec / 1000000, 10, 210, 30); }
void CrossfadeGeneratedImage::draw(GraphicsContext& context, const FloatRect& dstRect, const FloatRect& srcRect, ColorSpace, CompositeOperator compositeOp, BlendMode blendMode, ImageOrientationDescription) { GraphicsContextStateSaver stateSaver(context); context.setCompositeOperation(compositeOp, blendMode); context.clip(dstRect); context.translate(dstRect.x(), dstRect.y()); if (dstRect.size() != srcRect.size()) context.scale(FloatSize(dstRect.width() / srcRect.width(), dstRect.height() / srcRect.height())); context.translate(-srcRect.x(), -srcRect.y()); drawCrossfade(context); }
void PrintContext::spoolPage(GraphicsContext& ctx, int pageNumber, float width) { IntRect pageRect = m_pageRects[pageNumber]; float scale = width / pageRect.width(); ctx.save(); ctx.scale(FloatSize(scale, scale)); ctx.translate(-pageRect.x(), -pageRect.y()); ctx.clip(pageRect); m_frame->view()->paintContents(&ctx, pageRect); ctx.restore(); }
void RenderEmbeddedObject::paintReplaced(PaintInfo& paintInfo, int tx, int ty) { if (!m_replacementText) return; if (paintInfo.phase == PaintPhaseSelection) return; GraphicsContext* context = paintInfo.context; if (context->paintingDisabled()) return; FloatRect pluginRect = contentBoxRect(); pluginRect.move(tx, ty); FontDescription fontDescription; RenderTheme::defaultTheme()->systemFont(CSSValueWebkitSmallControl, fontDescription); fontDescription.setWeight(FontWeightBold); Settings* settings = document()->settings(); ASSERT(settings); if (!settings) return; fontDescription.setRenderingMode(settings->fontRenderingMode()); fontDescription.setComputedSize(fontDescription.specifiedSize()); Font font(fontDescription, 0, 0); font.update(0); TextRun run(m_replacementText.characters(), m_replacementText.length()); run.disableRoundingHacks(); float textWidth = font.floatWidth(run); FloatRect replacementTextRect; replacementTextRect.setSize(FloatSize(textWidth + replacementTextRoundedRectLeftRightTextMargin * 2, replacementTextRoundedRectHeight)); replacementTextRect.setLocation(FloatPoint((pluginRect.size().width() / 2 - replacementTextRect.size().width() / 2) + pluginRect.location().x(), (pluginRect.size().height() / 2 - replacementTextRect.size().height() / 2) + pluginRect.location().y())); Path path = Path::createRoundedRectangle(replacementTextRect, FloatSize(replacementTextRoundedRectRadius, replacementTextRoundedRectRadius)); context->save(); context->clip(pluginRect); context->beginPath(); context->addPath(path); context->setAlpha(replacementTextRoundedRectOpacity); context->setFillColor(Color::white, style()->colorSpace()); context->fillPath(); FloatPoint labelPoint(roundf(replacementTextRect.location().x() + (replacementTextRect.size().width() - textWidth) / 2), roundf(replacementTextRect.location().y()+ (replacementTextRect.size().height() - font.height()) / 2 + font.ascent())); context->setAlpha(replacementTextTextOpacity); context->setFillColor(Color::black, style()->colorSpace()); context->drawBidiText(font, run, labelPoint); context->restore(); }
void BitmapTextureImageBuffer::updateContents(TextureMapper*, GraphicsLayer* sourceLayer, const IntRect& targetRect, const IntPoint& sourceOffset, UpdateContentsFlag) { GraphicsContext* context = m_image->context(); context->clearRect(targetRect); IntRect sourceRect(targetRect); sourceRect.setLocation(sourceOffset); context->save(); context->clip(targetRect); context->translate(targetRect.x() - sourceOffset.x(), targetRect.y() - sourceOffset.y()); sourceLayer->paintGraphicsLayerContents(*context, sourceRect); context->restore(); }
void PrintContext::spoolPage(GraphicsContext& ctx, int pageNumber, float width) { // FIXME: Not correct for vertical text. IntRect pageRect = m_pageRects[pageNumber]; float scale = width / pageRect.width(); ctx.save(); ctx.scale(FloatSize(scale, scale)); ctx.translate(-pageRect.x(), -pageRect.y()); ctx.clip(pageRect); m_frame->view()->paintContents(&ctx, pageRect); if (ctx.supportsURLFragments()) outputLinkedDestinations(ctx, m_frame->document(), pageRect); ctx.restore(); }
void CrossfadeGeneratedImage::drawCrossfade(GraphicsContext& context) { // Draw nothing if either of the images hasn't loaded yet. if (m_fromImage == Image::nullImage() || m_toImage == Image::nullImage()) return; GraphicsContextStateSaver stateSaver(context); context.clip(FloatRect(FloatPoint(), m_crossfadeSize)); context.beginTransparencyLayer(1); drawCrossfadeSubimage(context, m_fromImage, CompositeSourceOver, 1 - m_percentage, m_crossfadeSize); drawCrossfadeSubimage(context, m_toImage, CompositePlusLighter, m_percentage, m_crossfadeSize); context.endTransparencyLayer(); }
void SVGImage::draw(GraphicsContext& context, const FloatRect& dstRect, const FloatRect& srcRect, CompositeOperator compositeOp, BlendMode blendMode, ImageOrientationDescription) { if (!m_page) return; FrameView* view = frameView(); ASSERT(view); GraphicsContextStateSaver stateSaver(context); context.setCompositeOperation(compositeOp, blendMode); context.clip(enclosingIntRect(dstRect)); float alpha = context.alpha(); bool compositingRequiresTransparencyLayer = compositeOp != CompositeSourceOver || blendMode != BlendModeNormal || alpha < 1; if (compositingRequiresTransparencyLayer) { context.beginTransparencyLayer(alpha); context.setCompositeOperation(CompositeSourceOver, BlendModeNormal); } FloatSize scale(dstRect.width() / srcRect.width(), dstRect.height() / srcRect.height()); // We can only draw the entire frame, clipped to the rect we want. So compute where the top left // of the image would be if we were drawing without clipping, and translate accordingly. FloatSize topLeftOffset(srcRect.location().x() * scale.width(), srcRect.location().y() * scale.height()); FloatPoint destOffset = dstRect.location() - topLeftOffset; context.translate(destOffset.x(), destOffset.y()); context.scale(scale); view->resize(containerSize()); if (!m_url.isEmpty()) view->scrollToFragment(m_url); if (view->needsLayout()) view->layout(); view->paint(context, intersection(context.clipBounds(), enclosingIntRect(srcRect))); if (compositingRequiresTransparencyLayer) context.endTransparencyLayer(); stateSaver.restore(); if (imageObserver()) imageObserver()->didDraw(this); }
void RenderFlowThread::paintFlowThreadPortionInRegion(PaintInfo& paintInfo, RenderRegion* region, LayoutRect flowThreadPortionRect, LayoutRect flowThreadPortionOverflowRect, const LayoutPoint& paintOffset) const { GraphicsContext* context = paintInfo.context; if (!context) return; // RenderFlowThread should start painting its content in a position that is offset // from the region rect's current position. The amount of offset is equal to the location of // the flow thread portion in the flow thread's local coordinates. // Note that we have to pixel snap the location at which we're going to paint, since this is necessary // to minimize the amount of incorrect snapping that would otherwise occur. // If we tried to paint by applying a non-integral translation, then all the // layout code that attempted to pixel snap would be incorrect. IntPoint adjustedPaintOffset; LayoutPoint portionLocation; if (style()->isFlippedBlocksWritingMode()) { LayoutRect flippedFlowThreadPortionRect(flowThreadPortionRect); flipForWritingMode(flippedFlowThreadPortionRect); portionLocation = flippedFlowThreadPortionRect.location(); } else portionLocation = flowThreadPortionRect.location(); adjustedPaintOffset = roundedIntPoint(paintOffset - portionLocation); // The clipping rect for the region is set up by assuming the flowThreadPortionRect is going to paint offset from adjustedPaintOffset. // Remember that we pixel snapped and moved the paintOffset and stored the snapped result in adjustedPaintOffset. Now we add back in // the flowThreadPortionRect's location to get the spot where we expect the portion to actually paint. This can be non-integral and // that's ok. We then pixel snap the resulting clipping rect to account for snapping that will occur when the flow thread paints. IntRect regionClippingRect = pixelSnappedIntRect(computeRegionClippingRect(adjustedPaintOffset + portionLocation, flowThreadPortionRect, flowThreadPortionOverflowRect)); PaintInfo info(paintInfo); info.rect.intersect(regionClippingRect); if (!info.rect.isEmpty()) { context->save(); context->clip(regionClippingRect); context->translate(adjustedPaintOffset.x(), adjustedPaintOffset.y()); info.rect.moveBy(-adjustedPaintOffset); layer()->paint(context, info.rect, 0, 0, region, RenderLayer::PaintLayerTemporaryClipRects); context->restore(); } }
void ScrollableAreaPainter::paintResizer(GraphicsContext& context, const IntPoint& paintOffset, const CullRect& cullRect) { if (getScrollableArea().box().style()->resize() == RESIZE_NONE) return; IntRect absRect = getScrollableArea().resizerCornerRect( getScrollableArea().box().pixelSnappedBorderBoxRect(), ResizerForPointer); if (absRect.isEmpty()) return; absRect.moveBy(paintOffset); if (getScrollableArea().resizer()) { if (!cullRect.intersectsCullRect(absRect)) return; ScrollbarPainter::paintIntoRect(*getScrollableArea().resizer(), context, paintOffset, LayoutRect(absRect)); return; } if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible( context, getScrollableArea().box(), DisplayItem::kResizer)) return; LayoutObjectDrawingRecorder recorder(context, getScrollableArea().box(), DisplayItem::kResizer, absRect); drawPlatformResizerImage(context, absRect); // Draw a frame around the resizer (1px grey line) if there are any scrollbars // present. Clipping will exclude the right and bottom edges of this frame. if (!getScrollableArea().hasOverlayScrollbars() && getScrollableArea().hasScrollbar()) { GraphicsContextStateSaver stateSaver(context); context.clip(absRect); IntRect largerCorner = absRect; largerCorner.setSize( IntSize(largerCorner.width() + 1, largerCorner.height() + 1)); context.setStrokeColor(Color(217, 217, 217)); context.setStrokeThickness(1.0f); context.setFillColor(Color::transparent); context.drawRect(largerCorner); } }
void ImagePainter::paintReplaced(const PaintInfo& paintInfo, const LayoutPoint& paintOffset) { LayoutUnit cWidth = m_layoutImage.contentWidth(); LayoutUnit cHeight = m_layoutImage.contentHeight(); GraphicsContext* context = paintInfo.context; if (!m_layoutImage.imageResource()->hasImage()) { if (paintInfo.phase == PaintPhaseSelection) return; if (cWidth > 2 && cHeight > 2) { // Draw an outline rect where the image should be. IntRect paintRect = pixelSnappedIntRect(LayoutRect(paintOffset.x() + m_layoutImage.borderLeft() + m_layoutImage.paddingLeft(), paintOffset.y() + m_layoutImage.borderTop() + m_layoutImage.paddingTop(), cWidth, cHeight)); LayoutObjectDrawingRecorder drawingRecorder(*context, m_layoutImage, paintInfo.phase, paintRect); if (drawingRecorder.canUseCachedDrawing()) return; context->setStrokeStyle(SolidStroke); context->setStrokeColor(Color::lightGray); context->setFillColor(Color::transparent); context->drawRect(paintRect); } } else if (cWidth > 0 && cHeight > 0) { LayoutRect contentRect = m_layoutImage.contentBoxRect(); contentRect.moveBy(paintOffset); LayoutRect paintRect = m_layoutImage.replacedContentRect(); paintRect.moveBy(paintOffset); LayoutObjectDrawingRecorder drawingRecorder(*context, m_layoutImage, paintInfo.phase, contentRect); if (drawingRecorder.canUseCachedDrawing()) return; bool clip = !contentRect.contains(paintRect); if (clip) { context->save(); context->clip(contentRect); } paintIntoRect(context, paintRect); if (clip) context->restore(); } }
ImageBitmap::ImageBitmap(HTMLVideoElement* video, const IntRect& cropRect) : m_cropRect(cropRect) , m_imageElement(0) , m_bitmapOffset(IntPoint()) { IntRect videoRect = IntRect(IntPoint(), video->player()->naturalSize()); IntRect srcRect = intersection(cropRect, videoRect); IntRect dstRect(IntPoint(), srcRect.size()); OwnPtr<ImageBuffer> buf = ImageBuffer::create(videoRect.size(), 1, UnacceleratedNonPlatformBuffer); GraphicsContext* c = buf->context(); c->clip(dstRect); c->translate(-srcRect.x(), -srcRect.y()); video->paintCurrentFrameInContext(c, videoRect); m_bitmap = buf->copyImage(DontCopyBackingStore); m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y())), srcRect.size()); ScriptWrappable::init(this); }