mirror of
https://gitee.com/openharmony/graphic_graphic_2d
synced 2024-12-03 12:53:54 +00:00
cleancode for drawing
Signed-off-by: HengmingWang <wanghengming@huawei.com>
This commit is contained in:
parent
cfad725655
commit
28423ef0c9
@ -793,7 +793,7 @@ napi_value JsCanvas::OnDrawPixelMapMesh(napi_env env, napi_callback_info info)
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid vertices params.");
|
||||
}
|
||||
|
||||
float vertices[verticesSize];
|
||||
auto vertices = new float[verticesSize];
|
||||
for (uint32_t i = 0; i < verticesSize; i++) {
|
||||
napi_value tempVertex = nullptr;
|
||||
napi_get_element(env, verticesArray, i, &tempVertex);
|
||||
@ -801,6 +801,7 @@ napi_value JsCanvas::OnDrawPixelMapMesh(napi_env env, napi_callback_info info)
|
||||
bool isVertexOk = ConvertFromJsValue(env, tempVertex, vertex);
|
||||
if (!isVertexOk) {
|
||||
ROSEN_LOGE("JsCanvas::OnDrawPixelMapMesh vertex is invalid");
|
||||
delete []vertices;
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
vertices[i] = vertex;
|
||||
@ -817,19 +818,23 @@ napi_value JsCanvas::OnDrawPixelMapMesh(napi_env env, napi_callback_info info)
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid colors params.");
|
||||
}
|
||||
|
||||
uint32_t colors[colorsSize];
|
||||
for (uint32_t i = 0; i < colorsSize; i++) {
|
||||
napi_value tempColor = nullptr;
|
||||
napi_get_element(env, colorsArray, i, &tempColor);
|
||||
uint32_t color = 0;
|
||||
bool isColorOk = ConvertFromJsValue(env, tempColor, color);
|
||||
if (!isColorOk) {
|
||||
ROSEN_LOGE("JsCanvas::OnDrawPixelMapMesh color is invalid");
|
||||
return NapiGetUndefined(env);
|
||||
uint32_t* colorsMesh = nullptr;
|
||||
if (colorsSize != 0) {
|
||||
auto colors = new uint32_t[colorsSize];
|
||||
for (uint32_t i = 0; i < colorsSize; i++) {
|
||||
napi_value tempColor = nullptr;
|
||||
napi_get_element(env, colorsArray, i, &tempColor);
|
||||
uint32_t color = 0;
|
||||
bool isColorOk = ConvertFromJsValue(env, tempColor, color);
|
||||
if (!isColorOk) {
|
||||
ROSEN_LOGE("JsCanvas::OnDrawPixelMapMesh color is invalid");
|
||||
delete []colors;
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
colors[i] = color;
|
||||
}
|
||||
colors[i] = color;
|
||||
colorsMesh = colors + colorOffset;
|
||||
}
|
||||
uint32_t* colorsMesh = colorsSize ? (colors + colorOffset) : nullptr;
|
||||
|
||||
DrawingPixelMapMesh(pixelMap, column, row, verticesMesh, colorsMesh, m_canvas);
|
||||
|
||||
|
@ -159,7 +159,7 @@ public:
|
||||
*/
|
||||
void SetImmutable();
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Replaces pixel values with c, interpreted as being in the sRGB ColorSpace.
|
||||
* @param color unpremultiplied color
|
||||
*/
|
||||
|
@ -209,12 +209,12 @@ void SkiaCanvas::DrawSdf(const SDFShapeBase& shape)
|
||||
uint64_t num = para.size();
|
||||
for (uint64_t i = 1; i <= num; i++) {
|
||||
char buf[10] = {0}; // maximum length of string needed is 10.
|
||||
(void)sprintf_s(buf, sizeof(buf), "para%d", i);
|
||||
(void)sprintf_s(buf, sizeof(buf), "para%lld", i);
|
||||
builder.uniform(buf) = para[i-1];
|
||||
}
|
||||
for (uint64_t i = 1; i <= num1; i++) {
|
||||
char buf[15] = {0}; // maximum length of string needed is 15.
|
||||
(void)sprintf_s(buf, sizeof(buf), "transpara%d", i);
|
||||
(void)sprintf_s(buf, sizeof(buf), "transpara%lld", i);
|
||||
builder.uniform(buf) = para1[i-1];
|
||||
}
|
||||
std::vector<float> color = shape.GetColorPara();
|
||||
|
@ -181,7 +181,7 @@ private:
|
||||
std::shared_ptr<SkCanvas> skiaCanvas_;
|
||||
SkCanvas* skCanvas_;
|
||||
// opinc_begin
|
||||
SkCanvas* skCanvasBackup_;
|
||||
SkCanvas* skCanvasBackup_ = nullptr;
|
||||
std::shared_ptr<SkiaCanvasOp> skiaCanvasOp_ = nullptr;
|
||||
// opinc_end
|
||||
SkiaPaint skiaPaint_;
|
||||
|
@ -24,15 +24,15 @@ namespace OHOS {
|
||||
namespace Rosen {
|
||||
class RSB_EXPORT RSShader {
|
||||
public:
|
||||
RSShader() = default;
|
||||
~RSShader() = default;
|
||||
static std::shared_ptr<RSShader> CreateRSShader();
|
||||
static std::shared_ptr<RSShader> CreateRSShader(const std::shared_ptr<Drawing::ShaderEffect>& drShader);
|
||||
|
||||
void SetDrawingShader(const std::shared_ptr<Drawing::ShaderEffect>& drShader);
|
||||
const std::shared_ptr<Drawing::ShaderEffect>& GetDrawingShader() const;
|
||||
~RSShader() = default;
|
||||
|
||||
private:
|
||||
RSShader() = default;
|
||||
RSShader(const RSShader&) = delete;
|
||||
RSShader(const RSShader&&) = delete;
|
||||
RSShader& operator=(const RSShader&) = delete;
|
||||
|
@ -516,8 +516,8 @@ bool RSMarshallingHelper::Marshalling(Parcel& parcel, const Drawing::Matrix& val
|
||||
{
|
||||
Drawing::Matrix::Buffer buffer;
|
||||
val.GetAll(buffer);
|
||||
int32_t size = buffer.size() * sizeof(Drawing::scalar);
|
||||
bool ret = parcel.WriteInt32(size);
|
||||
uint32_t size = buffer.size() * sizeof(Drawing::scalar);
|
||||
bool ret = parcel.WriteUint32(size);
|
||||
ret &= RSMarshallingHelper::WriteToParcel(parcel, buffer.data(), size);
|
||||
if (!ret) {
|
||||
ROSEN_LOGE("unirender: failed RSMarshallingHelper::Marshalling Drawing::Matrix");
|
||||
@ -527,7 +527,7 @@ bool RSMarshallingHelper::Marshalling(Parcel& parcel, const Drawing::Matrix& val
|
||||
|
||||
bool RSMarshallingHelper::Unmarshalling(Parcel& parcel, Drawing::Matrix& val)
|
||||
{
|
||||
int32_t size = parcel.ReadInt32();
|
||||
uint32_t size = parcel.ReadUint32();
|
||||
if (size < sizeof(Drawing::scalar) * Drawing::Matrix::MATRIX_SIZE) {
|
||||
ROSEN_LOGE("RSMarshallingHelper::Unmarshalling Drawing::Matrix failed size %{public}d", size);
|
||||
return false;
|
||||
|
@ -316,7 +316,7 @@ void RSSvgDomMaskDrawable::Draw(const RSRenderContent& content, RSPaintFilterCan
|
||||
canvas.Save();
|
||||
Drawing::SaveLayerOps slr(&bounds, nullptr);
|
||||
canvas.SaveLayer(slr);
|
||||
int tmpLayer = canvas.GetSaveCount();
|
||||
uint32_t tmpLayer = canvas.GetSaveCount();
|
||||
Drawing::SaveLayerOps slrMask(&bounds, &maskFilterBrush_);
|
||||
canvas.SaveLayer(slrMask);
|
||||
{
|
||||
@ -340,7 +340,7 @@ void RSSvgPictureMaskDrawable::Draw(const RSRenderContent& content, RSPaintFilte
|
||||
canvas.Save();
|
||||
Drawing::SaveLayerOps slr(&bounds, nullptr);
|
||||
canvas.SaveLayer(slr);
|
||||
int tmpLayer = canvas.GetSaveCount();
|
||||
uint32_t tmpLayer = canvas.GetSaveCount();
|
||||
Drawing::SaveLayerOps slrMask(&bounds, &maskFilterBrush_);
|
||||
canvas.SaveLayer(slrMask);
|
||||
{
|
||||
@ -364,7 +364,7 @@ void RSGradientMaskDrawable::Draw(const RSRenderContent& content, RSPaintFilterC
|
||||
canvas.Save();
|
||||
Drawing::SaveLayerOps slr(&bounds, nullptr);
|
||||
canvas.SaveLayer(slr);
|
||||
int tmpLayer = canvas.GetSaveCount();
|
||||
uint32_t tmpLayer = canvas.GetSaveCount();
|
||||
Drawing::SaveLayerOps slrMask(&bounds, &maskFilterBrush_);
|
||||
canvas.SaveLayer(slrMask);
|
||||
{
|
||||
@ -391,7 +391,7 @@ void RSPathMaskDrawable::Draw(const RSRenderContent& content, RSPaintFilterCanva
|
||||
canvas.Save();
|
||||
Drawing::SaveLayerOps slr(&bounds, nullptr);
|
||||
canvas.SaveLayer(slr);
|
||||
int tmpLayer = canvas.GetSaveCount();
|
||||
uint32_t tmpLayer = canvas.GetSaveCount();
|
||||
Drawing::SaveLayerOps slrMask(&bounds, &maskFilterBrush_);
|
||||
canvas.SaveLayer(slrMask);
|
||||
{
|
||||
|
@ -19,13 +19,12 @@ namespace OHOS {
|
||||
namespace Rosen {
|
||||
std::shared_ptr<RSShader> RSShader::CreateRSShader()
|
||||
{
|
||||
std::shared_ptr<RSShader> rsShader(new RSShader());
|
||||
return rsShader;
|
||||
return std::make_shared<RSShader>();
|
||||
}
|
||||
|
||||
std::shared_ptr<RSShader> RSShader::CreateRSShader(const std::shared_ptr<Drawing::ShaderEffect>& drShader)
|
||||
{
|
||||
std::shared_ptr<RSShader> rsShader(new RSShader());
|
||||
auto rsShader = std::make_shared<RSShader>();
|
||||
rsShader->SetDrawingShader(drShader);
|
||||
return rsShader;
|
||||
}
|
||||
|
@ -69,7 +69,8 @@ public:
|
||||
void CreatePyhsicalScreen();
|
||||
void DoPrepareCompleted(sptr<Surface>& surface, const struct PrepareCompleteParam ¶m);
|
||||
void OnBufferAvailable() override;
|
||||
SurfaceError ProduceBuffer(sptr<Surface> &produceSurface, uint32_t width, uint32_t height, uint32_t index, bool baseLayer);
|
||||
SurfaceError ProduceBuffer(sptr<Surface> &produceSurface, uint32_t width,
|
||||
uint32_t height, uint32_t index, bool baseLayer);
|
||||
bool FillBaseLayer(std::shared_ptr<HdiLayerInfo> &showLayer, uint32_t index, uint32_t zorder,
|
||||
GraphicIRect &dstRect);
|
||||
bool DrawBaseLayer(std::vector<LayerInfoPtr> &layerVec);
|
||||
@ -185,7 +186,6 @@ void HelloDrawing::TestDrawImage(Canvas& canvas, uint32_t width, uint32_t height
|
||||
|
||||
void HelloDrawing::DoDrawData(void *image, uint32_t width, uint32_t height)
|
||||
{
|
||||
|
||||
Bitmap bitmap;
|
||||
BitmapFormat format {COLORTYPE_RGBA_8888, ALPHATYPE_OPAQUE};
|
||||
bitmap.Build(width, height, format);
|
||||
@ -532,7 +532,7 @@ void HelloDrawing::OnHotPlugEvent(std::shared_ptr<HdiOutput> &output, bool conne
|
||||
if (connected) {
|
||||
CreatePyhsicalScreen();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HelloDrawing::DoPrepareCompleted(sptr<Surface>& surface, const struct PrepareCompleteParam ¶m)
|
||||
{
|
||||
|
@ -267,7 +267,7 @@ void TestDrawImage(Canvas& canvas, uint32_t width, uint32_t height)
|
||||
SamplingOptions sampling = SamplingOptions(Drawing::FilterMode::NEAREST, Drawing::MipmapMode::NEAREST);
|
||||
auto e = ShaderEffect::CreateImageShader(image, TileMode::REPEAT, TileMode::MIRROR, sampling, matrix);
|
||||
LOGI("sampling useCubic = %{public}d, filter = %{public}d, mipmap = %{public}d",
|
||||
sampling.GetUseCubic(), sampling.GetFilterMode(), sampling.GetMipmapMode());
|
||||
sampling.GetUseCubic(), sampling.GetFilterMode(), sampling.GetMipmapMode());
|
||||
auto c = Drawing::ColorSpace::CreateRefImage(image);
|
||||
|
||||
Pen pen;
|
||||
@ -318,7 +318,8 @@ void TestPicture(Canvas& canvas, uint32_t width, uint32_t height)
|
||||
image.BuildFromPicture(picture, {50, 50}, matrix, brush, BitDepth::KU8, srgbColorSpace);
|
||||
|
||||
Drawing::Rect rect(1000, 0, 1300, 300); // The tile rectangle size in picture coordinates.
|
||||
auto e = ShaderEffect::CreatePictureShader(picture, TileMode::REPEAT, TileMode::MIRROR, FilterMode::NEAREST, matrix, rect);
|
||||
auto e = ShaderEffect::CreatePictureShader(picture, TileMode::REPEAT, TileMode::MIRROR,
|
||||
FilterMode::NEAREST, matrix, rect);
|
||||
Pen pen;
|
||||
pen.SetAntiAlias(true);
|
||||
pen.SetColor(Drawing::Color::COLOR_BLUE);
|
||||
@ -459,7 +460,8 @@ std::unique_ptr<PixelMap> ConstructPixmap()
|
||||
info.alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
|
||||
info.colorSpace = Media::ColorSpace::SRGB;
|
||||
pixelMap->SetImageInfo(info);
|
||||
LOGI("Constructed pixelMap info: width = %{public}d, height = %{public}d, pixelformat = %{public}d, alphatype = %{public}d, colorspace = %{public}d",
|
||||
LOGI("Constructed pixelMap info: width = %{public}d, height = %{public}d, pixelformat = %{public}d, "
|
||||
"alphatype = %{public}d, colorspace = %{public}d",
|
||||
info.size.width, info.size.height, info.pixelFormat, info.alphaType, info.colorSpace);
|
||||
|
||||
uint32_t rowDataSize = pixelMapWidth;
|
||||
|
Loading…
Reference in New Issue
Block a user