RenderHTMLCanvas.cpp [plain text]
#include "config.h"
#include "RenderHTMLCanvas.h"
#include "CanvasRenderingContext.h"
#include "Document.h"
#include "Frame.h"
#include "FrameView.h"
#include "GraphicsContext.h"
#include "HTMLCanvasElement.h"
#include "HTMLNames.h"
#include "ImageQualityController.h"
#include "Page.h"
#include "PaintInfo.h"
#include "RenderView.h"
#include <wtf/IsoMallocInlines.h>
namespace WebCore {
using namespace HTMLNames;
WTF_MAKE_ISO_ALLOCATED_IMPL(RenderHTMLCanvas);
RenderHTMLCanvas::RenderHTMLCanvas(HTMLCanvasElement& element, RenderStyle&& style)
: RenderReplaced(element, WTFMove(style), element.size())
{
view().frameView().incrementVisuallyNonEmptyPixelCount(roundedIntSize(intrinsicSize()));
}
HTMLCanvasElement& RenderHTMLCanvas::canvasElement() const
{
return downcast<HTMLCanvasElement>(nodeForNonAnonymous());
}
bool RenderHTMLCanvas::requiresLayer() const
{
if (RenderReplaced::requiresLayer())
return true;
if (CanvasRenderingContext* context = canvasElement().renderingContext())
return context->isAccelerated();
return false;
}
void RenderHTMLCanvas::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
GraphicsContext& context = paintInfo.context();
LayoutRect contentBoxRect = this->contentBoxRect();
contentBoxRect.moveBy(paintOffset);
LayoutRect replacedContentRect = this->replacedContentRect(intrinsicSize());
replacedContentRect.moveBy(paintOffset);
bool clip = !contentBoxRect.contains(replacedContentRect);
GraphicsContextStateSaver stateSaver(paintInfo.context(), clip);
if (clip)
paintInfo.context().clip(snappedIntRect(contentBoxRect));
if (paintInfo.phase == PaintPhaseForeground)
page().addRelevantRepaintedObject(this, intersection(replacedContentRect, contentBoxRect));
InterpolationQualityMaintainer interpolationMaintainer(context, ImageQualityController::interpolationQualityFromStyle(style()));
canvasElement().paint(context, replacedContentRect);
}
void RenderHTMLCanvas::canvasSizeChanged()
{
IntSize canvasSize = canvasElement().size();
LayoutSize zoomedSize(canvasSize.width() * style().effectiveZoom(), canvasSize.height() * style().effectiveZoom());
if (zoomedSize == intrinsicSize())
return;
setIntrinsicSize(zoomedSize);
if (!parent())
return;
setNeedsLayoutIfNeededAfterIntrinsicSizeChange();
}
}