[DrawableDescriptor]Fix use ptr befor which can be nullptr.

Signed-off-by: Zhang Jinyu <zhangjinyu101@huawei.com>
Change-Id: I1b3e6160cd07a224f81e717a7cbf4166bf149233
Signed-off-by: Zhang Jinyu <zhangjinyu101@huawei.com>
This commit is contained in:
Zhang Jinyu 2024-08-26 20:52:50 +08:00
parent 294ceb8b7d
commit 833811327b

View File

@ -468,6 +468,10 @@ Rosen::Drawing::ImageInfo LayeredDrawableDescriptor::CreateRSImageInfo(
void LayeredDrawableDescriptor::CompositeIconAdaptive(std::shared_ptr<Rosen::Drawing::Bitmap>& foreground, void LayeredDrawableDescriptor::CompositeIconAdaptive(std::shared_ptr<Rosen::Drawing::Bitmap>& foreground,
std::shared_ptr<Rosen::Drawing::Bitmap>& background, std::shared_ptr<Rosen::Drawing::Bitmap>& mask) std::shared_ptr<Rosen::Drawing::Bitmap>& background, std::shared_ptr<Rosen::Drawing::Bitmap>& mask)
{ {
if (!background) {
HILOGW("The background is null when adaptive composite icons are used.");
return;
}
Rosen::Drawing::Brush brush; Rosen::Drawing::Brush brush;
brush.SetAntiAlias(true); brush.SetAntiAlias(true);
Rosen::Drawing::ImageInfo imageInfo = Rosen::Drawing::ImageInfo imageInfo =
@ -484,11 +488,12 @@ void LayeredDrawableDescriptor::CompositeIconAdaptive(std::shared_ptr<Rosen::Dra
bitmapCanvas.DetachBrush(); bitmapCanvas.DetachBrush();
} }
Rosen::Drawing::Rect srcRect(0.0, 0.0, static_cast<float>(mask->GetWidth()), static_cast<float>(mask->GetHeight()));
Rosen::Drawing::Rect dstRect( Rosen::Drawing::Rect dstRect(
0.0, 0.0, static_cast<float>(background->GetWidth()), static_cast<float>(background->GetHeight())); 0.0, 0.0, static_cast<float>(background->GetWidth()), static_cast<float>(background->GetHeight()));
Rosen::Drawing::Image image; Rosen::Drawing::Image image;
if (mask) { if (mask) {
Rosen::Drawing::Rect srcRect(
0.0, 0.0, static_cast<float>(mask->GetWidth()), static_cast<float>(mask->GetHeight()));
image.BuildFromBitmap(*mask); image.BuildFromBitmap(*mask);
brush.SetBlendMode(Rosen::Drawing::BlendMode::DST_ATOP); brush.SetBlendMode(Rosen::Drawing::BlendMode::DST_ATOP);
bitmapCanvas.AttachBrush(brush); bitmapCanvas.AttachBrush(brush);