!17150 drawing代码同步

Merge pull request !17150 from Marksss/master
This commit is contained in:
openharmony_ci 2024-11-18 13:12:14 +00:00 committed by Gitee
commit ee348accd8
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
16 changed files with 95 additions and 88 deletions

View File

@ -15,13 +15,11 @@
#include "js_font.h"
#include "src/utils/SkUTF.h"
#include "native_value.h"
#include "js_drawing_utils.h"
#include "js_typeface.h"
#include "native_value.h"
#include "path_napi/js_path.h"
#include "src/utils/SkUTF.h"
namespace OHOS::Rosen {
namespace Drawing {

View File

@ -58,8 +58,8 @@ inline T1* ConvertToOriginalText(T2* ptr)
return reinterpret_cast<T1*>(ptr);
}
static uint32_t LoadFromFontCollection(
OH_Drawing_FontCollection* fontCollection, const std::string& familyName, const uint8_t* data, size_t dataLength)
static uint32_t LoadFromFontCollection(OH_Drawing_FontCollection* fontCollection,
const std::string& familyName, const uint8_t* data, size_t dataLength)
{
if (fontCollection == nullptr) {
return ERROR_NULL_FONT_COLLECTION;
@ -141,8 +141,8 @@ uint32_t OH_Drawing_RegisterFont(
return LoadFromFontCollection(fontCollection, familyName, data, size);
}
uint32_t OH_Drawing_RegisterFontBuffer(
OH_Drawing_FontCollection* fontCollection, const char* fontFamily, uint8_t* fontBuffer, size_t length)
uint32_t OH_Drawing_RegisterFontBuffer(OH_Drawing_FontCollection* fontCollection, const char* fontFamily,
uint8_t* fontBuffer, size_t length)
{
if (fontCollection == nullptr) {
return ERROR_NULL_FONT_COLLECTION;

View File

@ -1,4 +1,3 @@
/*
* Copyright (c) 2021-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
@ -602,8 +601,8 @@ OH_Drawing_TextBox* OH_Drawing_TypographyGetRectsForRange(OH_Drawing_Typography*
}
auto originalRectHeightStyle = ConvertToOriginalText<TextRectHeightStyle>(&heightStyle);
auto originalRectWidthStyle = ConvertToOriginalText<TextRectWidthStyle>(&widthStyle);
*originalVector = ConvertToOriginalText<Typography>(typography)->GetTextRectsByBoundary(start, end,
*originalRectHeightStyle, *originalRectWidthStyle);
*originalVector = ConvertToOriginalText<Typography>(typography)
->GetTextRectsByBoundary(start, end, *originalRectHeightStyle, *originalRectWidthStyle);
return (OH_Drawing_TextBox*)originalVector;
}
@ -1892,7 +1891,7 @@ void OH_Drawing_TextStyleDestroyFontFeatures(OH_Drawing_FontFeature* fontFeature
if ((fontFeature + i)->tag == nullptr) {
continue;
}
delete[](fontFeature + i)->tag;
delete[] (fontFeature + i)->tag;
(fontFeature + i)->tag = nullptr;
}
delete[] fontFeature;
@ -2387,7 +2386,7 @@ static void ResetString(char** ptr)
if (!ptr || !(*ptr)) {
return;
}
delete[](*ptr);
delete[] (*ptr);
(*ptr) = nullptr;
}
@ -2401,7 +2400,7 @@ static void ResetDrawingAliasInfoSet(OH_Drawing_FontAliasInfo** aliasInfoArray,
ResetString(&((*aliasInfoArray)[i].familyName));
}
delete[](*aliasInfoArray);
delete[] (*aliasInfoArray);
(*aliasInfoArray) = nullptr;
aliasInfoSize = 0;
}
@ -2437,7 +2436,7 @@ static void ResetDrawingAdjustInfo(OH_Drawing_FontAdjustInfo** adjustInfoArray,
if (adjustInfoArray == nullptr || *adjustInfoArray == nullptr) {
return;
}
delete[](*adjustInfoArray);
delete[] (*adjustInfoArray);
(*adjustInfoArray) = nullptr;
adjustInfoSize = 0;
}
@ -2491,7 +2490,7 @@ static void ResetDrawingFontGenericInfoSet(
ResetDrawingFontGenericInfo((*fontGenericInfoArray)[i]);
}
delete[](*fontGenericInfoArray);
delete[] (*fontGenericInfoArray);
(*fontGenericInfoArray) = nullptr;
fontGenericInfoSize = 0;
}
@ -2537,7 +2536,7 @@ static void ResetDrawingFallbackInfoSet(OH_Drawing_FontFallbackInfo** fallbackIn
for (size_t i = 0; i < fallbackInfoSize; i++) {
ResetDrawingFallbackInfo((*fallbackInfoArray)[i]);
}
delete[](*fallbackInfoArray);
delete[] (*fallbackInfoArray);
(*fallbackInfoArray) = nullptr;
fallbackInfoSize = 0;
}
@ -2585,7 +2584,7 @@ static void ResetDrawingFallbackGroupSet(OH_Drawing_FontFallbackGroup** fallback
for (size_t i = 0; i < fallbackGroupSize; i++) {
ResetDrawingFallbackGroup((*fallbackGroupArray)[i]);
}
delete[](*fallbackGroupArray);
delete[] (*fallbackGroupArray);
(*fallbackGroupArray) = nullptr;
fallbackGroupSize = 0;
}
@ -2633,10 +2632,10 @@ static void ResetStringArray(char*** ptr, size_t& charArraySize)
if (!((*ptr)[i])) {
continue;
}
delete[]((*ptr)[i]);
delete[] ((*ptr)[i]);
((*ptr)[i]) = nullptr;
}
delete[](*ptr);
delete[] (*ptr);
(*ptr) = nullptr;
charArraySize = 0;
}

View File

@ -517,12 +517,15 @@ private:
inline void Path::Dump(std::string& out) const
{
auto bounds = impl_->GetBounds();
out += "[length:" + std::to_string(impl_->GetLength(false));
out += " Bounds";
bounds.Dump(out);
out += " valid:" + std::string(impl_->IsValid() ? "true" : "false");
out += "]";
out += '[';
if (impl_ != nullptr) {
auto bounds = impl_->GetBounds();
out += "length:" + std::to_string(impl_->GetLength(false));
out += " Bounds";
bounds.Dump(out);
out += " valid:" + std::string(impl_->IsValid() ? "true" : "false");
}
out += ']';
}
} // namespace Drawing
} // namespace Rosen

View File

@ -218,7 +218,7 @@ public:
*/
Pixmap GetPixmap() const;
/*
/**
* @brief Make new image from Bitmap but never copy Pixels
* @note the function never copy Pixels, make sure Pixels is available during using the image
*/
@ -252,12 +252,15 @@ private:
inline void Bitmap::Dump(std::string& out) const
{
out += "[width:" + std::to_string(bmpImplPtr->GetWidth());
out += " height:" + std::to_string(bmpImplPtr->GetHeight());
out += " rowBytes:" + std::to_string(bmpImplPtr->GetRowBytes());
out += " colorType:" + std::to_string(static_cast<int>(bmpImplPtr->GetColorType()));
out += " alphaType:" + std::to_string(static_cast<int>(bmpImplPtr->GetAlphaType()));
out += "]";
out += '[';
if (bmpImplPtr != nullptr) {
out += "width:" + std::to_string(bmpImplPtr->GetWidth());
out += " height:" + std::to_string(bmpImplPtr->GetHeight());
out += " rowBytes:" + std::to_string(bmpImplPtr->GetRowBytes());
out += " colorType:" + std::to_string(static_cast<int>(bmpImplPtr->GetColorType()));
out += " alphaType:" + std::to_string(static_cast<int>(bmpImplPtr->GetAlphaType()));
}
out += ']';
}
} // namespace Drawing
} // namespace Rosen

View File

@ -18,9 +18,8 @@
#include <functional>
#include <set>
#include "trace_memory_dump.h"
#include "impl_interface/gpu_context_impl.h"
#include "trace_memory_dump.h"
#include "utils/data.h"
#include "utils/drawing_macros.h"

View File

@ -179,11 +179,11 @@ public:
*/
void GenerateCache(Canvas* canvas = nullptr, const Rect* rect = nullptr);
bool GetIsCache();
bool GetIsCache() const;
void SetIsCache(bool isCached);
bool GetCachedHighContrast();
bool GetCachedHighContrast() const;
void SetCachedHighContrast(bool cachedHighContrast);

View File

@ -115,6 +115,16 @@ public:
void PostScale(scalar sx, scalar sy);
/**
* @brief Sets Matrix to Matrix constructed from scaling by (sx, sy)
* about pivot point(px,py), multiplied by Matrix.
* @param sx horizontal scale factor
* @param sy vertical scale factor
* @param px pivot on x-axis
* @param px pivot on y-axis
*/
void PostScale(scalar sx, scalar sy, scalar px, scalar py);
/**
* @brief Sets Matrix to Matrix multiplied by Matrix constructed
* from skewing by (kx, ky) about pivot point (0, 0).
@ -150,16 +160,6 @@ public:
* @param ky pivot on y-axis
*/
void PostSkew(scalar kx, scalar ky, scalar px, scalar py);
/**
* @brief Sets Matrix to Matrix constructed from scaling by (sx, sy)
* about pivot point(px,py), multiplied by Matrix.
* @param sx horizontal scale factor
* @param sy vertical scale factor
* @param px pivot on x-axis
* @param px pivot on y-axis
*/
void PostScale(scalar sx, scalar sy, scalar px, scalar py);
/**
* @brief Sets Matrix to Matrix other multiplied by Matrix.

View File

@ -133,13 +133,16 @@ private:
inline void Region::Dump(std::string& out) const
{
out += "[empty:" + std::string(impl_->IsEmpty() ? "true" : "false");
out += " isRect:" + std::string(impl_->IsRect() ? "true" : "false");
out += " BoundaryPath";
Path path;
impl_->GetBoundaryPath(&path);
path.Dump(out);
out += "]";
out += '[';
if (impl_ != nullptr) {
out += "empty:" + std::string(impl_->IsEmpty() ? "true" : "false");
out += " isRect:" + std::string(impl_->IsRect() ? "true" : "false");
out += " BoundaryPath";
Path path;
impl_->GetBoundaryPath(&path);
path.Dump(out);
}
out += ']';
}
} // namespace Drawing
} // namespace Rosen

View File

@ -38,8 +38,6 @@ class Surface;
struct FlushInfo;
#ifdef RS_ENABLE_GPU
struct FrameBuffer;
class ImageInfo;
class GPUContext;
#endif
enum class BackendAccess;

View File

@ -62,50 +62,46 @@ public:
}
protected:
sk_sp<SkSurface> onNewSurface(const SkImageInfo&, const SkSurfaceProps&) override;
SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override;
bool onDoSaveBehind(const SkRect* rect) override;
bool onDoSaveBehind(const SkRect*) override;
void onDrawPaint(const SkPaint&) override;
void onDrawBehind(const SkPaint&) override;
void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) override;
void onDrawRect(const SkRect&, const SkPaint&) override;
void onDrawRRect(const SkRRect&, const SkPaint&) override;
void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
void onDrawRegion(const SkRegion&, const SkPaint&) override;
void onDrawRRect(const SkRRect&, const SkPaint&) override;
void onDrawRect(const SkRect&, const SkPaint&) override;
void onDrawOval(const SkRect&, const SkPaint&) override;
void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override;
void onDrawRegion(const SkRegion&, const SkPaint&) override;
void onDrawPath(const SkPath&, const SkPaint&) override;
void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override;
bool onPeekPixels(SkPixmap* pixmap) override;
void onDrawImage2(const SkImage*, SkScalar, SkScalar, const SkSamplingOptions&,
const SkPaint*) override;
void onDrawImageRect2(const SkImage*, const SkRect&, const SkRect&, const SkSamplingOptions&,
const SkPaint*, SrcRectConstraint) override;
void onDrawImageLattice2(const SkImage*, const Lattice&, const SkRect&, SkFilterMode,
const SkPaint*) override;
void onDrawAtlas2(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[], int,
SkBlendMode, const SkSamplingOptions&, const SkRect*, const SkPaint*) override;
void onDrawImage2(const SkImage*, SkScalar, SkScalar, const SkSamplingOptions&, const SkPaint*) override;
void onDrawImageRect2(const SkImage*, const SkRect&, const SkRect&, const SkSamplingOptions&, const SkPaint*,
SrcRectConstraint) override;
void onDrawImageLattice2(const SkImage*, const Lattice&, const SkRect&, SkFilterMode, const SkPaint*) override;
void onDrawAtlas2(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[], int, SkBlendMode,
const SkSamplingOptions&, const SkRect*, const SkPaint*) override;
bool onAccessTopLayerPixels(SkPixmap* pixmap) override;
void onDrawVerticesObject(const SkVertices*, SkBlendMode, const SkPaint&) override;
void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
const SkPoint texCoords[4], SkBlendMode, const SkPaint& paint) override;
void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], const SkPoint texCoords[4],
SkBlendMode, const SkPaint& paint) override;
void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override;
void onDrawDrawable(SkDrawable*, const SkMatrix*) override;
SkImageInfo onImageInfo() const override;
void onDrawGlyphRunList(const SkGlyphRunList&, const SkPaint&) override;
void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
const SkPaint& paint) override;
void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint) override;
void onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) override;
void onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rec) override;
void onDrawEdgeAAQuad(const SkRect&, const SkPoint[4], QuadAAFlags, const SkColor4f&,
SkBlendMode) override;
void onDrawEdgeAAQuad(const SkRect&, const SkPoint[4], QuadAAFlags, const SkColor4f&, SkBlendMode) override;
void onDrawEdgeAAImageSet2(const ImageSetEntry[], int count, const SkPoint[], const SkMatrix[],
const SkSamplingOptions&, const SkPaint*, SrcRectConstraint) override;
// draw on actual canvas
sk_sp<SkSurface> onNewSurface(const SkImageInfo&, const SkSurfaceProps&) override;
bool onPeekPixels(SkPixmap* pixmap) override;
bool onAccessTopLayerPixels(SkPixmap* pixmap) override;
SkImageInfo onImageInfo() const override;
bool onGetProps(SkSurfaceProps* props) const override;
private:

View File

@ -19,12 +19,12 @@
#include "include/core/SkFontTypes.h"
#include "include/core/SkPath.h"
#include "include/utils/SkTextUtils.h"
#include "src/core/SkFontPriv.h"
#include "skia_adapter/skia_convert_utils.h"
#include "skia_adapter/skia_typeface.h"
#include "skia_path.h"
#include "skia_typeface.h"
#include "src/core/SkFontPriv.h"
#include "text/font.h"
#include "utils/log.h"

View File

@ -28,6 +28,7 @@
namespace OHOS {
namespace Rosen {
namespace Drawing {
static std::mutex g_registarMutex;
SkiaPersistentCache::SkiaPersistentCache(GPUContextOptions::PersistentCache* cache) : cache_(cache) {}
sk_sp<SkData> SkiaPersistentCache::load(const SkData& key)
@ -434,6 +435,7 @@ std::unordered_map<uintptr_t, std::function<void(const std::function<void()>& ta
void SkiaGPUContext::RegisterPostFunc(const std::function<void(const std::function<void()>& task)>& func)
{
std::unique_lock lock(g_registarMutex);
if (grContext_ != nullptr) {
contextPostMap_[uintptr_t(grContext_.get())] = func;
}
@ -441,6 +443,7 @@ void SkiaGPUContext::RegisterPostFunc(const std::function<void(const std::functi
std::function<void(const std::function<void()>& task)> SkiaGPUContext::GetPostFunc(sk_sp<GrDirectContext> grContext)
{
std::unique_lock lock(g_registarMutex);
if (grContext != nullptr && contextPostMap_.count(uintptr_t(grContext.get())) > 0) {
return contextPostMap_[uintptr_t(grContext.get())];
}

View File

@ -239,7 +239,7 @@ std::shared_ptr<Surface> SkiaSurface::MakeFromBackendTexture(GPUContext* gpuCont
sk_sp<SkSurface> skSurface = nullptr;
SkSurfaceProps surfaceProps(0, SkPixelGeometry::kUnknown_SkPixelGeometry);
#ifdef RS_ENABLE_VK
if (SystemProperties::IsUseVulkan()) {
if (SystemProperties::GetGpuApiType() == GpuApiType::VULKAN) {
GrVkImageInfo image_info;
SkiaTextureInfo::ConvertToGrBackendTexture(info).getVkImageInfo(&image_info);
GrBackendTexture backendRenderTarget(info.GetWidth(), info.GetHeight(), image_info);
@ -250,7 +250,7 @@ std::shared_ptr<Surface> SkiaSurface::MakeFromBackendTexture(GPUContext* gpuCont
}
#endif
#ifdef RS_ENABLE_GL
if (!SystemProperties::IsUseVulkan()) {
if (SystemProperties::GetGpuApiType() == GpuApiType::OPENGL) {
GrBackendTexture glBackendTexture = SkiaTextureInfo::ConvertToGrBackendTexture(info);
skSurface = SkSurface::MakeFromBackendTexture(grContext.get(),
glBackendTexture, SkiaTextureInfo::ConvertToGrSurfaceOrigin(origin),
@ -526,7 +526,6 @@ void SkiaSurface::Wait(int32_t time, const VkSemaphore& semaphore)
if (!SystemProperties::IsUseVulkan()) {
return;
}
if (skSurface_ == nullptr) {
LOGD("skSurface is nullptr");
return;

View File

@ -1845,16 +1845,16 @@ std::shared_ptr<DrawImageRectOpItem> DrawTextBlobOpItem::GenerateCachedOpItem(Ca
void DrawTextBlobOpItem::DumpItems(std::string& out) const
{
out += " scalarX:" + std::to_string(x_) + " scalarY:" + std::to_string(y_);
if (textBlob_) {
if (textBlob_ != nullptr) {
out += " TextBlob[";
out += "UniqueID:" + std::to_string(textBlob_->UniqueID());
auto bounds = textBlob_->Bounds();
if (bounds) {
if (bounds != nullptr) {
out += " Bounds";
bounds->Dump(out);
}
out += " isEmoji:" + std::string(textBlob_->IsEmoji() ? "true" : "false");
out += "]";
out += ']';
}
}

View File

@ -361,7 +361,7 @@ void DrawCmdList::GenerateCache(Canvas* canvas, const Rect* rect)
#endif
}
bool DrawCmdList::GetIsCache()
bool DrawCmdList::GetIsCache() const
{
return isCached_;
}
@ -371,7 +371,7 @@ void DrawCmdList::SetIsCache(bool isCached)
isCached_ = isCached;
}
bool DrawCmdList::GetCachedHighContrast()
bool DrawCmdList::GetCachedHighContrast() const
{
return cachedHighContrast_;
}
@ -463,6 +463,12 @@ void DrawCmdList::GenerateCacheByBuffer(Canvas* canvas, const Rect* rect)
bool replaceSuccess = player.GenerateCachedOpItem(curOpItemPtr->GetType(), itemPtr, avaliableSize);
if (replaceSuccess) {
replacedOpListForBuffer_.push_back({offset, lastOpItemOffset_.value()});
itemPtr = opAllocator_.OffsetToAddr(offset, sizeof(OpItem));
curOpItemPtr = static_cast<OpItem*>(itemPtr);
if (curOpItemPtr == nullptr) {
LOGE("DrawCmdList::GenerateCache failed, opItem is nullptr");
break;
}
}
offset = curOpItemPtr->GetNextOpItemOffset();
} while (offset != 0 && offset < maxOffset);