This source file includes following definitions.
- layerTypeRequired
- paintReplaced
- canvasSizeChanged
- additionalCompositingReasons
#include "config.h"
#include "core/rendering/RenderHTMLCanvas.h"
#include "core/html/HTMLCanvasElement.h"
#include "core/html/canvas/CanvasRenderingContext.h"
#include "core/frame/FrameView.h"
#include "core/frame/LocalFrame.h"
#include "core/page/Page.h"
#include "core/rendering/PaintInfo.h"
#include "core/rendering/RenderView.h"
namespace WebCore {
using namespace HTMLNames;
RenderHTMLCanvas::RenderHTMLCanvas(HTMLCanvasElement* element)
: RenderReplaced(element, element->size())
{
view()->frameView()->setIsVisuallyNonEmpty();
}
LayerType RenderHTMLCanvas::layerTypeRequired() const
{
LayerType type = RenderReplaced::layerTypeRequired();
if (type != NoLayer)
return type;
HTMLCanvasElement* canvas = toHTMLCanvasElement(node());
if (canvas && canvas->renderingContext() && canvas->renderingContext()->isAccelerated())
return NormalLayer;
return NoLayer;
}
void RenderHTMLCanvas::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
GraphicsContext* context = paintInfo.context;
LayoutRect contentRect = contentBoxRect();
contentRect.moveBy(paintOffset);
LayoutRect paintRect = replacedContentRect();
paintRect.moveBy(paintOffset);
bool clip = !contentRect.contains(paintRect);
if (clip) {
paintInfo.context->save();
paintInfo.context->clip(pixelSnappedIntRect(contentRect));
}
InterpolationQuality interpolationQuality = style()->imageRendering() == ImageRenderingOptimizeContrast ? InterpolationLow : CanvasDefaultInterpolationQuality;
InterpolationQuality previousInterpolationQuality = context->imageInterpolationQuality();
context->setImageInterpolationQuality(interpolationQuality);
toHTMLCanvasElement(node())->paint(context, paintRect);
context->setImageInterpolationQuality(previousInterpolationQuality);
if (clip)
context->restore();
}
void RenderHTMLCanvas::canvasSizeChanged()
{
IntSize canvasSize = toHTMLCanvasElement(node())->size();
LayoutSize zoomedSize(canvasSize.width() * style()->effectiveZoom(), canvasSize.height() * style()->effectiveZoom());
if (zoomedSize == intrinsicSize())
return;
setIntrinsicSize(zoomedSize);
if (!parent())
return;
if (!preferredLogicalWidthsDirty())
setPreferredLogicalWidthsDirty();
LayoutSize oldSize = size();
updateLogicalWidth();
updateLogicalHeight();
if (oldSize == size())
return;
if (!selfNeedsLayout())
setNeedsLayout();
}
CompositingReasons RenderHTMLCanvas::additionalCompositingReasons(CompositingTriggerFlags triggers) const
{
if (!(triggers & CanvasTrigger))
return CompositingReasonNone;
HTMLCanvasElement* canvas = toHTMLCanvasElement(node());
if (canvas->renderingContext() && canvas->renderingContext()->isAccelerated())
return CompositingReasonCanvas;
return CompositingReasonNone;
}
}