#include "flutter/flow/ohos_layers/clip_rect_layer.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkRRect.h"
#include "flutter/flow/ohos_layers/paint_context.h"
namespace flutter::OHOS {
void ClipRectLayer::Prepare(const SkMatrix& matrix)
{
SkRect childPaintBounds = SkRect::MakeEmpty();
PrepareChildren(matrix, childPaintBounds);
if (childPaintBounds.intersect(clipRect_)) {
SetPaintBounds(childPaintBounds);
}
}
void ClipRectLayer::Paint(const PaintContext& paintContext) const
{
SkAutoCanvasRestore save(paintContext.skCanvas, true);
paintContext.skCanvas->clipRect(clipRect_, 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();
}
}
}