mirror of
https://gitee.com/openharmony/graphic_graphic_2d
synced 2025-03-03 18:21:45 +00:00
rotation problem
Signed-off-by: pengpenglottie <pengpeng35@huawei.com> Change-Id: I2223af8d4b68b8a3238fe2d1b96d57abdfe7509e
This commit is contained in:
parent
b6c9133f1e
commit
31deabeb07
@ -84,9 +84,11 @@ private:
|
||||
static void DrawColorfulShadowInner(const RSProperties& properties, RSPaintFilterCanvas& canvas, SkPath& path);
|
||||
static void DrawShadowInner(const RSProperties& properties, RSPaintFilterCanvas& canvas, SkPath& path);
|
||||
#ifdef NEW_SKIA
|
||||
static bool GetGradientDirectionPoints(SkPoint* pts, const SkRect& clipBounds, GradientDirection direction);
|
||||
static bool GetGradientDirectionPoints(SkPoint* pts,
|
||||
const SkRect& clipBounds, GradientDirection direction);
|
||||
static void TransformGradientBlurDirection(uint8_t& direction, const uint8_t directionBias);
|
||||
static sk_sp<SkShader> MakeAlphaGradientShader(const SkRect& clipBounds,
|
||||
const std::shared_ptr<RSLinearGradientBlurPara>& para);
|
||||
const std::shared_ptr<RSLinearGradientBlurPara>& para, uint8_t directionBias);
|
||||
static sk_sp<SkShader> MakeHorizontalMeanBlurShader(float radiusIn,
|
||||
sk_sp<SkShader> shader, sk_sp<SkShader> gradientShader);
|
||||
static sk_sp<SkShader> MakeVerticalMeanBlurShader(float radiusIn,
|
||||
@ -96,6 +98,7 @@ private:
|
||||
float radius, sk_sp<SkShader> alphaGradientShader, const SkIRect& clipIPadding);
|
||||
static void DrawVerticalLinearGradientBlur(SkSurface* skSurface, RSPaintFilterCanvas& canvas,
|
||||
float radius, sk_sp<SkShader> alphaGradientShader, const SkIRect& clipIPadding);
|
||||
static uint8_t CalcDirectionBias(const SkMatrix& mat);
|
||||
#endif
|
||||
#else
|
||||
static void Clip(Drawing::Canvas& canvas, RectF rect);
|
||||
|
@ -69,6 +69,8 @@ constexpr float MAX_TRANS_RATIO = 0.95f;
|
||||
constexpr float MIN_SPOT_RATIO = 1.0f;
|
||||
constexpr float MAX_SPOT_RATIO = 1.95f;
|
||||
constexpr float MAX_AMBIENT_RADIUS = 150.0f;
|
||||
constexpr static float FLOAT_ZERO_THRESHOLD = 0.001f;
|
||||
constexpr static uint8_t DIRECTION_NUM = 4;
|
||||
} // namespace
|
||||
|
||||
#ifndef USE_ROSEN_DRAWING
|
||||
@ -770,14 +772,47 @@ bool RSPropertiesPainter::GetGradientDirectionPoints(
|
||||
}
|
||||
return true;
|
||||
}
|
||||
void RSPropertiesPainter::TransformGradientBlurDirection(uint8_t& direction, const uint8_t directionBias)
|
||||
{
|
||||
if (direction == static_cast<uint8_t>(GradientDirection::LEFT_BOTTOM)) {
|
||||
direction += 2; // 2 is used to transtorm diagnal direction.
|
||||
} else if (direction == static_cast<uint8_t>(GradientDirection::RIGHT_TOP) ||
|
||||
direction == static_cast<uint8_t>(GradientDirection::RIGHT_BOTTOM)) {
|
||||
direction -= 1; // 1 is used to transtorm diagnal direction.
|
||||
}
|
||||
if (direction <= static_cast<uint8_t>(GradientDirection::BOTTOM)) {
|
||||
if (direction < directionBias) {
|
||||
direction += DIRECTION_NUM;
|
||||
}
|
||||
direction -= directionBias;
|
||||
} else {
|
||||
direction -= DIRECTION_NUM;
|
||||
if (direction < directionBias) {
|
||||
direction += DIRECTION_NUM;
|
||||
}
|
||||
direction -= directionBias;
|
||||
direction += DIRECTION_NUM;
|
||||
}
|
||||
if (direction == static_cast<uint8_t>(GradientDirection::RIGHT_BOTTOM)) {
|
||||
direction -= 2; // 2 is used to restore diagnal direction.
|
||||
} else if (direction == static_cast<uint8_t>(GradientDirection::LEFT_BOTTOM) ||
|
||||
direction == static_cast<uint8_t>(GradientDirection::RIGHT_TOP)) {
|
||||
direction += 1; // 1 is used to restore diagnal direction.
|
||||
}
|
||||
}
|
||||
|
||||
sk_sp<SkShader> RSPropertiesPainter::MakeAlphaGradientShader(
|
||||
const SkRect& clipBounds, const std::shared_ptr<RSLinearGradientBlurPara>& para)
|
||||
const SkRect& clipBounds, const std::shared_ptr<RSLinearGradientBlurPara>& para, uint8_t directionBias)
|
||||
{
|
||||
std::vector<SkColor> c;
|
||||
std::vector<SkScalar> p;
|
||||
SkPoint pts[2];
|
||||
bool result = GetGradientDirectionPoints(pts, clipBounds, para->direction_);
|
||||
uint8_t direction = static_cast<uint8_t>(para->direction_);
|
||||
if (directionBias != 0) {
|
||||
TransformGradientBlurDirection(direction, directionBias);
|
||||
}
|
||||
bool result = GetGradientDirectionPoints(
|
||||
pts, clipBounds, static_cast<GradientDirection>(direction));
|
||||
if (!result) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -905,6 +940,21 @@ void RSPropertiesPainter::DrawVerticalLinearGradientBlur(SkSurface* skSurface, R
|
||||
paint.setShader(shader);
|
||||
canvas.drawRect(SkRect::Make(clipIPadding.makeOffset(-clipIPadding.left(), -clipIPadding.top())), paint);
|
||||
}
|
||||
|
||||
uint8_t RSPropertiesPainter::CalcDirectionBias(const SkMatrix& mat) {
|
||||
uint8_t directionBias = 0;
|
||||
// 1 and 3 represents rotate matrix's index
|
||||
if ((mat.get(1) > FLOAT_ZERO_THRESHOLD) && (mat.get(3) < (0 - FLOAT_ZERO_THRESHOLD))) {
|
||||
directionBias = 1; // 1 represents rotate 90 degree
|
||||
// 0 and 4 represents rotate matrix's index
|
||||
} else if ((mat.get(0) < (0 - FLOAT_ZERO_THRESHOLD)) && (mat.get(4) < (0 - FLOAT_ZERO_THRESHOLD))) {
|
||||
directionBias = 2; // 2 represents rotate 180 degree
|
||||
// 1 and 3 represents rotate matrix's index
|
||||
} else if ((mat.get(1) < (0 - FLOAT_ZERO_THRESHOLD)) && (mat.get(3) > FLOAT_ZERO_THRESHOLD)) {
|
||||
directionBias = 3; // 3 represents rotate 270 degree
|
||||
}
|
||||
return directionBias;
|
||||
}
|
||||
#endif
|
||||
|
||||
void RSPropertiesPainter::DrawLinearGradientBlurFilter(
|
||||
@ -926,9 +976,11 @@ void RSPropertiesPainter::DrawLinearGradientBlurFilter(
|
||||
|
||||
auto clipBounds = canvas.getDeviceClipBounds();
|
||||
auto clipIPadding = clipBounds.makeOutset(-1, -1);
|
||||
SkMatrix mat = canvas.getTotalMatrix();
|
||||
uint8_t directionBias = CalcDirectionBias(mat);
|
||||
|
||||
auto para = properties.GetLinearGradientBlurPara();
|
||||
auto alphaGradientShader = MakeAlphaGradientShader(SkRect::Make(clipIPadding), para);
|
||||
auto alphaGradientShader = MakeAlphaGradientShader(SkRect::Make(clipIPadding), para, directionBias);
|
||||
if (alphaGradientShader == nullptr) {
|
||||
ROSEN_LOGE("RSPropertiesPainter::DrawLinearGradientBlurFilter alphaGradientShader null");
|
||||
return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user