bugfix about scale according to dst and buffer size

Signed-off-by: thelastking <chenlulu16@huawei.com>
Change-Id: Ie0f1b54ae20a7645c84637de2226a646ee79e6db
This commit is contained in:
thelastking 2022-02-23 16:08:27 +08:00
parent 034abf9e90
commit cc45c16b43
2 changed files with 13 additions and 7 deletions

View File

@ -16,6 +16,7 @@
#include <unordered_set> #include <unordered_set>
#include "include/core/SkRect.h"
#include "platform/common/rs_log.h" #include "platform/common/rs_log.h"
#include "property/rs_properties_painter.h" #include "property/rs_properties_painter.h"
#include "render/rs_blur_filter.h" #include "render/rs_blur_filter.h"
@ -395,12 +396,14 @@ void FillDrawParameters(BufferDrawParameters& params, const sptr<OHOS::SurfaceBu
params.antiAlias = true; params.antiAlias = true;
const RSProperties& property = node.GetRenderProperties(); const RSProperties& property = node.GetRenderProperties();
params.alpha = node.GetAlpha() * property.GetAlpha(); params.alpha = node.GetAlpha() * property.GetAlpha();
params.dstRect = SkRect::MakeXYWH(0, 0, buffer->GetWidth(), buffer->GetHeight()); params.dstRect = SkRect::MakeXYWH(0, 0, buffer->GetSurfaceBufferWidth(), buffer->GetSurfaceBufferHeight());
auto geoPtr = std::static_pointer_cast<RSObjAbsGeometry>(property.GetBoundsGeometry()); auto geoPtr = std::static_pointer_cast<RSObjAbsGeometry>(property.GetBoundsGeometry());
if (geoPtr) { if (geoPtr) {
params.transform = geoPtr->GetAbsMatrix(); params.transform = geoPtr->GetAbsMatrix();
params.widthScale = static_cast<double>(geoPtr->GetAbsRect().width_ * 1.0 / buffer->GetWidth()); params.dstLeft = geoPtr->GetAbsRect().left_;
params.heightScale = static_cast<double>(geoPtr->GetAbsRect().height_ * 1.0 / buffer->GetHeight()); params.dstTop = geoPtr->GetAbsRect().top_;
params.dstWidth = geoPtr->GetAbsRect().width_;
params.dstHeight = geoPtr->GetAbsRect().height_;
} }
} }
} // namespace Detail } // namespace Detail
@ -479,8 +482,8 @@ void RsRenderServiceUtil::Draw(SkCanvas& canvas, BufferDrawParameters& params, R
if (bitmap.installPixels(pixmap)) { if (bitmap.installPixels(pixmap)) {
canvas.save(); canvas.save();
if (params.onDisplay) { if (params.onDisplay) {
canvas.clipRect(SkRect::MakeXYWH(params.dstLeft, params.dstTop, params.dstWidth, params.dstHeight));
canvas.setMatrix(params.transform); canvas.setMatrix(params.transform);
canvas.scale(params.widthScale, params.heightScale);
DealAnimation(canvas, paint, node); DealAnimation(canvas, paint, node);
const RSProperties& property = node.GetRenderProperties(); const RSProperties& property = node.GetRenderProperties();
auto filter = std::static_pointer_cast<RSSkiaFilter>(property.GetBackgroundFilter()); auto filter = std::static_pointer_cast<RSSkiaFilter>(property.GetBackgroundFilter());
@ -491,7 +494,8 @@ void RsRenderServiceUtil::Draw(SkCanvas& canvas, BufferDrawParameters& params, R
RSPropertiesPainter::RestoreForFilter(canvas); RSPropertiesPainter::RestoreForFilter(canvas);
} }
} }
canvas.drawBitmapRect(bitmap, params.dstRect, &paint); canvas.drawBitmapRect(bitmap, params.dstRect, SkRect::MakeXYWH(0, 0, params.dstWidth, params.dstHeight),
&paint);
canvas.restore(); canvas.restore();
} }
} }

View File

@ -35,8 +35,10 @@ struct BufferDrawParameters {
bool antiAlias = true; bool antiAlias = true;
bool onDisplay = true; bool onDisplay = true;
float alpha = 1.0f; float alpha = 1.0f;
double widthScale = 1.0f; uint32_t dstLeft = 0;
double heightScale = 1.0f; uint32_t dstTop = 0;
uint32_t dstWidth = 0;
uint32_t dstHeight = 0;
SkPixmap pixmap; SkPixmap pixmap;
SkBitmap bitmap; SkBitmap bitmap;
SkMatrix transform; SkMatrix transform;