#include "flutter/flow/ohos_layers/clip_rrect_layer.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkRRect.h"
#include "flutter/flow/ohos_layers/paint_context.h"
namespace flutter::OHOS {
void ClipRRectLayer::Prepare(const SkMatrix& matrix)
{
SkRect clipRrectBounds = clipRrect_.getBounds();
SkRect childPaintBounds = SkRect::MakeEmpty();
PrepareChildren(matrix, childPaintBounds);
if (childPaintBounds.intersect(clipRrectBounds)) {
SetPaintBounds(clipRrectBounds);
}
}
void ClipRRectLayer::Paint(const PaintContext& paintContext) const
{
SkAutoCanvasRestore save(paintContext.skCanvas, true);
paintContext.skCanvas->clipRRect(clipRrect_, clipBehavior_ != Clip::HARDEDGE);
if (clipBehavior_ == Clip::ANTIALIAS_WITH_SAVELAYER) {
paintContext.skCanvas->saveLayer(GetPaintBounds(), nullptr);
}
PaintChildren(paintContext);
if (clipBehavior_ == Clip::ANTIALIAS_WITH_SAVELAYER) {
paintContext.skCanvas->restore();
}
}
}