• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef USE_ROSEN_DRAWING
17 
18 #include "pipeline/rs_draw_cmd.h"
19 #ifdef ROSEN_OHOS
20 #include "buffer_utils.h"
21 #endif
22 #ifdef NEW_SKIA
23 #include "include/gpu/GrDirectContext.h"
24 #else
25 #include "include/gpu/GrContext.h"
26 #endif
27 #include "message_parcel.h"
28 #include "rs_trace.h"
29 #include "securec.h"
30 
31 #include "pipeline/rs_paint_filter_canvas.h"
32 #include "pipeline/rs_root_render_node.h"
33 #include "platform/common/rs_log.h"
34 #include "platform/common/rs_system_properties.h"
35 #include "render/rs_pixel_map_util.h"
36 
37 namespace OHOS {
38 namespace Rosen {
39 namespace {
40 constexpr int32_t CORNER_SIZE = 4;
SimplifyPaint(uint32_t color,SkPaint * paint)41 void SimplifyPaint(uint32_t color, SkPaint* paint)
42 {
43     paint->setColor(color);
44     paint->setShader(nullptr);
45     paint->setColorFilter(nullptr);
46     paint->setStrokeWidth(1.04); // 1.04 is empirical value
47     paint->setStrokeJoin(SkPaint::kRound_Join);
48 }
49 } // namespace
50 
Instance()51 OpItemTasks& OpItemTasks::Instance()
52 {
53     static OpItemTasks instance;
54     return instance;
55 }
56 
AddTask(std::function<void ()> task)57 void OpItemTasks::AddTask(std::function<void()> task)
58 {
59     std::lock_guard<std::mutex> lock(mutex_);
60     tasks_.push_back(task);
61 }
62 
ProcessTask()63 void OpItemTasks::ProcessTask()
64 {
65     std::vector<std::function<void()>> tasks = {};
66     {
67         std::lock_guard<std::mutex> lock(mutex_);
68         std::swap(tasks, tasks_);
69     }
70     for (auto& task : tasks) {
71         task();
72     }
73 }
74 
IsEmpty()75 bool OpItemTasks::IsEmpty()
76 {
77     std::lock_guard<std::mutex> lock(mutex_);
78     return tasks_.empty();
79 }
80 
GenerateCachedOpItem(const RSPaintFilterCanvas * canvas,const SkRect * rect) const81 std::unique_ptr<OpItem> OpItemWithPaint::GenerateCachedOpItem(
82     const RSPaintFilterCanvas* canvas, const SkRect* rect) const
83 {
84     // check if this opItem can be cached
85     auto optionalBounds = GetCacheBounds();
86     if (!optionalBounds.has_value() || optionalBounds.value().isEmpty()) {
87         return nullptr;
88     }
89     auto& bounds = optionalBounds.value();
90 
91     // create surface & canvas to draw onto
92     sk_sp<SkSurface> offscreenSurface = nullptr;
93     if (auto surface = canvas != nullptr ? canvas->GetSurface() : nullptr) {
94         // create GPU accelerated surface if possible
95         offscreenSurface = surface->makeSurface(bounds.width(), bounds.height());
96     } else {
97         // create CPU raster surface
98         auto offscreenInfo =
99             SkImageInfo::Make(bounds.width(), bounds.height(), kRGBA_8888_SkColorType, kPremul_SkAlphaType);
100         offscreenSurface = SkSurface::MakeRaster(offscreenInfo);
101     }
102     // check if surface is created successfully
103     if (offscreenSurface == nullptr) {
104         RS_LOGW("OpItem::GenerateCachedOpItem Failed to create offscreen surface, abort caching");
105         return nullptr;
106     }
107     // create offscreen canvas and copy configuration from current canvas
108     auto offscreenCanvas = std::make_unique<RSPaintFilterCanvas>(offscreenSurface.get());
109     if (canvas) {
110         offscreenCanvas->CopyConfiguration(*canvas);
111     }
112 
113     // align draw op to [0, 0]
114     if (bounds.left() != 0 || bounds.top() != 0) {
115         offscreenCanvas->translate(-bounds.left(), -bounds.top());
116     }
117 
118     // draw on the bitmap.
119     Draw(*offscreenCanvas, rect);
120 
121     // generate BitmapOpItem with correct offset
122     SkPaint paint;
123     paint.setAntiAlias(true);
124     if (paint_.getColor() == 0x00000001) {
125 #ifdef NEW_SKIA
126         return std::make_unique<BitmapOpItem>(offscreenSurface->makeImageSnapshot(), bounds.x(), bounds.y(),
127             SkSamplingOptions(), &paint);
128 #else
129         return std::make_unique<BitmapOpItem>(offscreenSurface->makeImageSnapshot(), bounds.x(), bounds.y(), &paint);
130 #endif
131     } else {
132 #ifdef NEW_SKIA
133         return std::make_unique<ColorFilterBitmapOpItem>(
134             offscreenSurface->makeImageSnapshot(), bounds.x(), bounds.y(), SkSamplingOptions(), &paint);
135 #else
136         return std::make_unique<ColorFilterBitmapOpItem>(
137             offscreenSurface->makeImageSnapshot(), bounds.x(), bounds.y(), &paint);
138 #endif
139     }
140 }
141 
Draw(RSPaintFilterCanvas & canvas,const SkRect * rect) const142 void OpItemWithRSImage::Draw(RSPaintFilterCanvas& canvas, const SkRect* rect) const
143 {
144     if (rsImage_) {
145 #ifdef NEW_SKIA
146         rsImage_->DrawImage(canvas, samplingOptions_, paint_);
147 #else
148         rsImage_->DrawImage(canvas, paint_);
149 #endif
150     }
151 }
152 
RectOpItem(SkRect rect,const SkPaint & paint)153 RectOpItem::RectOpItem(SkRect rect, const SkPaint& paint) : OpItemWithPaint(sizeof(RectOpItem)), rect_(rect)
154 {
155     paint_ = paint;
156 }
157 
Draw(RSPaintFilterCanvas & canvas,const SkRect *) const158 void RectOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect*) const
159 {
160     canvas.drawRect(rect_, paint_);
161 }
162 
RoundRectOpItem(const SkRRect & rrect,const SkPaint & paint)163 RoundRectOpItem::RoundRectOpItem(const SkRRect& rrect, const SkPaint& paint)
164     : OpItemWithPaint(sizeof(RoundRectOpItem)), rrect_(rrect)
165 {
166     paint_ = paint;
167 }
168 
Draw(RSPaintFilterCanvas & canvas,const SkRect *) const169 void RoundRectOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect*) const
170 {
171     canvas.drawRRect(rrect_, paint_);
172 }
173 
DRRectOpItem(const SkRRect & outer,const SkRRect & inner,const SkPaint & paint)174 DRRectOpItem::DRRectOpItem(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint)
175     : OpItemWithPaint(sizeof(DRRectOpItem))
176 {
177     outer_ = outer;
178     inner_ = inner;
179     paint_ = paint;
180 }
181 
Draw(RSPaintFilterCanvas & canvas,const SkRect *) const182 void DRRectOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect*) const
183 {
184     canvas.drawDRRect(outer_, inner_, paint_);
185 }
186 
OvalOpItem(SkRect rect,const SkPaint & paint)187 OvalOpItem::OvalOpItem(SkRect rect, const SkPaint& paint) : OpItemWithPaint(sizeof(OvalOpItem)), rect_(rect)
188 {
189     paint_ = paint;
190 }
191 
Draw(RSPaintFilterCanvas & canvas,const SkRect *) const192 void OvalOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect*) const
193 {
194     canvas.drawOval(rect_, paint_);
195 }
196 
RegionOpItem(SkRegion region,const SkPaint & paint)197 RegionOpItem::RegionOpItem(SkRegion region, const SkPaint& paint) : OpItemWithPaint(sizeof(RegionOpItem))
198 {
199     region_ = region;
200     paint_ = paint;
201 }
202 
Draw(RSPaintFilterCanvas & canvas,const SkRect *) const203 void RegionOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect*) const
204 {
205     canvas.drawRegion(region_, paint_);
206 }
207 
ArcOpItem(const SkRect & rect,float startAngle,float sweepAngle,bool useCenter,const SkPaint & paint)208 ArcOpItem::ArcOpItem(const SkRect& rect, float startAngle, float sweepAngle, bool useCenter, const SkPaint& paint)
209     : OpItemWithPaint(sizeof(ArcOpItem)), rect_(rect), startAngle_(startAngle), sweepAngle_(sweepAngle),
210       useCenter_(useCenter)
211 {
212     paint_ = paint;
213 }
214 
Draw(RSPaintFilterCanvas & canvas,const SkRect *) const215 void ArcOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect*) const
216 {
217     canvas.drawArc(rect_, startAngle_, sweepAngle_, useCenter_, paint_);
218 }
219 
SaveOpItem()220 SaveOpItem::SaveOpItem() : OpItem(sizeof(SaveOpItem)) {}
221 
Draw(RSPaintFilterCanvas & canvas,const SkRect *) const222 void SaveOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect*) const
223 {
224     canvas.save();
225 }
226 
RestoreOpItem()227 RestoreOpItem::RestoreOpItem() : OpItem(sizeof(RestoreOpItem)) {}
228 
Draw(RSPaintFilterCanvas & canvas,const SkRect *) const229 void RestoreOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect*) const
230 {
231     canvas.restore();
232 }
233 
FlushOpItem()234 FlushOpItem::FlushOpItem() : OpItem(sizeof(FlushOpItem)) {}
235 
Draw(RSPaintFilterCanvas & canvas,const SkRect *) const236 void FlushOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect*) const
237 {
238     canvas.flush();
239 }
240 
241 #ifdef NEW_SKIA
MatrixOpItem(const SkM44 & matrix)242 MatrixOpItem::MatrixOpItem(const SkM44& matrix) : OpItem(sizeof(MatrixOpItem)), matrix_(matrix) {}
243 #else
MatrixOpItem(const SkMatrix & matrix)244 MatrixOpItem::MatrixOpItem(const SkMatrix& matrix) : OpItem(sizeof(MatrixOpItem)), matrix_(matrix) {}
245 #endif
246 
Draw(RSPaintFilterCanvas & canvas,const SkRect *) const247 void MatrixOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect*) const
248 {
249     canvas.setMatrix(matrix_);
250 }
251 
ClipRectOpItem(const SkRect & rect,SkClipOp op,bool doAA)252 ClipRectOpItem::ClipRectOpItem(const SkRect& rect, SkClipOp op, bool doAA)
253     : OpItem(sizeof(ClipRectOpItem)), rect_(rect), clipOp_(op), doAA_(doAA)
254 {}
255 
Draw(RSPaintFilterCanvas & canvas,const SkRect *) const256 void ClipRectOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect*) const
257 {
258     canvas.clipRect(rect_, clipOp_, doAA_);
259 }
260 
ClipRRectOpItem(const SkRRect & rrect,SkClipOp op,bool doAA)261 ClipRRectOpItem::ClipRRectOpItem(const SkRRect& rrect, SkClipOp op, bool doAA)
262     : OpItem(sizeof(ClipRRectOpItem)), rrect_(rrect), clipOp_(op), doAA_(doAA)
263 {}
264 
Draw(RSPaintFilterCanvas & canvas,const SkRect *) const265 void ClipRRectOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect*) const
266 {
267     canvas.clipRRect(rrect_, clipOp_, doAA_);
268 }
269 
ClipRegionOpItem(const SkRegion & region,SkClipOp op)270 ClipRegionOpItem::ClipRegionOpItem(const SkRegion& region, SkClipOp op)
271     : OpItem(sizeof(ClipRegionOpItem)), region_(region), clipOp_(op)
272 {}
273 
Draw(RSPaintFilterCanvas & canvas,const SkRect *) const274 void ClipRegionOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect*) const
275 {
276     canvas.clipRegion(region_, clipOp_);
277 }
278 
TranslateOpItem(float distanceX,float distanceY)279 TranslateOpItem::TranslateOpItem(float distanceX, float distanceY)
280     : OpItem(sizeof(TranslateOpItem)), distanceX_(distanceX), distanceY_(distanceY)
281 {}
282 
Draw(RSPaintFilterCanvas & canvas,const SkRect *) const283 void TranslateOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect*) const
284 {
285     canvas.translate(distanceX_, distanceY_);
286 }
287 
ScaleOpItem(float scaleX,float scaleY)288 ScaleOpItem::ScaleOpItem(float scaleX, float scaleY)
289     : OpItem(sizeof(ScaleOpItem)), scaleX_(scaleX), scaleY_(scaleY)
290 {}
291 
Draw(RSPaintFilterCanvas & canvas,const SkRect *) const292 void ScaleOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect*) const
293 {
294     canvas.scale(scaleX_, scaleY_);
295 }
296 
TextBlobOpItem(const sk_sp<SkTextBlob> textBlob,float x,float y,const SkPaint & paint)297 TextBlobOpItem::TextBlobOpItem(const sk_sp<SkTextBlob> textBlob, float x, float y, const SkPaint& paint)
298     : OpItemWithPaint(sizeof(TextBlobOpItem)), textBlob_(textBlob), x_(x), y_(y)
299 {
300     paint_ = paint;
301 }
302 
Draw(RSPaintFilterCanvas & canvas,const SkRect *) const303 void TextBlobOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect*) const
304 {
305     bool isHighContrastEnabled = canvas.isHighContrastEnabled();
306     if (isHighContrastEnabled) {
307         ROSEN_LOGD("TextBlobOpItem::Draw highContrastEnabled");
308         uint32_t color = paint_.getColor();
309         uint32_t channelSum = SkColorGetR(color) + SkColorGetG(color) + SkColorGetB(color);
310         bool flag = channelSum < 594; // 594 is empirical value
311 
312         SkPaint outlinePaint(paint_);
313         SimplifyPaint(flag ? SK_ColorWHITE : SK_ColorBLACK, &outlinePaint);
314         outlinePaint.setStyle(SkPaint::kStrokeAndFill_Style);
315         canvas.drawTextBlob(textBlob_, x_, y_, outlinePaint);
316 
317         SkPaint innerPaint(paint_);
318         SimplifyPaint(flag ? SK_ColorBLACK : SK_ColorWHITE, &innerPaint);
319         innerPaint.setStyle(SkPaint::kFill_Style);
320         canvas.drawTextBlob(textBlob_, x_, y_, innerPaint);
321     } else {
322         canvas.drawTextBlob(textBlob_, x_, y_, paint_);
323     }
324 }
325 
326 #ifdef NEW_SKIA
BitmapOpItem(const sk_sp<SkImage> bitmapInfo,float left,float top,const SkSamplingOptions & samplingOptions,const SkPaint * paint)327 BitmapOpItem::BitmapOpItem(const sk_sp<SkImage> bitmapInfo, float left, float top,
328     const SkSamplingOptions& samplingOptions, const SkPaint* paint)
329     : OpItemWithRSImage(samplingOptions, sizeof(BitmapOpItem)), samplingOptions_(samplingOptions)
330 {
331     if (bitmapInfo) {
332         rsImage_ = std::make_shared<RSImageBase>();
333         rsImage_->SetImage(bitmapInfo);
334         rsImage_->SetSrcRect(RectF(0, 0, bitmapInfo->width(), bitmapInfo->height()));
335         rsImage_->SetDstRect(RectF(left, top, bitmapInfo->width(), bitmapInfo->height()));
336     }
337     if (paint) {
338         paint_ = *paint;
339     }
340 }
341 
BitmapOpItem(std::shared_ptr<RSImageBase> rsImage,const SkSamplingOptions & samplingOptions,const SkPaint & paint)342 BitmapOpItem::BitmapOpItem(std::shared_ptr<RSImageBase> rsImage, const SkSamplingOptions& samplingOptions,
343     const SkPaint& paint)
344     : OpItemWithRSImage(rsImage, samplingOptions, paint, sizeof(BitmapOpItem)), samplingOptions_(samplingOptions)
345 {}
346 
ColorFilterBitmapOpItem(const sk_sp<SkImage> bitmapInfo,float left,float top,const SkSamplingOptions & samplingOptions,const SkPaint * paint)347 ColorFilterBitmapOpItem::ColorFilterBitmapOpItem(
348     const sk_sp<SkImage> bitmapInfo, float left, float top,
349     const SkSamplingOptions& samplingOptions, const SkPaint* paint)
350     : BitmapOpItem(bitmapInfo, left, top, SkSamplingOptions(), paint)
351 {}
352 
ColorFilterBitmapOpItem(std::shared_ptr<RSImageBase> rsImage,const SkSamplingOptions & samplingOptions,const SkPaint & paint)353 ColorFilterBitmapOpItem::ColorFilterBitmapOpItem(std::shared_ptr<RSImageBase> rsImage,
354     const SkSamplingOptions& samplingOptions, const SkPaint& paint)
355     : BitmapOpItem(rsImage, SkSamplingOptions(), paint)
356 {}
357 #else
BitmapOpItem(const sk_sp<SkImage> bitmapInfo,float left,float top,const SkPaint * paint)358 BitmapOpItem::BitmapOpItem(const sk_sp<SkImage> bitmapInfo, float left, float top, const SkPaint* paint)
359     : OpItemWithRSImage(sizeof(BitmapOpItem))
360 {
361     if (bitmapInfo) {
362         rsImage_ = std::make_shared<RSImageBase>();
363         rsImage_->SetImage(bitmapInfo);
364         rsImage_->SetSrcRect(RectF(0, 0, bitmapInfo->width(), bitmapInfo->height()));
365         rsImage_->SetDstRect(RectF(left, top, bitmapInfo->width(), bitmapInfo->height()));
366     }
367     if (paint) {
368         paint_ = *paint;
369     }
370 }
371 
BitmapOpItem(std::shared_ptr<RSImageBase> rsImage,const SkPaint & paint)372 BitmapOpItem::BitmapOpItem(std::shared_ptr<RSImageBase> rsImage, const SkPaint& paint)
373     : OpItemWithRSImage(rsImage, paint, sizeof(BitmapOpItem))
374 {}
375 
ColorFilterBitmapOpItem(const sk_sp<SkImage> bitmapInfo,float left,float top,const SkPaint * paint)376 ColorFilterBitmapOpItem::ColorFilterBitmapOpItem(
377     const sk_sp<SkImage> bitmapInfo, float left, float top, const SkPaint* paint)
378     : BitmapOpItem(bitmapInfo, left, top, paint)
379 {}
380 
ColorFilterBitmapOpItem(std::shared_ptr<RSImageBase> rsImage,const SkPaint & paint)381 ColorFilterBitmapOpItem::ColorFilterBitmapOpItem(std::shared_ptr<RSImageBase> rsImage, const SkPaint& paint)
382     : BitmapOpItem(rsImage, paint)
383 {}
384 #endif
385 
Draw(RSPaintFilterCanvas & canvas,const SkRect *) const386 void ColorFilterBitmapOpItem::Draw(RSPaintFilterCanvas &canvas, const SkRect *) const
387 {
388     auto colorFilterCanvas = std::make_shared<RSColorFilterCanvas>(&canvas);
389     BitmapOpItem::Draw(*colorFilterCanvas, nullptr);
390 }
391 
392 #ifdef NEW_SKIA
BitmapRectOpItem(const sk_sp<SkImage> bitmapInfo,const SkRect * rectSrc,const SkRect & rectDst,const SkSamplingOptions & samplingOptions,const SkPaint * paint,SkCanvas::SrcRectConstraint constraint)393 BitmapRectOpItem::BitmapRectOpItem(
394     const sk_sp<SkImage> bitmapInfo, const SkRect* rectSrc, const SkRect& rectDst,
395     const SkSamplingOptions& samplingOptions, const SkPaint* paint, SkCanvas::SrcRectConstraint constraint)
396     : OpItemWithRSImage(samplingOptions, sizeof(BitmapRectOpItem)),
397     samplingOptions_(samplingOptions), constraint_(constraint)
398 {
399     if (bitmapInfo) {
400         rsImage_ = std::make_shared<RSImageBase>();
401         rsImage_->SetImage(bitmapInfo);
402         rsImage_->SetSrcRect(rectSrc == nullptr ? RectF(0, 0, bitmapInfo->width(), bitmapInfo->height()) :
403                              RectF(rectSrc->left(), rectSrc->top(), rectSrc->width(), rectSrc->height()));
404         rsImage_->SetDstRect(RectF(rectDst.left(), rectDst.top(), rectDst.width(), rectDst.height()));
405     }
406     if (paint) {
407         paint_ = *paint;
408     }
409 }
410 
BitmapRectOpItem(std::shared_ptr<RSImageBase> rsImage,const SkSamplingOptions & samplingOptions,const SkPaint & paint,SkCanvas::SrcRectConstraint constraint)411 BitmapRectOpItem::BitmapRectOpItem(std::shared_ptr<RSImageBase> rsImage, const SkSamplingOptions& samplingOptions,
412     const SkPaint& paint, SkCanvas::SrcRectConstraint constraint)
413     : OpItemWithRSImage(rsImage, samplingOptions, paint, sizeof(BitmapRectOpItem)),
414     samplingOptions_(samplingOptions), constraint_(constraint)
415 {}
416 #else
BitmapRectOpItem(const sk_sp<SkImage> bitmapInfo,const SkRect * rectSrc,const SkRect & rectDst,const SkPaint * paint)417 BitmapRectOpItem::BitmapRectOpItem(
418     const sk_sp<SkImage> bitmapInfo, const SkRect* rectSrc, const SkRect& rectDst, const SkPaint* paint)
419     : OpItemWithRSImage(sizeof(BitmapRectOpItem))
420 {
421     if (bitmapInfo) {
422         rsImage_ = std::make_shared<RSImageBase>();
423         rsImage_->SetImage(bitmapInfo);
424         rsImage_->SetSrcRect(rectSrc == nullptr ? RectF(0, 0, bitmapInfo->width(), bitmapInfo->height()) :
425                              RectF(rectSrc->left(), rectSrc->top(), rectSrc->width(), rectSrc->height()));
426         rsImage_->SetDstRect(RectF(rectDst.left(), rectDst.top(), rectDst.width(), rectDst.height()));
427     }
428     if (paint) {
429         paint_ = *paint;
430     }
431 }
432 
BitmapRectOpItem(std::shared_ptr<RSImageBase> rsImage,const SkPaint & paint)433 BitmapRectOpItem::BitmapRectOpItem(std::shared_ptr<RSImageBase> rsImage, const SkPaint& paint)
434     : OpItemWithRSImage(rsImage, paint, sizeof(BitmapRectOpItem))
435 {}
436 #endif
437 
438 #ifdef NEW_SKIA
PixelMapOpItem(const std::shared_ptr<Media::PixelMap> & pixelmap,float left,float top,const SkSamplingOptions & samplingOptions,const SkPaint * paint)439 PixelMapOpItem::PixelMapOpItem(
440     const std::shared_ptr<Media::PixelMap>& pixelmap, float left, float top,
441     const SkSamplingOptions& samplingOptions, const SkPaint* paint)
442     : OpItemWithRSImage(samplingOptions, sizeof(PixelMapOpItem)), samplingOptions_(samplingOptions)
443 {
444     if (pixelmap) {
445         rsImage_ = std::make_shared<RSImageBase>();
446         rsImage_->SetPixelMap(pixelmap);
447         rsImage_->SetSrcRect(RectF(0, 0, pixelmap->GetWidth(), pixelmap->GetHeight()));
448         rsImage_->SetDstRect(RectF(left, top, pixelmap->GetWidth(), pixelmap->GetHeight()));
449     }
450     if (paint) {
451         paint_ = *paint;
452     }
453 }
454 
PixelMapOpItem(std::shared_ptr<RSImageBase> rsImage,const SkSamplingOptions & samplingOptions,const SkPaint & paint)455 PixelMapOpItem::PixelMapOpItem(std::shared_ptr<RSImageBase> rsImage, const SkSamplingOptions& samplingOptions,
456     const SkPaint& paint)
457     : OpItemWithRSImage(rsImage, samplingOptions, paint, sizeof(PixelMapOpItem)), samplingOptions_(samplingOptions)
458 {}
459 #else
PixelMapOpItem(const std::shared_ptr<Media::PixelMap> & pixelmap,float left,float top,const SkPaint * paint)460 PixelMapOpItem::PixelMapOpItem(
461     const std::shared_ptr<Media::PixelMap>& pixelmap, float left, float top, const SkPaint* paint)
462     : OpItemWithRSImage(sizeof(PixelMapOpItem))
463 {
464     if (pixelmap) {
465         rsImage_ = std::make_shared<RSImageBase>();
466         rsImage_->SetPixelMap(pixelmap);
467         rsImage_->SetSrcRect(RectF(0, 0, pixelmap->GetWidth(), pixelmap->GetHeight()));
468         rsImage_->SetDstRect(RectF(left, top, pixelmap->GetWidth(), pixelmap->GetHeight()));
469     }
470     if (paint) {
471         paint_ = *paint;
472     }
473 }
474 
PixelMapOpItem(std::shared_ptr<RSImageBase> rsImage,const SkPaint & paint)475 PixelMapOpItem::PixelMapOpItem(std::shared_ptr<RSImageBase> rsImage, const SkPaint& paint)
476     : OpItemWithRSImage(rsImage, paint, sizeof(PixelMapOpItem))
477 {}
478 #endif
479 
480 #ifdef NEW_SKIA
PixelMapRectOpItem(const std::shared_ptr<Media::PixelMap> & pixelmap,const SkRect & src,const SkRect & dst,const SkSamplingOptions & samplingOptions,const SkPaint * paint,SkCanvas::SrcRectConstraint constraint)481 PixelMapRectOpItem::PixelMapRectOpItem(
482     const std::shared_ptr<Media::PixelMap>& pixelmap, const SkRect& src, const SkRect& dst,
483     const SkSamplingOptions& samplingOptions, const SkPaint* paint, SkCanvas::SrcRectConstraint constraint)
484     : OpItemWithRSImage(samplingOptions, sizeof(PixelMapRectOpItem)),
485     samplingOptions_(samplingOptions), constraint_(constraint)
486 {
487     if (pixelmap) {
488         rsImage_ = std::make_shared<RSImageBase>();
489         rsImage_->SetPixelMap(pixelmap);
490         rsImage_->SetSrcRect(RectF(src.left(), src.top(), src.width(), src.height()));
491         rsImage_->SetDstRect(RectF(dst.left(), dst.top(), dst.width(), dst.height()));
492     }
493     if (paint) {
494         paint_ = *paint;
495     }
496 }
497 
PixelMapRectOpItem(std::shared_ptr<RSImageBase> rsImage,const SkSamplingOptions & samplingOptions,const SkPaint & paint,SkCanvas::SrcRectConstraint constraint)498 PixelMapRectOpItem::PixelMapRectOpItem(std::shared_ptr<RSImageBase> rsImage, const SkSamplingOptions& samplingOptions,
499     const SkPaint& paint, SkCanvas::SrcRectConstraint constraint)
500     : OpItemWithRSImage(rsImage, samplingOptions, paint, sizeof(PixelMapRectOpItem)),
501     samplingOptions_(samplingOptions), constraint_(constraint)
502 {}
503 #else
PixelMapRectOpItem(const std::shared_ptr<Media::PixelMap> & pixelmap,const SkRect & src,const SkRect & dst,const SkPaint * paint)504 PixelMapRectOpItem::PixelMapRectOpItem(
505     const std::shared_ptr<Media::PixelMap>& pixelmap, const SkRect& src, const SkRect& dst, const SkPaint* paint)
506     : OpItemWithRSImage(sizeof(PixelMapRectOpItem))
507 {
508     if (pixelmap) {
509         rsImage_ = std::make_shared<RSImageBase>();
510         rsImage_->SetPixelMap(pixelmap);
511         rsImage_->SetSrcRect(RectF(src.left(), src.top(), src.width(), src.height()));
512         rsImage_->SetDstRect(RectF(dst.left(), dst.top(), dst.width(), dst.height()));
513     }
514     if (paint) {
515         paint_ = *paint;
516     }
517 }
518 
PixelMapRectOpItem(std::shared_ptr<RSImageBase> rsImage,const SkPaint & paint)519 PixelMapRectOpItem::PixelMapRectOpItem(std::shared_ptr<RSImageBase> rsImage, const SkPaint& paint)
520     : OpItemWithRSImage(rsImage, paint, sizeof(PixelMapRectOpItem))
521 {}
522 #endif
523 
524 #ifdef NEW_SKIA
BitmapNineOpItem(const sk_sp<SkImage> bitmapInfo,const SkIRect & center,const SkRect & rectDst,SkFilterMode filter,const SkPaint * paint)525 BitmapNineOpItem::BitmapNineOpItem(const sk_sp<SkImage> bitmapInfo, const SkIRect& center, const SkRect& rectDst,
526     SkFilterMode filter, const SkPaint* paint)
527     : OpItemWithPaint(sizeof(BitmapNineOpItem)), center_(center), rectDst_(rectDst), filter_(filter)
528 {
529     if (bitmapInfo) {
530         bitmapInfo_ = bitmapInfo;
531     }
532     if (paint) {
533         paint_ = *paint;
534     }
535 }
536 
Draw(RSPaintFilterCanvas & canvas,const SkRect *) const537 void BitmapNineOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect*) const
538 {
539     canvas.drawImageNine(bitmapInfo_.get(), center_, rectDst_, filter_, &paint_);
540 }
541 #else
BitmapNineOpItem(const sk_sp<SkImage> bitmapInfo,const SkIRect & center,const SkRect & rectDst,const SkPaint * paint)542 BitmapNineOpItem::BitmapNineOpItem(
543     const sk_sp<SkImage> bitmapInfo, const SkIRect& center, const SkRect& rectDst, const SkPaint* paint)
544     : OpItemWithPaint(sizeof(BitmapNineOpItem)), center_(center), rectDst_(rectDst)
545 {
546     if (bitmapInfo) {
547         bitmapInfo_ = bitmapInfo;
548     }
549     if (paint) {
550         paint_ = *paint;
551     }
552 }
553 
Draw(RSPaintFilterCanvas & canvas,const SkRect *) const554 void BitmapNineOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect*) const
555 {
556     canvas.drawImageNine(bitmapInfo_, center_, rectDst_, &paint_);
557 }
558 #endif
559 
AdaptiveRRectOpItem(float radius,const SkPaint & paint)560 AdaptiveRRectOpItem::AdaptiveRRectOpItem(float radius, const SkPaint& paint)
561     : OpItemWithPaint(sizeof(AdaptiveRRectOpItem)), radius_(radius), paint_(paint)
562 {}
563 
Draw(RSPaintFilterCanvas & canvas,const SkRect * rect) const564 void AdaptiveRRectOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect* rect) const
565 {
566     if (!rect) {
567         ROSEN_LOGE("AdaptiveRRectOpItem::Draw, skrect is null");
568         return;
569     }
570     SkRRect rrect = SkRRect::MakeRectXY(*rect, radius_, radius_);
571     canvas.drawRRect(rrect, paint_);
572 }
573 
AdaptiveRRectScaleOpItem(float radiusRatio,const SkPaint & paint)574 AdaptiveRRectScaleOpItem::AdaptiveRRectScaleOpItem(float radiusRatio, const SkPaint& paint)
575     : OpItemWithPaint(sizeof(AdaptiveRRectScaleOpItem)), radiusRatio_(radiusRatio), paint_(paint)
576 {}
577 
Draw(RSPaintFilterCanvas & canvas,const SkRect * rect) const578 void AdaptiveRRectScaleOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect* rect) const
579 {
580     if (!rect) {
581         ROSEN_LOGE("AdaptiveRRectScaleOpItem::Draw, skrect is null");
582         return;
583     }
584     SkRRect rrect = SkRRect::MakeRectXY(*rect, radiusRatio_ * (*rect).height(), radiusRatio_ * (*rect).height());
585     canvas.drawRRect(rrect, paint_);
586 }
587 
ClipAdaptiveRRectOpItem(const SkVector radius[])588 ClipAdaptiveRRectOpItem::ClipAdaptiveRRectOpItem(const SkVector radius[])
589     : OpItem(sizeof(ClipAdaptiveRRectOpItem))
590 {
591     errno_t ret = memcpy_s(radius_, CORNER_SIZE * sizeof(SkVector), radius, CORNER_SIZE * sizeof(SkVector));
592     if (ret != EOK) {
593         ROSEN_LOGE("ClipAdaptiveRRectOpItem: memcpy failed!");
594     }
595 }
596 
Draw(RSPaintFilterCanvas & canvas,const SkRect * rect) const597 void ClipAdaptiveRRectOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect* rect) const
598 {
599     if (!rect) {
600         ROSEN_LOGE("ClipAdaptiveRRectOpItem::Draw skrect is null");
601         return;
602     }
603     SkRRect rrect = SkRRect::MakeEmpty();
604     rrect.setRectRadii(*rect, radius_);
605     canvas.clipRRect(rrect, true);
606 }
607 
ClipOutsetRectOpItem(float dx,float dy)608 ClipOutsetRectOpItem::ClipOutsetRectOpItem(float dx, float dy)
609     : OpItem(sizeof(ClipOutsetRectOpItem)), dx_(dx), dy_(dy)
610 {}
611 
Draw(RSPaintFilterCanvas & canvas,const SkRect * rect) const612 void ClipOutsetRectOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect* rect) const
613 {
614     auto clipRect = canvas.getLocalClipBounds().makeOutset(dx_, dy_);
615 #ifdef NEW_SKIA
616     canvas.clipRect(clipRect, SkClipOp::kIntersect, true);
617 #else
618     canvas.clipRect(clipRect, SkClipOp::kExtraEnumNeedInternallyPleaseIgnoreWillGoAway5, true);
619 #endif
620 }
621 
PathOpItem(const SkPath & path,const SkPaint & paint)622 PathOpItem::PathOpItem(const SkPath& path, const SkPaint& paint) : OpItemWithPaint(sizeof(PathOpItem))
623 {
624     path_ = path;
625     paint_ = paint;
626 }
627 
Draw(RSPaintFilterCanvas & canvas,const SkRect *) const628 void PathOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect*) const
629 {
630     canvas.drawPath(path_, paint_);
631 }
632 
ClipPathOpItem(const SkPath & path,SkClipOp clipOp,bool doAA)633 ClipPathOpItem::ClipPathOpItem(const SkPath& path, SkClipOp clipOp, bool doAA)
634     : OpItem(sizeof(ClipPathOpItem)), path_(path), clipOp_(clipOp), doAA_(doAA)
635 {}
636 
Draw(RSPaintFilterCanvas & canvas,const SkRect *) const637 void ClipPathOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect*) const
638 {
639     canvas.clipPath(path_, clipOp_, doAA_);
640 }
641 
PaintOpItem(const SkPaint & paint)642 PaintOpItem::PaintOpItem(const SkPaint& paint) : OpItemWithPaint(sizeof(PaintOpItem))
643 {
644     paint_ = paint;
645 }
646 
Draw(RSPaintFilterCanvas & canvas,const SkRect *) const647 void PaintOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect*) const
648 {
649     canvas.drawPaint(paint_);
650 }
651 
652 #ifdef NEW_SKIA
ImageWithParmOpItem(const sk_sp<SkImage> img,const sk_sp<SkData> data,const RsImageInfo & rsimageInfo,const SkSamplingOptions & samplingOptions,const SkPaint & paint)653 ImageWithParmOpItem::ImageWithParmOpItem(const sk_sp<SkImage> img, const sk_sp<SkData> data,
654     const RsImageInfo& rsimageInfo, const SkSamplingOptions& samplingOptions, const SkPaint& paint)
655     : OpItemWithPaint(sizeof(ImageWithParmOpItem)), samplingOptions_(samplingOptions)
656 #else
657 ImageWithParmOpItem::ImageWithParmOpItem(const sk_sp<SkImage> img, const sk_sp<SkData> data,
658     const RsImageInfo& rsimageInfo, const SkPaint& paint)
659     : OpItemWithPaint(sizeof(ImageWithParmOpItem))
660 #endif
661 {
662     rsImage_ = std::make_shared<RSImage>();
663     rsImage_->SetImage(img);
664     rsImage_->SetCompressData(data, rsimageInfo.uniqueId_, rsimageInfo.width_, rsimageInfo.height_);
665     rsImage_->SetImageFit(rsimageInfo.fitNum_);
666     rsImage_->SetImageRepeat(rsimageInfo.repeatNum_);
667     rsImage_->SetRadius(rsimageInfo.radius_);
668     rsImage_->SetScale(rsimageInfo.scale_);
669     paint_ = paint;
670 }
671 
672 #ifdef NEW_SKIA
ImageWithParmOpItem(const std::shared_ptr<Media::PixelMap> & pixelmap,const RsImageInfo & rsimageInfo,const SkSamplingOptions & samplingOptions,const SkPaint & paint)673 ImageWithParmOpItem::ImageWithParmOpItem(
674     const std::shared_ptr<Media::PixelMap>& pixelmap, const RsImageInfo& rsimageInfo,
675     const SkSamplingOptions& samplingOptions, const SkPaint& paint)
676     : OpItemWithPaint(sizeof(ImageWithParmOpItem)), samplingOptions_(samplingOptions)
677 #else
678 ImageWithParmOpItem::ImageWithParmOpItem(
679     const std::shared_ptr<Media::PixelMap>& pixelmap, const RsImageInfo& rsimageInfo, const SkPaint& paint)
680     : OpItemWithPaint(sizeof(ImageWithParmOpItem))
681 #endif
682 {
683     rsImage_ = std::make_shared<RSImage>();
684     rsImage_->SetPixelMap(pixelmap);
685     rsImage_->SetImageFit(rsimageInfo.fitNum_);
686     rsImage_->SetImageRepeat(rsimageInfo.repeatNum_);
687     rsImage_->SetRadius(rsimageInfo.radius_);
688     rsImage_->SetScale(rsimageInfo.scale_);
689     paint_ = paint;
690 }
691 
692 #ifdef NEW_SKIA
ImageWithParmOpItem(const std::shared_ptr<RSImage> & rsImage,const SkSamplingOptions & samplingOptions,const SkPaint & paint)693 ImageWithParmOpItem::ImageWithParmOpItem(const std::shared_ptr<RSImage>& rsImage,
694     const SkSamplingOptions& samplingOptions, const SkPaint& paint)
695     : OpItemWithPaint(sizeof(ImageWithParmOpItem)), rsImage_(rsImage), samplingOptions_(samplingOptions)
696 #else
697 ImageWithParmOpItem::ImageWithParmOpItem(const std::shared_ptr<RSImage>& rsImage, const SkPaint& paint)
698     : OpItemWithPaint(sizeof(ImageWithParmOpItem)), rsImage_(rsImage)
699 #endif
700 {
701     paint_ = paint;
702 }
~ImageWithParmOpItem()703 ImageWithParmOpItem::~ImageWithParmOpItem()
704 {
705 #if defined(ROSEN_OHOS) && defined(RS_ENABLE_GL)
706 #ifndef USE_ROSEN_DRAWING
707     if (texId_ != 0U) {
708         glBindTexture(GL_TEXTURE_2D, 0);
709         glDeleteTextures(1, &texId_);
710         texId_ = 0U;
711     }
712     if (nativeWindowBuffer_ != nullptr) {
713         DestroyNativeWindowBuffer(nativeWindowBuffer_);
714         nativeWindowBuffer_ = nullptr;
715     }
716     if (eglImage_ != EGL_NO_IMAGE_KHR) {
717         auto disp = eglGetDisplay(EGL_DEFAULT_DISPLAY);
718         eglDestroyImageKHR(disp, eglImage_);
719         eglImage_ = EGL_NO_IMAGE_KHR;
720     }
721 #endif
722 #endif
723 }
Draw(RSPaintFilterCanvas & canvas,const SkRect * rect) const724 void ImageWithParmOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect* rect) const
725 {
726     if (!rect) {
727         ROSEN_LOGE("ImageWithParmOpItem: no rect");
728         return;
729     }
730 
731 #if defined(ROSEN_OHOS) && defined(RS_ENABLE_GL)
732 #ifndef USE_ROSEN_DRAWING
733     std::shared_ptr<Media::PixelMap> pixelmap = rsImage_->GetPixelMap();
734     if (pixelmap != nullptr && pixelmap->GetAllocatorType() == Media::AllocatorType::DMA_ALLOC) {
735         sk_sp<SkImage> dmaImage = GetSkImageFromSurfaceBuffer(canvas,
736             reinterpret_cast<SurfaceBuffer*> (pixelmap->GetFd()));
737         rsImage_->SetImage(dmaImage);
738     }
739 #endif
740 #endif
741 
742 #ifdef NEW_SKIA
743     rsImage_->CanvasDrawImage(canvas, *rect, samplingOptions_, paint_);
744 #else
745     rsImage_->CanvasDrawImage(canvas, *rect, paint_);
746 #endif
747 }
748 
749 #if defined(ROSEN_OHOS) && defined(RS_ENABLE_GL)
750 #ifndef USE_ROSEN_DRAWING
GetSkImageFromSurfaceBuffer(SkCanvas & canvas,SurfaceBuffer * surfaceBuffer) const751 sk_sp<SkImage> ImageWithParmOpItem::GetSkImageFromSurfaceBuffer(SkCanvas& canvas, SurfaceBuffer* surfaceBuffer) const
752 {
753     if (surfaceBuffer == nullptr) {
754         RS_LOGE("GetSkImageFromSurfaceBuffer surfaceBuffer is nullptr");
755         return nullptr;
756     }
757     if (nativeWindowBuffer_ == nullptr) {
758         sptr<SurfaceBuffer> sfBuffer(surfaceBuffer);
759         nativeWindowBuffer_ = CreateNativeWindowBufferFromSurfaceBuffer(&sfBuffer);
760         if (!nativeWindowBuffer_) {
761             RS_LOGE("GetSkImageFromSurfaceBuffer create native window buffer fail");
762             return nullptr;
763         }
764     }
765     EGLint attrs[] = {
766         EGL_IMAGE_PRESERVED,
767         EGL_TRUE,
768         EGL_NONE,
769     };
770 
771     auto disp = eglGetDisplay(EGL_DEFAULT_DISPLAY);
772     if (eglImage_ == EGL_NO_IMAGE_KHR) {
773         eglImage_ = eglCreateImageKHR(disp, EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_OHOS, nativeWindowBuffer_, attrs);
774         if (eglImage_ == EGL_NO_IMAGE_KHR) {
775             RS_LOGE("%s create egl image fail %d", __func__, eglGetError());
776             return nullptr;
777         }
778     }
779 
780     // Create texture object
781     if (texId_ == 0U) {
782         glGenTextures(1, &texId_);
783         glBindTexture(GL_TEXTURE_2D, texId_);
784         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
785         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
786         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
787         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
788         glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, static_cast<GLeglImageOES>(eglImage_));
789     }
790 
791     GrGLTextureInfo textureInfo = { GL_TEXTURE_2D, texId_, GL_RGBA8_OES };
792 
793     GrBackendTexture backendTexture(
794         surfaceBuffer->GetWidth(), surfaceBuffer->GetHeight(), GrMipMapped::kNo, textureInfo);
795 #ifdef NEW_SKIA
796     auto skImage = SkImage::MakeFromTexture(canvas.recordingContext(), backendTexture, kTopLeft_GrSurfaceOrigin,
797         kRGBA_8888_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGB());
798 #else
799     auto skImage = SkImage::MakeFromTexture(canvas.getGrContext(), backendTexture, kTopLeft_GrSurfaceOrigin,
800         kRGBA_8888_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGB());
801 #endif
802     return skImage;
803 }
804 #endif // USE_ROSEN_DRAWING
805 #endif // ROSEN_OHOS & RS_ENABLE_GL
806 
807 #ifdef NEW_SKIA
ConcatOpItem(const SkM44 & matrix)808 ConcatOpItem::ConcatOpItem(const SkM44& matrix) : OpItem(sizeof(ConcatOpItem)), matrix_(matrix) {}
809 #else
ConcatOpItem(const SkMatrix & matrix)810 ConcatOpItem::ConcatOpItem(const SkMatrix& matrix) : OpItem(sizeof(ConcatOpItem)), matrix_(matrix) {}
811 #endif
812 
Draw(RSPaintFilterCanvas & canvas,const SkRect *) const813 void ConcatOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect*) const
814 {
815     canvas.concat(matrix_);
816 }
817 
SaveLayerOpItem(const SkCanvas::SaveLayerRec & rec)818 SaveLayerOpItem::SaveLayerOpItem(const SkCanvas::SaveLayerRec& rec) : OpItemWithPaint(sizeof(SaveLayerOpItem))
819 {
820     if (rec.fBounds) {
821         rect_ = *rec.fBounds;
822         rectPtr_ = &rect_;
823     }
824     if (rec.fPaint) {
825         paint_ = *rec.fPaint;
826     }
827     backdrop_ = sk_ref_sp(rec.fBackdrop);
828     flags_ = rec.fSaveLayerFlags;
829 #ifndef NEW_SKIA
830     mask_ = sk_ref_sp(rec.fClipMask);
831     matrix_ = rec.fClipMatrix ? *(rec.fClipMatrix) : SkMatrix::I();
832 #endif
833 }
834 
Draw(RSPaintFilterCanvas & canvas,const SkRect *) const835 void SaveLayerOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect*) const
836 {
837 #ifdef NEW_SKIA
838     canvas.saveLayer(
839         { rectPtr_, &paint_, backdrop_.get(), flags_ });
840 #else
841     canvas.saveLayer(
842         { rectPtr_, &paint_, backdrop_.get(), mask_.get(), matrix_.isIdentity() ? nullptr : &matrix_, flags_ });
843 #endif
844 }
845 
DrawableOpItem(SkDrawable * drawable,const SkMatrix * matrix)846 DrawableOpItem::DrawableOpItem(SkDrawable* drawable, const SkMatrix* matrix) : OpItem(sizeof(DrawableOpItem))
847 {
848     drawable_ = sk_ref_sp(drawable);
849     if (matrix) {
850         matrix_ = *matrix;
851     }
852 }
853 
Draw(RSPaintFilterCanvas & canvas,const SkRect *) const854 void DrawableOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect*) const
855 {
856     canvas.drawDrawable(drawable_.get(), &matrix_);
857 }
858 
PictureOpItem(const sk_sp<SkPicture> picture,const SkMatrix * matrix,const SkPaint * paint)859 PictureOpItem::PictureOpItem(const sk_sp<SkPicture> picture, const SkMatrix* matrix, const SkPaint* paint)
860     : OpItemWithPaint(sizeof(PictureOpItem)), picture_(picture)
861 {
862     if (matrix) {
863         matrix_ = *matrix;
864     }
865     if (paint) {
866         paint_ = *paint;
867     }
868 }
869 
Draw(RSPaintFilterCanvas & canvas,const SkRect *) const870 void PictureOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect*) const
871 {
872     canvas.drawPicture(picture_, &matrix_, &paint_);
873 }
874 
PointsOpItem(SkCanvas::PointMode mode,int count,const SkPoint processedPoints[],const SkPaint & paint)875 PointsOpItem::PointsOpItem(SkCanvas::PointMode mode, int count, const SkPoint processedPoints[], const SkPaint& paint)
876     : OpItemWithPaint(sizeof(PointsOpItem)), mode_(mode), count_(count), processedPoints_(new SkPoint[count])
877 {
878     errno_t ret = memcpy_s(processedPoints_, count * sizeof(SkPoint), processedPoints, count * sizeof(SkPoint));
879     if (ret != EOK) {
880         ROSEN_LOGE("PointsOpItem: memcpy failed!");
881     }
882     paint_ = paint;
883 }
884 
Draw(RSPaintFilterCanvas & canvas,const SkRect *) const885 void PointsOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect*) const
886 {
887     canvas.drawPoints(mode_, count_, processedPoints_, paint_);
888 }
889 
890 #ifdef NEW_SKIA
VerticesOpItem(const SkVertices * vertices,SkBlendMode mode,const SkPaint & paint)891 VerticesOpItem::VerticesOpItem(const SkVertices* vertices, SkBlendMode mode, const SkPaint& paint)
892     : OpItemWithPaint(sizeof(VerticesOpItem)),
893       vertices_(sk_ref_sp(const_cast<SkVertices*>(vertices))),
894       mode_(mode)
895 {
896     paint_ = paint;
897 }
898 #else
VerticesOpItem(const SkVertices * vertices,const SkVertices::Bone bones[],int boneCount,SkBlendMode mode,const SkPaint & paint)899 VerticesOpItem::VerticesOpItem(const SkVertices* vertices, const SkVertices::Bone bones[],
900     int boneCount, SkBlendMode mode, const SkPaint& paint)
901     : OpItemWithPaint(sizeof(VerticesOpItem)), vertices_(sk_ref_sp(const_cast<SkVertices*>(vertices))),
902       bones_(new SkVertices::Bone[boneCount]), boneCount_(boneCount), mode_(mode)
903 {
904     errno_t ret = memcpy_s(bones_, boneCount * sizeof(SkVertices::Bone), bones, boneCount * sizeof(SkVertices::Bone));
905     if (ret != EOK) {
906         ROSEN_LOGE("VerticesOpItem: memcpy failed!");
907     }
908     paint_ = paint;
909 }
910 #endif
~VerticesOpItem()911 VerticesOpItem::~VerticesOpItem()
912 {
913 #ifndef NEW_SKIA
914     delete[] bones_;
915 #endif
916 }
917 
Draw(RSPaintFilterCanvas & canvas,const SkRect *) const918 void VerticesOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect*) const
919 {
920 #ifdef NEW_SKIA
921     canvas.drawVertices(vertices_, mode_, paint_);
922 #else
923     canvas.drawVertices(vertices_, bones_, boneCount_, mode_, paint_);
924 #endif
925 }
926 
ShadowRecOpItem(const SkPath & path,const SkDrawShadowRec & rec)927 ShadowRecOpItem::ShadowRecOpItem(const SkPath& path, const SkDrawShadowRec& rec)
928     : OpItem(sizeof(ShadowRecOpItem)), path_(path), rec_(rec)
929 {}
930 
Draw(RSPaintFilterCanvas & canvas,const SkRect *) const931 void ShadowRecOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect*) const
932 {
933     auto rec = rec_;
934     if (canvas.GetAlpha() < 1.f) {
935         rec.fAmbientColor = SkColorSetA(rec_.fAmbientColor,
936             static_cast<unsigned>(canvas.GetAlpha() * SkColorGetA(rec_.fAmbientColor)));
937         rec.fSpotColor = SkColorSetA(rec_.fSpotColor,
938             static_cast<unsigned>(canvas.GetAlpha() * SkColorGetA(rec_.fSpotColor)));
939     }
940     canvas.private_draw_shadow_rec(path_, rec);
941 }
942 
MultiplyAlphaOpItem(float alpha)943 MultiplyAlphaOpItem::MultiplyAlphaOpItem(float alpha) : OpItem(sizeof(MultiplyAlphaOpItem)), alpha_(alpha) {}
944 
Draw(RSPaintFilterCanvas & canvas,const SkRect *) const945 void MultiplyAlphaOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect*) const
946 {
947     canvas.MultiplyAlpha(alpha_);
948 }
949 
SaveAlphaOpItem()950 SaveAlphaOpItem::SaveAlphaOpItem() : OpItem(sizeof(SaveAlphaOpItem)) {}
951 
Draw(RSPaintFilterCanvas & canvas,const SkRect *) const952 void SaveAlphaOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect*) const
953 {
954     canvas.SaveAlpha();
955 }
956 
RestoreAlphaOpItem()957 RestoreAlphaOpItem::RestoreAlphaOpItem() : OpItem(sizeof(RestoreAlphaOpItem)) {}
958 
Draw(RSPaintFilterCanvas & canvas,const SkRect *) const959 void RestoreAlphaOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect*) const
960 {
961     canvas.RestoreAlpha();
962 }
963 
964 #ifdef ROSEN_OHOS
SurfaceBufferOpItem(const RSSurfaceBufferInfo & surfaceBufferInfo)965 SurfaceBufferOpItem::SurfaceBufferOpItem(const RSSurfaceBufferInfo& surfaceBufferInfo)
966     : OpItemWithPaint(sizeof(SurfaceBufferOpItem)), surfaceBufferInfo_(surfaceBufferInfo)
967 {}
968 
~SurfaceBufferOpItem()969 SurfaceBufferOpItem::~SurfaceBufferOpItem()
970 {
971 #ifdef RS_ENABLE_GL
972     if (eglImage_ != EGL_NO_IMAGE_KHR) {
973         auto disp = eglGetDisplay(EGL_DEFAULT_DISPLAY);
974         eglDestroyImageKHR(disp, eglImage_);
975     }
976     if (nativeWindowBuffer_ != nullptr) {
977         DestroyNativeWindowBuffer(nativeWindowBuffer_);
978     }
979     if (texId_ != 0U) {
980         glDeleteTextures(1, &texId_);
981     }
982 #endif
983 }
984 
Draw(RSPaintFilterCanvas & canvas,const SkRect *) const985 void SurfaceBufferOpItem::Draw(RSPaintFilterCanvas& canvas, const SkRect*) const
986 {
987 #ifdef RS_ENABLE_GL
988     if (surfaceBufferInfo_.surfaceBuffer_ == nullptr) {
989         ROSEN_LOGE("SurfaceBufferOpItem::Draw surfaceBuffer_ is nullptr");
990         return;
991     }
992     nativeWindowBuffer_ = CreateNativeWindowBufferFromSurfaceBuffer(&(surfaceBufferInfo_.surfaceBuffer_));
993     if (!nativeWindowBuffer_) {
994         ROSEN_LOGE("SurfaceBufferOpItem::Draw create native window buffer fail");
995         return;
996     }
997     EGLint attrs[] = {
998         EGL_IMAGE_PRESERVED,
999         EGL_TRUE,
1000         EGL_NONE,
1001     };
1002 
1003     auto disp = eglGetDisplay(EGL_DEFAULT_DISPLAY);
1004     eglImage_ = eglCreateImageKHR(disp, EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_OHOS, nativeWindowBuffer_, attrs);
1005     if (eglImage_ == EGL_NO_IMAGE_KHR) {
1006         ROSEN_LOGE("%s create egl image fail %d", __func__, eglGetError());
1007         return;
1008     }
1009 
1010     // save
1011     GLuint originTexture;
1012     glGetIntegerv(GL_TEXTURE_BINDING_2D, reinterpret_cast<GLint *>(&originTexture));
1013     GLint minFilter;
1014     glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, &minFilter);
1015     GLint magFilter;
1016     glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, &magFilter);
1017     GLint wrapS;
1018     glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, &wrapS);
1019     GLint wrapT;
1020     glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, &wrapT);
1021 
1022     // Create texture object
1023     texId_ = 0;
1024     glGenTextures(1, &texId_);
1025     glBindTexture(GL_TEXTURE_2D, texId_);
1026     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1027     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1028     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1029     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1030     glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, static_cast<GLeglImageOES>(eglImage_));
1031 
1032     // restore
1033     glBindTexture(GL_TEXTURE_2D, originTexture);
1034     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter);
1035     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter);
1036     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapS);
1037     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapT);
1038 
1039     GrGLTextureInfo textureInfo = { GL_TEXTURE_2D, texId_, GL_RGBA8_OES };
1040 
1041     GrBackendTexture backendTexture(
1042         surfaceBufferInfo_.width_, surfaceBufferInfo_.height_, GrMipMapped::kNo, textureInfo);
1043 #ifdef NEW_SKIA
1044     auto skImage = SkImage::MakeFromTexture(canvas.recordingContext(), backendTexture, kTopLeft_GrSurfaceOrigin,
1045         kRGBA_8888_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGB());
1046 #else
1047     auto skImage = SkImage::MakeFromTexture(canvas.getGrContext(), backendTexture, kTopLeft_GrSurfaceOrigin,
1048         kRGBA_8888_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGB());
1049 #endif
1050     canvas.drawImage(skImage, surfaceBufferInfo_.offSetX_, surfaceBufferInfo_.offSetY_);
1051 #endif // RS_ENABLE_GL
1052 }
1053 #endif // ROSEN_OHOS
1054 
1055 // RectOpItem
Marshalling(Parcel & parcel) const1056 bool RectOpItem::Marshalling(Parcel& parcel) const
1057 {
1058     bool success = RSMarshallingHelper::Marshalling(parcel, rect_) &&
1059                    RSMarshallingHelper::Marshalling(parcel, paint_);
1060     if (!success) {
1061         ROSEN_LOGE("RectOpItem::Marshalling failed!");
1062         return false;
1063     }
1064     return success;
1065 }
1066 
Unmarshalling(Parcel & parcel)1067 OpItem* RectOpItem::Unmarshalling(Parcel& parcel)
1068 {
1069     SkRect rect;
1070     SkPaint paint;
1071     bool success = RSMarshallingHelper::Unmarshalling(parcel, rect) &&
1072                    RSMarshallingHelper::Unmarshalling(parcel, paint);
1073     if (!success) {
1074         ROSEN_LOGE("RectOpItem::Unmarshalling failed!");
1075         return nullptr;
1076     }
1077     return new RectOpItem(rect, paint);
1078 }
1079 
1080 // RoundRectOpItem
Marshalling(Parcel & parcel) const1081 bool RoundRectOpItem::Marshalling(Parcel& parcel) const
1082 {
1083     bool success = RSMarshallingHelper::Marshalling(parcel, rrect_) &&
1084                    RSMarshallingHelper::Marshalling(parcel, paint_);
1085     if (!success) {
1086         ROSEN_LOGE("RoundRectOpItem::Marshalling failed!");
1087         return false;
1088     }
1089     return success;
1090 }
1091 
Unmarshalling(Parcel & parcel)1092 OpItem* RoundRectOpItem::Unmarshalling(Parcel& parcel)
1093 {
1094     SkRRect rrect;
1095     SkPaint paint;
1096     bool success = RSMarshallingHelper::Unmarshalling(parcel, rrect) &&
1097                    RSMarshallingHelper::Unmarshalling(parcel, paint);
1098     if (!success) {
1099         ROSEN_LOGE("RoundRectOpItem::Unmarshalling failed!");
1100         return nullptr;
1101     }
1102     return new RoundRectOpItem(rrect, paint);
1103 }
1104 
1105 // ImageWithParmOpItem
Marshalling(Parcel & parcel) const1106 bool ImageWithParmOpItem::Marshalling(Parcel& parcel) const
1107 {
1108     bool success = RSMarshallingHelper::Marshalling(parcel, rsImage_) &&
1109                    RSMarshallingHelper::Marshalling(parcel, paint_);
1110 #ifdef NEW_SKIA
1111     success = success && RSMarshallingHelper::Marshalling(parcel, samplingOptions_);
1112 #endif
1113     if (!success) {
1114         ROSEN_LOGE("ImageWithParmOpItem::Marshalling failed!");
1115         return false;
1116     }
1117     return success;
1118 }
1119 
Unmarshalling(Parcel & parcel)1120 OpItem* ImageWithParmOpItem::Unmarshalling(Parcel& parcel)
1121 {
1122     std::shared_ptr<RSImage> rsImage;
1123     SkPaint paint;
1124     bool success = RSMarshallingHelper::Unmarshalling(parcel, rsImage) &&
1125                    RSMarshallingHelper::Unmarshalling(parcel, paint);
1126 #ifdef NEW_SKIA
1127     SkSamplingOptions samplingOptions;
1128     success = success && RSMarshallingHelper::Unmarshalling(parcel, samplingOptions);
1129 #endif
1130     if (!success) {
1131         ROSEN_LOGE("ImageWithParmOpItem::Unmarshalling failed!");
1132         return nullptr;
1133     }
1134 #ifdef NEW_SKIA
1135     return new ImageWithParmOpItem(rsImage, samplingOptions, paint);
1136 #else
1137     return new ImageWithParmOpItem(rsImage, paint);
1138 #endif
1139 }
1140 
1141 // DRRectOpItem
Marshalling(Parcel & parcel) const1142 bool DRRectOpItem::Marshalling(Parcel& parcel) const
1143 {
1144     bool success = RSMarshallingHelper::Marshalling(parcel, outer_) &&
1145                    RSMarshallingHelper::Marshalling(parcel, inner_) &&
1146                    RSMarshallingHelper::Marshalling(parcel, paint_);
1147     if (!success) {
1148         ROSEN_LOGE("DRRectOpItem::Marshalling failed!");
1149         return false;
1150     }
1151     return success;
1152 }
1153 
Unmarshalling(Parcel & parcel)1154 OpItem* DRRectOpItem::Unmarshalling(Parcel& parcel)
1155 {
1156     SkRRect outer;
1157     SkRRect inner;
1158     SkPaint paint;
1159     bool success = RSMarshallingHelper::Unmarshalling(parcel, outer) &&
1160                    RSMarshallingHelper::Unmarshalling(parcel, inner) &&
1161                    RSMarshallingHelper::Unmarshalling(parcel, paint);
1162     if (!success) {
1163         ROSEN_LOGE("DRRectOpItem::Unmarshalling failed!");
1164         return nullptr;
1165     }
1166     return new DRRectOpItem(outer, inner, paint);
1167 }
1168 
1169 // OvalOpItem
Marshalling(Parcel & parcel) const1170 bool OvalOpItem::Marshalling(Parcel& parcel) const
1171 {
1172     bool success = RSMarshallingHelper::Marshalling(parcel, rect_) &&
1173                    RSMarshallingHelper::Marshalling(parcel, paint_);
1174     if (!success) {
1175         ROSEN_LOGE("OvalOpItem::Marshalling failed!");
1176         return false;
1177     }
1178     return success;
1179 }
1180 
Unmarshalling(Parcel & parcel)1181 OpItem* OvalOpItem::Unmarshalling(Parcel& parcel)
1182 {
1183     SkRect rect;
1184     SkPaint paint;
1185     bool success = RSMarshallingHelper::Unmarshalling(parcel, rect) &&
1186                    RSMarshallingHelper::Unmarshalling(parcel, paint);
1187     if (!success) {
1188         ROSEN_LOGE("OvalOpItem::Unmarshalling failed!");
1189         return nullptr;
1190     }
1191     return new OvalOpItem(rect, paint);
1192 }
1193 
1194 // RegionOpItem
Marshalling(Parcel & parcel) const1195 bool RegionOpItem::Marshalling(Parcel& parcel) const
1196 {
1197     bool success = RSMarshallingHelper::Marshalling(parcel, region_) &&
1198                    RSMarshallingHelper::Marshalling(parcel, paint_);
1199     if (!success) {
1200         ROSEN_LOGE("RegionOpItem::Marshalling failed!");
1201         return false;
1202     }
1203     return success;
1204 }
1205 
Unmarshalling(Parcel & parcel)1206 OpItem* RegionOpItem::Unmarshalling(Parcel& parcel)
1207 {
1208     SkRegion region;
1209     SkPaint paint;
1210     bool success = RSMarshallingHelper::Unmarshalling(parcel, region) &&
1211                    RSMarshallingHelper::Unmarshalling(parcel, paint);
1212     if (!success) {
1213         ROSEN_LOGE("RegionOpItem::Unmarshalling failed!");
1214         return nullptr;
1215     }
1216     return new RegionOpItem(region, paint);
1217 }
1218 
1219 // ArcOpItem
Marshalling(Parcel & parcel) const1220 bool ArcOpItem::Marshalling(Parcel& parcel) const
1221 {
1222     bool success = RSMarshallingHelper::Marshalling(parcel, rect_) &&
1223                    RSMarshallingHelper::Marshalling(parcel, startAngle_) &&
1224                    RSMarshallingHelper::Marshalling(parcel, sweepAngle_) &&
1225                    RSMarshallingHelper::Marshalling(parcel, useCenter_) &&
1226                    RSMarshallingHelper::Marshalling(parcel, paint_);
1227     if (!success) {
1228         ROSEN_LOGE("ArcOpItem::Marshalling failed!");
1229         return false;
1230     }
1231     return success;
1232 }
1233 
Unmarshalling(Parcel & parcel)1234 OpItem* ArcOpItem::Unmarshalling(Parcel& parcel)
1235 {
1236     SkRect rect;
1237     float startAngle;
1238     float sweepAngle;
1239     bool useCenter;
1240     SkPaint paint;
1241     bool success = RSMarshallingHelper::Unmarshalling(parcel, rect) &&
1242                    RSMarshallingHelper::Unmarshalling(parcel, startAngle) &&
1243                    RSMarshallingHelper::Unmarshalling(parcel, sweepAngle) &&
1244                    RSMarshallingHelper::Unmarshalling(parcel, useCenter) &&
1245                    RSMarshallingHelper::Unmarshalling(parcel, paint);
1246     if (!success) {
1247         ROSEN_LOGE("ArcOpItem::Unmarshalling failed!");
1248         return nullptr;
1249     }
1250     return new ArcOpItem(rect, startAngle, sweepAngle, useCenter, paint);
1251 }
1252 
1253 // SaveOpItem
Unmarshalling(Parcel & parcel)1254 OpItem* SaveOpItem::Unmarshalling(Parcel& parcel)
1255 {
1256     return new SaveOpItem();
1257 }
1258 
1259 // RestoreOpItem
Unmarshalling(Parcel & parcel)1260 OpItem* RestoreOpItem::Unmarshalling(Parcel& parcel)
1261 {
1262     return new RestoreOpItem();
1263 }
1264 
1265 // FlushOpItem
Unmarshalling(Parcel & parcel)1266 OpItem* FlushOpItem::Unmarshalling(Parcel& parcel)
1267 {
1268     return new FlushOpItem();
1269 }
1270 
1271 // MatrixOpItem
Marshalling(Parcel & parcel) const1272 bool MatrixOpItem::Marshalling(Parcel& parcel) const
1273 {
1274     bool success = RSMarshallingHelper::Marshalling(parcel, matrix_);
1275     if (!success) {
1276         ROSEN_LOGE("MatrixOpItem::Marshalling failed!");
1277         return false;
1278     }
1279     return success;
1280 }
1281 
Unmarshalling(Parcel & parcel)1282 OpItem* MatrixOpItem::Unmarshalling(Parcel& parcel)
1283 {
1284 #ifdef NEW_SKIA
1285     SkM44 matrix;
1286 #else
1287     SkMatrix matrix;
1288 #endif
1289     bool success = RSMarshallingHelper::Unmarshalling(parcel, matrix);
1290     if (!success) {
1291         ROSEN_LOGE("MatrixOpItem::Unmarshalling failed!");
1292         return nullptr;
1293     }
1294     return new MatrixOpItem(matrix);
1295 }
1296 
1297 // ClipRectOpItem
Marshalling(Parcel & parcel) const1298 bool ClipRectOpItem::Marshalling(Parcel& parcel) const
1299 {
1300     bool success = RSMarshallingHelper::Marshalling(parcel, rect_) &&
1301                    RSMarshallingHelper::Marshalling(parcel, clipOp_) &&
1302                    RSMarshallingHelper::Marshalling(parcel, doAA_);
1303     if (!success) {
1304         ROSEN_LOGE("ClipRectOpItem::Marshalling failed!");
1305         return false;
1306     }
1307     return success;
1308 }
1309 
Unmarshalling(Parcel & parcel)1310 OpItem* ClipRectOpItem::Unmarshalling(Parcel& parcel)
1311 {
1312     SkRect rect;
1313     SkClipOp clipOp;
1314     bool doAA;
1315     bool success = RSMarshallingHelper::Unmarshalling(parcel, rect) &&
1316                    RSMarshallingHelper::Unmarshalling(parcel, clipOp) &&
1317                    RSMarshallingHelper::Unmarshalling(parcel, doAA);
1318     if (!success) {
1319         ROSEN_LOGE("ClipRectOpItem::Unmarshalling failed!");
1320         return nullptr;
1321     }
1322     return new ClipRectOpItem(rect, clipOp, doAA);
1323 }
1324 
1325 // ClipRRectOpItem
Marshalling(Parcel & parcel) const1326 bool ClipRRectOpItem::Marshalling(Parcel& parcel) const
1327 {
1328     bool success = RSMarshallingHelper::Marshalling(parcel, rrect_) &&
1329                    RSMarshallingHelper::Marshalling(parcel, clipOp_) &&
1330                    RSMarshallingHelper::Marshalling(parcel, doAA_);
1331     if (!success) {
1332         ROSEN_LOGE("ClipRRectOpItem::Marshalling failed!");
1333         return false;
1334     }
1335     return success;
1336 }
1337 
Unmarshalling(Parcel & parcel)1338 OpItem* ClipRRectOpItem::Unmarshalling(Parcel& parcel)
1339 {
1340     SkRRect rrect;
1341     SkClipOp clipOp;
1342     bool doAA;
1343     bool success = RSMarshallingHelper::Unmarshalling(parcel, rrect) &&
1344                    RSMarshallingHelper::Unmarshalling(parcel, clipOp) &&
1345                    RSMarshallingHelper::Unmarshalling(parcel, doAA);
1346     if (!success) {
1347         ROSEN_LOGE("ClipRRectOpItem::Unmarshalling failed!");
1348         return nullptr;
1349     }
1350     return new ClipRRectOpItem(rrect, clipOp, doAA);
1351 }
1352 
1353 // ClipRegionOpItem
Marshalling(Parcel & parcel) const1354 bool ClipRegionOpItem::Marshalling(Parcel& parcel) const
1355 {
1356     bool success = RSMarshallingHelper::Marshalling(parcel, region_) &&
1357                    RSMarshallingHelper::Marshalling(parcel, clipOp_);
1358     if (!success) {
1359         ROSEN_LOGE("ClipRegionOpItem::Marshalling failed!");
1360         return false;
1361     }
1362     return success;
1363 }
1364 
Unmarshalling(Parcel & parcel)1365 OpItem* ClipRegionOpItem::Unmarshalling(Parcel& parcel)
1366 {
1367     SkRegion region;
1368     SkClipOp clipOp;
1369     bool success = RSMarshallingHelper::Unmarshalling(parcel, region) &&
1370                    RSMarshallingHelper::Unmarshalling(parcel, clipOp);
1371     if (!success) {
1372         ROSEN_LOGE("ClipRegionOpItem::Unmarshalling failed!");
1373         return nullptr;
1374     }
1375     return new ClipRegionOpItem(region, clipOp);
1376 }
1377 
1378 // TranslateOpItem
Marshalling(Parcel & parcel) const1379 bool TranslateOpItem::Marshalling(Parcel& parcel) const
1380 {
1381     bool success = RSMarshallingHelper::Marshalling(parcel, distanceX_) &&
1382                    RSMarshallingHelper::Marshalling(parcel, distanceY_);
1383     if (!success) {
1384         ROSEN_LOGE("TranslateOpItem::Marshalling failed!");
1385         return false;
1386     }
1387     return success;
1388 }
1389 
Unmarshalling(Parcel & parcel)1390 OpItem* TranslateOpItem::Unmarshalling(Parcel& parcel)
1391 {
1392     float distanceX;
1393     float distanceY;
1394     bool success = RSMarshallingHelper::Unmarshalling(parcel, distanceX) &&
1395                    RSMarshallingHelper::Unmarshalling(parcel, distanceY);
1396     if (!success) {
1397         ROSEN_LOGE("TranslateOpItem::Unmarshalling failed!");
1398         return nullptr;
1399     }
1400     return new TranslateOpItem(distanceX, distanceY);
1401 }
1402 
1403 // ScaleOpItem
Marshalling(Parcel & parcel) const1404 bool ScaleOpItem::Marshalling(Parcel& parcel) const
1405 {
1406     bool success = RSMarshallingHelper::Marshalling(parcel, scaleX_) &&
1407                    RSMarshallingHelper::Marshalling(parcel, scaleY_);
1408     if (!success) {
1409         ROSEN_LOGE("ScaleOpItem::Marshalling failed!");
1410         return false;
1411     }
1412     return success;
1413 }
1414 
Unmarshalling(Parcel & parcel)1415 OpItem* ScaleOpItem::Unmarshalling(Parcel& parcel)
1416 {
1417     float scaleX;
1418     float scaleY;
1419     bool success = RSMarshallingHelper::Unmarshalling(parcel, scaleX) &&
1420                    RSMarshallingHelper::Unmarshalling(parcel, scaleY);
1421     if (!success) {
1422         ROSEN_LOGE("ScaleOpItem::Unmarshalling failed!");
1423         return nullptr;
1424     }
1425     return new ScaleOpItem(scaleX, scaleY);
1426 }
1427 
1428 // TextBlobOpItem
Marshalling(Parcel & parcel) const1429 bool TextBlobOpItem::Marshalling(Parcel& parcel) const
1430 {
1431     bool success = RSMarshallingHelper::Marshalling(parcel, textBlob_) &&
1432                    RSMarshallingHelper::Marshalling(parcel, x_) &&
1433                    RSMarshallingHelper::Marshalling(parcel, y_) &&
1434                    RSMarshallingHelper::Marshalling(parcel, paint_);
1435     if (!success) {
1436         ROSEN_LOGE("TextBlobOpItem::Marshalling failed!");
1437         return false;
1438     }
1439     return success;
1440 }
1441 
Unmarshalling(Parcel & parcel)1442 OpItem* TextBlobOpItem::Unmarshalling(Parcel& parcel)
1443 {
1444     sk_sp<SkTextBlob> textBlob;
1445     float x;
1446     float y;
1447     SkPaint paint;
1448     bool success = RSMarshallingHelper::Unmarshalling(parcel, textBlob) &&
1449                    RSMarshallingHelper::Unmarshalling(parcel, x) &&
1450                    RSMarshallingHelper::Unmarshalling(parcel, y) &&
1451                    RSMarshallingHelper::Unmarshalling(parcel, paint);
1452     if (!success) {
1453         ROSEN_LOGE("TextBlobOpItem::Unmarshalling failed!");
1454         return nullptr;
1455     }
1456     return new TextBlobOpItem(textBlob, x, y, paint);
1457 }
1458 
1459 // BitmapOpItem
Marshalling(Parcel & parcel) const1460 bool BitmapOpItem::Marshalling(Parcel& parcel) const
1461 {
1462     bool success = RSMarshallingHelper::Marshalling(parcel, rsImage_) &&
1463                    RSMarshallingHelper::Marshalling(parcel, paint_);
1464 #ifdef NEW_SKIA
1465     success = success && RSMarshallingHelper::Marshalling(parcel, samplingOptions_);
1466 #endif
1467     if (!success) {
1468         ROSEN_LOGE("BitmapOpItem::Marshalling failed!");
1469         return false;
1470     }
1471     return success;
1472 }
1473 
Unmarshalling(Parcel & parcel)1474 OpItem* BitmapOpItem::Unmarshalling(Parcel& parcel)
1475 {
1476     std::shared_ptr<RSImageBase> rsImage;
1477     SkPaint paint;
1478     bool success = RSMarshallingHelper::Unmarshalling(parcel, rsImage) &&
1479                    RSMarshallingHelper::Unmarshalling(parcel, paint);
1480 #ifdef NEW_SKIA
1481     SkSamplingOptions samplingOptions;
1482     success = success && RSMarshallingHelper::Unmarshalling(parcel, samplingOptions);
1483 #endif
1484     if (!success) {
1485         ROSEN_LOGE("BitmapOpItem::Unmarshalling failed!");
1486         return nullptr;
1487     }
1488 
1489 #ifdef NEW_SKIA
1490     return new BitmapOpItem(rsImage, samplingOptions, paint);
1491 #else
1492     return new BitmapOpItem(rsImage, paint);
1493 #endif
1494 }
1495 
1496 // ColorFilterBitmapOpItem
Marshalling(Parcel & parcel) const1497 bool ColorFilterBitmapOpItem::Marshalling(Parcel& parcel) const
1498 {
1499     return BitmapOpItem::Marshalling(parcel);
1500 }
1501 
Unmarshalling(Parcel & parcel)1502 OpItem* ColorFilterBitmapOpItem::Unmarshalling(Parcel &parcel)
1503 {
1504     return BitmapOpItem::Unmarshalling(parcel);
1505 }
1506 
1507 
1508 // BitmapRectOpItem
Marshalling(Parcel & parcel) const1509 bool BitmapRectOpItem::Marshalling(Parcel& parcel) const
1510 {
1511     bool success = RSMarshallingHelper::Marshalling(parcel, rsImage_) &&
1512                    RSMarshallingHelper::Marshalling(parcel, paint_);
1513 #ifdef NEW_SKIA
1514     success = success && RSMarshallingHelper::Marshalling(parcel, samplingOptions_) &&
1515         RSMarshallingHelper::Marshalling(parcel, static_cast<int32_t>(constraint_));
1516 #endif
1517     if (!success) {
1518         ROSEN_LOGE("BitmapRectOpItem::Marshalling failed!");
1519         return false;
1520     }
1521     return success;
1522 }
1523 
Unmarshalling(Parcel & parcel)1524 OpItem* BitmapRectOpItem::Unmarshalling(Parcel& parcel)
1525 {
1526     std::shared_ptr<RSImageBase> rsImage;
1527     SkPaint paint;
1528     bool success = RSMarshallingHelper::Unmarshalling(parcel, rsImage) &&
1529                    RSMarshallingHelper::Unmarshalling(parcel, paint);
1530 #ifdef NEW_SKIA
1531     SkSamplingOptions samplingOptions;
1532     int32_t constraint;
1533     success = success && RSMarshallingHelper::Unmarshalling(parcel, samplingOptions) &&
1534         RSMarshallingHelper::Unmarshalling(parcel, constraint);
1535 #endif
1536     if (!success) {
1537         ROSEN_LOGE("BitmapRectOpItem::Unmarshalling failed!");
1538         return nullptr;
1539     }
1540 
1541 #ifdef NEW_SKIA
1542     return new BitmapRectOpItem(rsImage, samplingOptions, paint, static_cast<SkCanvas::SrcRectConstraint>(constraint));
1543 #else
1544     return new BitmapRectOpItem(rsImage, paint);
1545 #endif
1546 }
1547 
1548 // PixelMapOpItem
Marshalling(Parcel & parcel) const1549 bool PixelMapOpItem::Marshalling(Parcel& parcel) const
1550 {
1551     bool success = RSMarshallingHelper::Marshalling(parcel, rsImage_) &&
1552                    RSMarshallingHelper::Marshalling(parcel, paint_);
1553 #ifdef NEW_SKIA
1554     success = success && RSMarshallingHelper::Marshalling(parcel, samplingOptions_);
1555 #endif
1556     if (!success) {
1557         ROSEN_LOGE("PixelMapOpItem::Marshalling failed!");
1558         return false;
1559     }
1560     return success;
1561 }
1562 
Unmarshalling(Parcel & parcel)1563 OpItem* PixelMapOpItem::Unmarshalling(Parcel& parcel)
1564 {
1565     std::shared_ptr<RSImageBase> rsImage;
1566     SkPaint paint;
1567     bool success = RSMarshallingHelper::Unmarshalling(parcel, rsImage) &&
1568                    RSMarshallingHelper::Unmarshalling(parcel, paint);
1569 #ifdef NEW_SKIA
1570     SkSamplingOptions samplingOptions;
1571     success = success && RSMarshallingHelper::Unmarshalling(parcel, samplingOptions);
1572 #endif
1573     if (!success) {
1574         ROSEN_LOGE("PixelMapOpItem::Unmarshalling failed!");
1575         return nullptr;
1576     }
1577 
1578 #ifdef NEW_SKIA
1579     return new PixelMapOpItem(rsImage, samplingOptions, paint);
1580 #else
1581     return new PixelMapOpItem(rsImage, paint);
1582 #endif
1583 }
1584 
1585 // PixelMapRectOpItem
Marshalling(Parcel & parcel) const1586 bool PixelMapRectOpItem::Marshalling(Parcel& parcel) const
1587 {
1588     bool success = RSMarshallingHelper::Marshalling(parcel, rsImage_) &&
1589                    RSMarshallingHelper::Marshalling(parcel, paint_);
1590 #ifdef NEW_SKIA
1591     success = success && RSMarshallingHelper::Marshalling(parcel, samplingOptions_) &&
1592         RSMarshallingHelper::Marshalling(parcel, static_cast<int32_t>(constraint_));
1593 #endif
1594     if (!success) {
1595         ROSEN_LOGE("PixelMapRectOpItem::Marshalling failed!");
1596         return false;
1597     }
1598     return success;
1599 }
1600 
Unmarshalling(Parcel & parcel)1601 OpItem* PixelMapRectOpItem::Unmarshalling(Parcel& parcel)
1602 {
1603     std::shared_ptr<RSImageBase> rsImage;
1604     SkPaint paint;
1605     bool success = RSMarshallingHelper::Unmarshalling(parcel, rsImage) &&
1606                    RSMarshallingHelper::Unmarshalling(parcel, paint);
1607 #ifdef NEW_SKIA
1608     SkSamplingOptions samplingOptions;
1609     int32_t constraint;
1610     success = success && RSMarshallingHelper::Unmarshalling(parcel, samplingOptions) &&
1611         RSMarshallingHelper::Unmarshalling(parcel, constraint);
1612 #endif
1613     if (!success) {
1614         ROSEN_LOGE("PixelMapRectOpItem::Unmarshalling failed!");
1615         return nullptr;
1616     }
1617 #ifdef NEW_SKIA
1618     return new PixelMapRectOpItem(rsImage, samplingOptions,
1619         paint, static_cast<SkCanvas::SrcRectConstraint>(constraint));
1620 #else
1621     return new PixelMapRectOpItem(rsImage, paint);
1622 #endif
1623 }
1624 
1625 // BitmapNineOpItem
Marshalling(Parcel & parcel) const1626 bool BitmapNineOpItem::Marshalling(Parcel& parcel) const
1627 {
1628     bool success = RSMarshallingHelper::Marshalling(parcel, bitmapInfo_) &&
1629                    RSMarshallingHelper::Marshalling(parcel, center_) &&
1630                    RSMarshallingHelper::Marshalling(parcel, rectDst_) &&
1631                    RSMarshallingHelper::Marshalling(parcel, paint_);
1632 #ifdef NEW_SKIA
1633     success = success && RSMarshallingHelper::Marshalling(parcel, static_cast<int32_t>(filter_));
1634 #endif
1635     if (!success) {
1636         ROSEN_LOGE("BitmapNineOpItem::Marshalling failed!");
1637         return false;
1638     }
1639     return success;
1640 }
1641 
Unmarshalling(Parcel & parcel)1642 OpItem* BitmapNineOpItem::Unmarshalling(Parcel& parcel)
1643 {
1644     RS_TRACE_NAME("BitmapNineOpItem::Unmarshalling");
1645     sk_sp<SkImage> bitmapInfo;
1646     SkIRect center;
1647     SkRect rectDst;
1648     SkPaint paint;
1649     bool success = RSMarshallingHelper::Unmarshalling(parcel, bitmapInfo) &&
1650                    RSMarshallingHelper::Unmarshalling(parcel, center) &&
1651                    RSMarshallingHelper::Unmarshalling(parcel, rectDst) &&
1652                    RSMarshallingHelper::Unmarshalling(parcel, paint);
1653 #ifdef NEW_SKIA
1654     int32_t fliter;
1655     success = success && RSMarshallingHelper::Unmarshalling(parcel, fliter);
1656 #endif
1657     if (!success) {
1658         ROSEN_LOGE("BitmapNineOpItem::Unmarshalling failed!");
1659         return nullptr;
1660     }
1661 #ifdef NEW_SKIA
1662     return new BitmapNineOpItem(bitmapInfo, center, rectDst,
1663         static_cast<SkFilterMode>(fliter), &paint);
1664 #else
1665     return new BitmapNineOpItem(bitmapInfo, center, rectDst, &paint);
1666 #endif
1667 }
1668 
1669 // AdaptiveRRectOpItem
Marshalling(Parcel & parcel) const1670 bool AdaptiveRRectOpItem::Marshalling(Parcel& parcel) const
1671 {
1672     bool success = RSMarshallingHelper::Marshalling(parcel, radius_) &&
1673                    RSMarshallingHelper::Marshalling(parcel, paint_);
1674     if (!success) {
1675         ROSEN_LOGE("AdaptiveRRectOpItem::Marshalling failed!");
1676         return false;
1677     }
1678     return success;
1679 }
1680 
Unmarshalling(Parcel & parcel)1681 OpItem* AdaptiveRRectOpItem::Unmarshalling(Parcel& parcel)
1682 {
1683     float radius;
1684     SkPaint paint;
1685     bool success = RSMarshallingHelper::Unmarshalling(parcel, radius) &&
1686                    RSMarshallingHelper::Unmarshalling(parcel, paint);
1687     if (!success) {
1688         ROSEN_LOGE("AdaptiveRRectOpItem::Unmarshalling failed!");
1689         return nullptr;
1690     }
1691     return new AdaptiveRRectOpItem(radius, paint);
1692 }
1693 
1694 // AdaptiveRRectScaleOpItem
Marshalling(Parcel & parcel) const1695 bool AdaptiveRRectScaleOpItem::Marshalling(Parcel& parcel) const
1696 {
1697     bool success = RSMarshallingHelper::Marshalling(parcel, radiusRatio_) &&
1698                    RSMarshallingHelper::Marshalling(parcel, paint_);
1699     if (!success) {
1700         ROSEN_LOGE("AdaptiveRRectScaleOpItem::Marshalling failed!");
1701         return false;
1702     }
1703     return success;
1704 }
1705 
Unmarshalling(Parcel & parcel)1706 OpItem* AdaptiveRRectScaleOpItem::Unmarshalling(Parcel& parcel)
1707 {
1708     float radiusRatio;
1709     SkPaint paint;
1710     bool success = RSMarshallingHelper::Unmarshalling(parcel, radiusRatio) &&
1711                    RSMarshallingHelper::Unmarshalling(parcel, paint);
1712     if (!success) {
1713         ROSEN_LOGE("AdaptiveRRectScaleOpItem::Unmarshalling failed!");
1714         return nullptr;
1715     }
1716     return new AdaptiveRRectScaleOpItem(radiusRatio, paint);
1717 }
1718 
1719 // ClipAdaptiveRRectOpItem
Marshalling(Parcel & parcel) const1720 bool ClipAdaptiveRRectOpItem::Marshalling(Parcel& parcel) const
1721 {
1722     bool success = RSMarshallingHelper::Marshalling(parcel, radius_);
1723     if (!success) {
1724         ROSEN_LOGE("ClipAdaptiveRRectOpItem::Marshalling failed!");
1725         return false;
1726     }
1727     return success;
1728 }
1729 
Unmarshalling(Parcel & parcel)1730 OpItem* ClipAdaptiveRRectOpItem::Unmarshalling(Parcel& parcel)
1731 {
1732     SkVector radius[CORNER_SIZE];
1733     for (auto i = 0; i < CORNER_SIZE; i++) {
1734         if (!RSMarshallingHelper::Unmarshalling(parcel, radius[i])) {
1735             ROSEN_LOGE("ClipAdaptiveRRectOpItem::Unmarshalling failed!");
1736             return nullptr;
1737         }
1738     }
1739     return new ClipAdaptiveRRectOpItem(radius);
1740 }
1741 
1742 // ClipOutsetRectOpItem
Marshalling(Parcel & parcel) const1743 bool ClipOutsetRectOpItem::Marshalling(Parcel& parcel) const
1744 {
1745     bool success = RSMarshallingHelper::Marshalling(parcel, dx_) &&
1746                    RSMarshallingHelper::Marshalling(parcel, dy_);
1747     if (!success) {
1748         ROSEN_LOGE("ClipOutsetRectOpItem::Marshalling failed!");
1749         return false;
1750     }
1751     return success;
1752 }
1753 
Unmarshalling(Parcel & parcel)1754 OpItem* ClipOutsetRectOpItem::Unmarshalling(Parcel& parcel)
1755 {
1756     float dx;
1757     float dy;
1758     bool success = RSMarshallingHelper::Unmarshalling(parcel, dx) &&
1759                    RSMarshallingHelper::Unmarshalling(parcel, dy);
1760     if (!success) {
1761         ROSEN_LOGE("ClipOutsetRectOpItem::Unmarshalling failed!");
1762         return nullptr;
1763     }
1764     return new ClipOutsetRectOpItem(dx, dy);
1765 }
1766 
1767 // PathOpItem
Marshalling(Parcel & parcel) const1768 bool PathOpItem::Marshalling(Parcel& parcel) const
1769 {
1770     bool success = RSMarshallingHelper::Marshalling(parcel, path_) &&
1771                    RSMarshallingHelper::Marshalling(parcel, paint_);
1772     if (!success) {
1773         ROSEN_LOGE("PathOpItem::Marshalling failed!");
1774         return false;
1775     }
1776     return success;
1777 }
1778 
Unmarshalling(Parcel & parcel)1779 OpItem* PathOpItem::Unmarshalling(Parcel& parcel)
1780 {
1781     SkPath path;
1782     SkPaint paint;
1783     bool success = RSMarshallingHelper::Unmarshalling(parcel, path) &&
1784                    RSMarshallingHelper::Unmarshalling(parcel, paint);
1785     if (!success) {
1786         ROSEN_LOGE("PathOpItem::Unmarshalling failed!");
1787         return nullptr;
1788     }
1789     return new PathOpItem(path, paint);
1790 }
1791 
1792 // ClipPathOpItem
Marshalling(Parcel & parcel) const1793 bool ClipPathOpItem::Marshalling(Parcel& parcel) const
1794 {
1795     bool success = RSMarshallingHelper::Marshalling(parcel, path_) &&
1796                    RSMarshallingHelper::Marshalling(parcel, clipOp_) &&
1797                    RSMarshallingHelper::Marshalling(parcel, doAA_);
1798     if (!success) {
1799         ROSEN_LOGE("ClipPathOpItem::Marshalling failed!");
1800         return false;
1801     }
1802     return success;
1803 }
1804 
Unmarshalling(Parcel & parcel)1805 OpItem* ClipPathOpItem::Unmarshalling(Parcel& parcel)
1806 {
1807     SkPath path;
1808     SkClipOp clipOp;
1809     bool doAA;
1810     bool success = RSMarshallingHelper::Unmarshalling(parcel, path) &&
1811                    RSMarshallingHelper::Unmarshalling(parcel, clipOp) &&
1812                    RSMarshallingHelper::Unmarshalling(parcel, doAA);
1813     if (!success) {
1814         ROSEN_LOGE("ClipPathOpItem::Unmarshalling failed!");
1815         return nullptr;
1816     }
1817     return new ClipPathOpItem(path, clipOp, doAA);
1818 }
1819 
1820 // PaintOpItem
Marshalling(Parcel & parcel) const1821 bool PaintOpItem::Marshalling(Parcel& parcel) const
1822 {
1823     bool success = RSMarshallingHelper::Marshalling(parcel, paint_);
1824     if (!success) {
1825         ROSEN_LOGE("PaintOpItem::Marshalling failed!");
1826         return false;
1827     }
1828     return success;
1829 }
1830 
Unmarshalling(Parcel & parcel)1831 OpItem* PaintOpItem::Unmarshalling(Parcel& parcel)
1832 {
1833     SkPaint paint;
1834     bool success = RSMarshallingHelper::Unmarshalling(parcel, paint);
1835     if (!success) {
1836         ROSEN_LOGE("PaintOpItem::Unmarshalling failed!");
1837         return nullptr;
1838     }
1839     return new PaintOpItem(paint);
1840 }
1841 
1842 // ConcatOpItem
Marshalling(Parcel & parcel) const1843 bool ConcatOpItem::Marshalling(Parcel& parcel) const
1844 {
1845     bool success = RSMarshallingHelper::Marshalling(parcel, matrix_);
1846     if (!success) {
1847         ROSEN_LOGE("ConcatOpItem::Marshalling failed!");
1848         return false;
1849     }
1850     return success;
1851 }
1852 
Unmarshalling(Parcel & parcel)1853 OpItem* ConcatOpItem::Unmarshalling(Parcel& parcel)
1854 {
1855 #ifdef NEW_SKIA
1856     SkM44 matrix;
1857 #else
1858     SkMatrix matrix;
1859 #endif
1860     bool success = RSMarshallingHelper::Unmarshalling(parcel, matrix);
1861     if (!success) {
1862         ROSEN_LOGE("ConcatOpItem::Unmarshalling failed!");
1863         return nullptr;
1864     }
1865     return new ConcatOpItem(matrix);
1866 }
1867 
1868 // SaveLayerOpItem
Marshalling(Parcel & parcel) const1869 bool SaveLayerOpItem::Marshalling(Parcel& parcel) const
1870 {
1871     bool success = parcel.WriteBool(rectPtr_ != nullptr);
1872     if (rectPtr_) {
1873         success = success && RSMarshallingHelper::Marshalling(parcel, rect_);
1874     }
1875     success = success && RSMarshallingHelper::Marshalling(parcel, backdrop_) &&
1876                RSMarshallingHelper::Marshalling(parcel, flags_) &&
1877                RSMarshallingHelper::Marshalling(parcel, paint_);
1878 #ifndef NEW_SKIA
1879     success = success && RSMarshallingHelper::Marshalling(parcel, mask_) &&
1880                RSMarshallingHelper::Marshalling(parcel, matrix_);
1881 #endif
1882     if (!success) {
1883         ROSEN_LOGE("SaveLayerOpItem::Marshalling failed!");
1884         return false;
1885     }
1886     return success;
1887 }
1888 
Unmarshalling(Parcel & parcel)1889 OpItem* SaveLayerOpItem::Unmarshalling(Parcel& parcel)
1890 {
1891     bool isRectExist;
1892     SkRect rect;
1893     SkRect* rectPtr = nullptr;
1894     sk_sp<SkImageFilter> backdrop;
1895     SkCanvas::SaveLayerFlags flags;
1896     SkPaint paint;
1897     bool success = parcel.ReadBool(isRectExist);
1898     if (isRectExist) {
1899         success = success && RSMarshallingHelper::Unmarshalling(parcel, rect);
1900         rectPtr = &rect;
1901     }
1902     success = success && RSMarshallingHelper::Unmarshalling(parcel, backdrop) &&
1903                RSMarshallingHelper::Unmarshalling(parcel, flags) &&
1904                RSMarshallingHelper::Unmarshalling(parcel, paint);
1905 #ifndef NEW_SKIA
1906     sk_sp<SkImage> mask;
1907     SkMatrix matrix;
1908     success = success && RSMarshallingHelper::Unmarshalling(parcel, mask) &&
1909                RSMarshallingHelper::Unmarshalling(parcel, matrix);
1910 #endif
1911     if (!success) {
1912         ROSEN_LOGE("SaveLayerOpItem::Unmarshalling failed!");
1913         return nullptr;
1914     }
1915 #ifdef NEW_SKIA
1916     SkCanvas::SaveLayerRec rec = { rectPtr, &paint, backdrop.get(), flags };
1917 #else
1918     SkCanvas::SaveLayerRec rec = { rectPtr, &paint, backdrop.get(), mask.get(), &matrix, flags };
1919 #endif
1920     return new SaveLayerOpItem(rec);
1921 }
1922 
1923 // DrawableOpItem
Marshalling(Parcel & parcel) const1924 bool DrawableOpItem::Marshalling(Parcel& parcel) const
1925 {
1926     bool success = RSMarshallingHelper::Marshalling(parcel, drawable_) &&
1927                    RSMarshallingHelper::Marshalling(parcel, matrix_);
1928     if (!success) {
1929         ROSEN_LOGE("DrawableOpItem::Marshalling failed!");
1930         return false;
1931     }
1932     return success;
1933 }
1934 
Unmarshalling(Parcel & parcel)1935 OpItem* DrawableOpItem::Unmarshalling(Parcel& parcel)
1936 {
1937     sk_sp<SkDrawable> drawable;
1938     SkMatrix matrix;
1939     bool success = RSMarshallingHelper::Unmarshalling(parcel, drawable) &&
1940                    RSMarshallingHelper::Unmarshalling(parcel, matrix);
1941     if (!success) {
1942         ROSEN_LOGE("DrawableOpItem::Unmarshalling failed!");
1943         return nullptr;
1944     }
1945     return new DrawableOpItem(drawable.release(), &matrix);
1946 }
1947 
1948 // PictureOpItem
Marshalling(Parcel & parcel) const1949 bool PictureOpItem::Marshalling(Parcel& parcel) const
1950 {
1951     bool success = RSMarshallingHelper::Marshalling(parcel, picture_) &&
1952                    RSMarshallingHelper::Marshalling(parcel, matrix_) &&
1953                    RSMarshallingHelper::Marshalling(parcel, paint_);
1954     if (!success) {
1955         ROSEN_LOGE("PictureOpItem::Marshalling failed!");
1956         return false;
1957     }
1958     return success;
1959 }
1960 
Unmarshalling(Parcel & parcel)1961 OpItem* PictureOpItem::Unmarshalling(Parcel& parcel)
1962 {
1963     sk_sp<SkPicture> picture;
1964     SkMatrix matrix;
1965     SkPaint paint;
1966     bool success = RSMarshallingHelper::Unmarshalling(parcel, picture) &&
1967                    RSMarshallingHelper::Unmarshalling(parcel, matrix) &&
1968                    RSMarshallingHelper::Unmarshalling(parcel, paint);
1969     if (!success) {
1970         ROSEN_LOGE("PictureOpItem::Unmarshalling failed!");
1971         return nullptr;
1972     }
1973     return new PictureOpItem(picture, &matrix, &paint);
1974 }
1975 
1976 // PointsOpItem
Marshalling(Parcel & parcel) const1977 bool PointsOpItem::Marshalling(Parcel& parcel) const
1978 {
1979     bool success = RSMarshallingHelper::Marshalling(parcel, mode_) &&
1980                    RSMarshallingHelper::Marshalling(parcel, count_) &&
1981                    RSMarshallingHelper::MarshallingArray(parcel, processedPoints_, count_) &&
1982                    RSMarshallingHelper::Marshalling(parcel, paint_);
1983     if (!success) {
1984         ROSEN_LOGE("PointsOpItem::Marshalling failed!");
1985         return false;
1986     }
1987     return success;
1988 }
1989 
Unmarshalling(Parcel & parcel)1990 OpItem* PointsOpItem::Unmarshalling(Parcel& parcel)
1991 {
1992     SkCanvas::PointMode mode;
1993     int count;
1994     const SkPoint* processedPoints = nullptr;
1995     SkPaint paint;
1996     bool success = RSMarshallingHelper::Unmarshalling(parcel, mode) &&
1997                    RSMarshallingHelper::Unmarshalling(parcel, count) &&
1998                    RSMarshallingHelper::UnmarshallingArray(parcel, processedPoints, count) &&
1999                    RSMarshallingHelper::Unmarshalling(parcel, paint);
2000     if (!success) {
2001         ROSEN_LOGE("PointsOpItem::Unmarshalling failed!");
2002         return nullptr;
2003     }
2004     return new PointsOpItem(mode, count, processedPoints, paint);
2005 }
2006 
2007 // VerticesOpItem
Marshalling(Parcel & parcel) const2008 bool VerticesOpItem::Marshalling(Parcel& parcel) const
2009 {
2010     bool success = RSMarshallingHelper::Marshalling(parcel, vertices_) &&
2011                    RSMarshallingHelper::Marshalling(parcel, mode_) &&
2012                    RSMarshallingHelper::Marshalling(parcel, paint_);
2013 #ifndef NEW_SKIA
2014     success = success && RSMarshallingHelper::Marshalling(parcel, boneCount_) &&
2015         RSMarshallingHelper::MarshallingArray(parcel, bones_, boneCount_);
2016 #endif
2017     if (!success) {
2018         ROSEN_LOGE("VerticesOpItem::Marshalling failed!");
2019         return false;
2020     }
2021     return success;
2022 }
2023 
Unmarshalling(Parcel & parcel)2024 OpItem* VerticesOpItem::Unmarshalling(Parcel& parcel)
2025 {
2026     sk_sp<SkVertices> vertices;
2027     SkBlendMode mode;
2028     SkPaint paint;
2029     bool success = RSMarshallingHelper::Unmarshalling(parcel, vertices) &&
2030                    RSMarshallingHelper::Unmarshalling(parcel, mode) &&
2031                    RSMarshallingHelper::Unmarshalling(parcel, paint);
2032 #ifndef NEW_SKIA
2033     const SkVertices::Bone* bones = nullptr;
2034     int boneCount;
2035     success = success && RSMarshallingHelper::Unmarshalling(parcel, boneCount) &&
2036         RSMarshallingHelper::UnmarshallingArray(parcel, bones, boneCount);
2037 #endif
2038     if (!success) {
2039         ROSEN_LOGE("VerticesOpItem::Unmarshalling failed!");
2040         return nullptr;
2041     }
2042 #ifdef NEW_SKIA
2043     return new VerticesOpItem(vertices.get(), mode, paint);
2044 #else
2045     return new VerticesOpItem(vertices.get(), bones, boneCount, mode, paint);
2046 #endif
2047 }
2048 
2049 // ShadowRecOpItem
Marshalling(Parcel & parcel) const2050 bool ShadowRecOpItem::Marshalling(Parcel& parcel) const
2051 {
2052     bool success = RSMarshallingHelper::Marshalling(parcel, path_) &&
2053                    RSMarshallingHelper::Marshalling(parcel, rec_);
2054     if (!success) {
2055         ROSEN_LOGE("ShadowRecOpItem::Marshalling failed!");
2056         return false;
2057     }
2058     return success;
2059 }
2060 
Unmarshalling(Parcel & parcel)2061 OpItem* ShadowRecOpItem::Unmarshalling(Parcel& parcel)
2062 {
2063     SkPath path;
2064     SkDrawShadowRec rec;
2065     bool success = RSMarshallingHelper::Unmarshalling(parcel, path) &&
2066                    RSMarshallingHelper::Unmarshalling(parcel, rec);
2067     if (!success) {
2068         ROSEN_LOGE("ShadowRecOpItem::Unmarshalling failed!");
2069         return nullptr;
2070     }
2071     return new ShadowRecOpItem(path, rec);
2072 }
2073 
2074 // MultiplyAlphaOpItem
Marshalling(Parcel & parcel) const2075 bool MultiplyAlphaOpItem::Marshalling(Parcel& parcel) const
2076 {
2077     bool success = RSMarshallingHelper::Marshalling(parcel, alpha_);
2078     if (!success) {
2079         ROSEN_LOGE("MultiplyAlphaOpItem::Marshalling failed!");
2080         return false;
2081     }
2082     return success;
2083 }
2084 
Unmarshalling(Parcel & parcel)2085 OpItem* MultiplyAlphaOpItem::Unmarshalling(Parcel& parcel)
2086 {
2087     float alpha;
2088     bool success = RSMarshallingHelper::Unmarshalling(parcel, alpha);
2089     if (!success) {
2090         ROSEN_LOGE("MultiplyAlphaOpItem::Unmarshalling failed!");
2091         return nullptr;
2092     }
2093     return new MultiplyAlphaOpItem(alpha);
2094 }
2095 
2096 // SaveAlphaOpItem
Unmarshalling(Parcel & parcel)2097 OpItem* SaveAlphaOpItem::Unmarshalling(Parcel& parcel)
2098 {
2099     return new SaveAlphaOpItem();
2100 }
2101 
2102 // RestoreAlphaOpItem
Unmarshalling(Parcel & parcel)2103 OpItem* RestoreAlphaOpItem::Unmarshalling(Parcel& parcel)
2104 {
2105     return new RestoreAlphaOpItem();
2106 }
2107 
2108 // SurfaceBufferOpItem
2109 #ifdef ROSEN_OHOS
Marshalling(Parcel & parcel) const2110 bool SurfaceBufferOpItem::Marshalling(Parcel& parcel) const
2111 {
2112     MessageParcel* parcelSurfaceBuffer = static_cast<MessageParcel*>(&parcel);
2113     WriteSurfaceBufferImpl(
2114         *parcelSurfaceBuffer, surfaceBufferInfo_.surfaceBuffer_->GetSeqNum(), surfaceBufferInfo_.surfaceBuffer_);
2115     bool success = RSMarshallingHelper::Marshalling(parcel, surfaceBufferInfo_.offSetX_) &&
2116                    RSMarshallingHelper::Marshalling(parcel, surfaceBufferInfo_.offSetY_) &&
2117                    RSMarshallingHelper::Marshalling(parcel, surfaceBufferInfo_.width_) &&
2118                    RSMarshallingHelper::Marshalling(parcel, surfaceBufferInfo_.height_);
2119     return success;
2120 }
2121 
Unmarshalling(Parcel & parcel)2122 OpItem* SurfaceBufferOpItem::Unmarshalling(Parcel& parcel)
2123 {
2124     RSSurfaceBufferInfo surfaceBufferInfo;
2125     MessageParcel *parcelSurfaceBuffer = static_cast<MessageParcel*>(&parcel);
2126     uint32_t sequence = 1U;
2127     ReadSurfaceBufferImpl(*parcelSurfaceBuffer, sequence, surfaceBufferInfo.surfaceBuffer_);
2128     bool success = RSMarshallingHelper::Unmarshalling(parcel, surfaceBufferInfo.offSetX_) &&
2129                    RSMarshallingHelper::Unmarshalling(parcel, surfaceBufferInfo.offSetY_) &&
2130                    RSMarshallingHelper::Unmarshalling(parcel, surfaceBufferInfo.width_) &&
2131                    RSMarshallingHelper::Unmarshalling(parcel, surfaceBufferInfo.height_);
2132     if (!success) {
2133         ROSEN_LOGE("SurfaceBufferOptItem::Unmarshalling failed");
2134         return nullptr;
2135     }
2136     return new SurfaceBufferOpItem(surfaceBufferInfo);
2137 }
2138 #endif
SetNodeId(NodeId id)2139 void OpItemWithRSImage::SetNodeId(NodeId id)
2140 {
2141     if (rsImage_) {
2142         rsImage_->UpdateNodeIdToPicture(id);
2143     }
2144 }
2145 
SetNodeId(NodeId id)2146 void ImageWithParmOpItem::SetNodeId(NodeId id)
2147 {
2148     if (rsImage_) {
2149         rsImage_->UpdateNodeIdToPicture(id);
2150     }
2151 }
2152 } // namespace Rosen
2153 } // namespace OHOS
2154 
2155 #endif // USE_ROSEN_DRAWING
2156