• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 #include "pipeline/rs_recording_canvas.h"
18 
19 #include "pipeline/rs_draw_cmd.h"
20 #include "platform/common/rs_log.h"
21 #include "platform/common/rs_system_properties.h"
22 #include "rs_trace.h"
23 
24 #define RS_DRAWOP_TRACE_FUNC() \
25     if (RSSystemProperties::GetDrawOpTraceEnabled()) { \
26         RS_TRACE_FUNC(); \
27     } do {} while (0)
28 
29 namespace OHOS {
30 namespace Rosen {
RSRecordingCanvas(int width,int height)31 RSRecordingCanvas::RSRecordingCanvas(int width, int height) : SkCanvasVirtualEnforcer<SkNoDrawCanvas>(width, height)
32 {
33     drawCmdList_ = std::make_shared<DrawCmdList>(width, height);
34 }
35 
~RSRecordingCanvas()36 RSRecordingCanvas::~RSRecordingCanvas() {}
37 
GetDrawCmdList() const38 std::shared_ptr<DrawCmdList> RSRecordingCanvas::GetDrawCmdList() const
39 {
40     return drawCmdList_;
41 }
42 
43 #ifdef NEW_SKIA
recordingContext()44 GrRecordingContext* RSRecordingCanvas::recordingContext()
45 {
46     return grContext_;
47 }
48 
SetGrRecordingContext(GrRecordingContext * context)49 void RSRecordingCanvas::SetGrRecordingContext(GrRecordingContext* context)
50 {
51     grContext_ = context;
52 }
53 
didConcat44(const SkM44 & mat)54 void RSRecordingCanvas::didConcat44(const SkM44& mat)
55 {
56     RS_DRAWOP_TRACE_FUNC();
57     std::unique_ptr<OpItem> op = std::make_unique<ConcatOpItem>(mat);
58     AddOp(std::move(op));
59 }
60 
didSetM44(const SkM44 & mat)61 void RSRecordingCanvas::didSetM44(const SkM44& mat)
62 {
63     RS_DRAWOP_TRACE_FUNC();
64     std::unique_ptr<OpItem> op = std::make_unique<MatrixOpItem>(mat);
65     AddOp(std::move(op));
66 }
67 
didScale(SkScalar dx,SkScalar dy)68 void RSRecordingCanvas::didScale(SkScalar dx, SkScalar dy)
69 {
70     RS_DRAWOP_TRACE_FUNC();
71     std::unique_ptr<OpItem> op = std::make_unique<ScaleOpItem>(dx, dy);
72     AddOp(std::move(op));
73 }
74 
onDrawGlyphRunList(const SkGlyphRunList & glyphRunList,const SkPaint & paint)75 void RSRecordingCanvas::onDrawGlyphRunList(const SkGlyphRunList& glyphRunList, const SkPaint& paint)
76 {
77     ROSEN_LOGE("RSRecordingCanvas::onDrawGlyphRunList not support yet");
78 }
onDrawImage2(const SkImage * img,SkScalar dx,SkScalar dy,const SkSamplingOptions & samplingOptions,const SkPaint * paint)79 void RSRecordingCanvas::onDrawImage2(const SkImage* img, SkScalar dx, SkScalar dy,
80     const SkSamplingOptions& samplingOptions, const SkPaint* paint)
81 {
82     RS_DRAWOP_TRACE_FUNC();
83     std::unique_ptr<OpItem> op = std::make_unique<BitmapOpItem>(sk_ref_sp(img), dx, dy, samplingOptions, paint);
84     AddOp(std::move(op));
85 }
onDrawImageRect2(const SkImage * img,const SkRect & src,const SkRect & dst,const SkSamplingOptions & samplingOptions,const SkPaint * paint,SrcRectConstraint constraint)86 void RSRecordingCanvas::onDrawImageRect2(const SkImage* img, const SkRect& src, const SkRect& dst,
87     const SkSamplingOptions& samplingOptions, const SkPaint* paint, SrcRectConstraint constraint)
88 {
89     RS_DRAWOP_TRACE_FUNC();
90     std::unique_ptr<OpItem> op =
91         std::make_unique<BitmapRectOpItem>(sk_ref_sp(img), &src, dst, samplingOptions, paint, constraint);
92     AddOp(std::move(op));
93 }
onDrawImageLattice2(const SkImage * img,const Lattice & lattice,const SkRect & dst,SkFilterMode mode,const SkPaint * paint)94 void RSRecordingCanvas::onDrawImageLattice2(const SkImage* img, const Lattice& lattice, const SkRect& dst,
95     SkFilterMode mode, const SkPaint* paint)
96 {
97     DrawImageLatticeAsBitmap(img, lattice, dst, paint);
98 }
99 
onDrawAtlas2(const SkImage *,const SkRSXform[],const SkRect src[],const SkColor[],int count,SkBlendMode mode,const SkSamplingOptions & samplingOptions,const SkRect * cull,const SkPaint * paint)100 void RSRecordingCanvas::onDrawAtlas2(const SkImage*, const SkRSXform[], const SkRect src[],
101     const SkColor[], int count, SkBlendMode mode, const SkSamplingOptions& samplingOptions,
102     const SkRect* cull, const SkPaint* paint)
103 {
104     ROSEN_LOGE("RSRecordingCanvas::onDrawAtlas2 not support yet");
105 }
onDrawEdgeAAImageSet2(const ImageSetEntry imageSet[],int count,const SkPoint dstClips[],const SkMatrix preViewMatrices[],const SkSamplingOptions & SamplingOptions,const SkPaint * paint,SrcRectConstraint constraint)106 void RSRecordingCanvas::onDrawEdgeAAImageSet2(const ImageSetEntry imageSet[], int count,
107     const SkPoint dstClips[], const SkMatrix preViewMatrices[],
108     const SkSamplingOptions& SamplingOptions, const SkPaint* paint,
109     SrcRectConstraint constraint)
110 {
111     ROSEN_LOGE("RSRecordingCanvas::onDrawEdgeAAImageSet2 not support yet");
112 }
onDrawVerticesObject(const SkVertices * vertices,SkBlendMode mode,const SkPaint & paint)113 void RSRecordingCanvas::onDrawVerticesObject(const SkVertices* vertices, SkBlendMode mode, const SkPaint& paint)
114 {
115     RS_DRAWOP_TRACE_FUNC();
116     std::unique_ptr<OpItem> op = std::make_unique<VerticesOpItem>(vertices, mode, paint);
117     AddOp(std::move(op));
118 }
onDrawEdgeAAQuad(const SkRect & rect,const SkPoint clip[4],QuadAAFlags aaFlags,const SkColor4f & color,SkBlendMode mode)119 void RSRecordingCanvas::onDrawEdgeAAQuad(const SkRect& rect, const SkPoint clip[4], QuadAAFlags aaFlags,
120     const SkColor4f& color, SkBlendMode mode)
121 {
122     ROSEN_LOGE("RSRecordingCanvas::onDrawEdgeAAQuad not support yet");
123 }
124 
DrawPixelMapRect(const std::shared_ptr<Media::PixelMap> & pixelmap,const SkRect & src,const SkRect & dst,const SkSamplingOptions & samplingOptions,const SkPaint * paint,SrcRectConstraint constraint)125 void RSRecordingCanvas::DrawPixelMapRect(
126     const std::shared_ptr<Media::PixelMap>& pixelmap, const SkRect& src, const SkRect& dst,
127     const SkSamplingOptions& samplingOptions, const SkPaint* paint, SrcRectConstraint constraint)
128 {
129     RS_DRAWOP_TRACE_FUNC();
130     std::unique_ptr<OpItem> op =
131         std::make_unique<PixelMapRectOpItem>(pixelmap, src, dst, samplingOptions, paint, constraint);
132     AddOp(std::move(op));
133 }
134 
DrawPixelMapRect(const std::shared_ptr<Media::PixelMap> & pixelmap,const SkRect & dst,const SkSamplingOptions & samplingOptions,const SkPaint * paint)135 void RSRecordingCanvas::DrawPixelMapRect(const std::shared_ptr<Media::PixelMap>& pixelmap, const SkRect& dst,
136     const SkSamplingOptions& samplingOptions, const SkPaint* paint)
137 {
138     DrawPixelMapRect(pixelmap, SkRect::MakeIWH(pixelmap->GetWidth(), pixelmap->GetHeight()),
139         dst, samplingOptions, paint);
140 }
141 
DrawPixelMap(const std::shared_ptr<Media::PixelMap> & pixelmap,SkScalar x,SkScalar y,const SkSamplingOptions & samplingOptions,const SkPaint * paint)142 void RSRecordingCanvas::DrawPixelMap(const std::shared_ptr<Media::PixelMap>& pixelmap, SkScalar x, SkScalar y,
143     const SkSamplingOptions& samplingOptions, const SkPaint* paint)
144 {
145     RS_DRAWOP_TRACE_FUNC();
146     std::unique_ptr<OpItem> op = std::make_unique<PixelMapOpItem>(pixelmap, x, y, samplingOptions, paint);
147     AddOp(std::move(op));
148 }
149 
DrawImageWithParm(const sk_sp<SkImage> img,const sk_sp<SkData> data,const Rosen::RsImageInfo & rsimageInfo,const SkSamplingOptions & samplingOptions,const SkPaint & paint)150 void RSRecordingCanvas::DrawImageWithParm(const sk_sp<SkImage>img, const sk_sp<SkData> data,
151     const Rosen::RsImageInfo& rsimageInfo, const SkSamplingOptions& samplingOptions, const SkPaint& paint)
152 {
153     RS_DRAWOP_TRACE_FUNC();
154     std::unique_ptr<OpItem> op = std::make_unique<ImageWithParmOpItem>(
155         img, data, rsimageInfo, samplingOptions, paint);
156     AddOp(std::move(op));
157 }
158 
DrawPixelMapWithParm(const std::shared_ptr<Media::PixelMap> & pixelmap,const Rosen::RsImageInfo & rsImageInfo,const SkSamplingOptions & samplingOptions,const SkPaint & paint)159 void RSRecordingCanvas::DrawPixelMapWithParm(const std::shared_ptr<Media::PixelMap>& pixelmap,
160     const Rosen::RsImageInfo& rsImageInfo, const SkSamplingOptions& samplingOptions, const SkPaint& paint)
161 {
162     RS_DRAWOP_TRACE_FUNC();
163     std::unique_ptr<OpItem> op = std::make_unique<ImageWithParmOpItem>(pixelmap, rsImageInfo, samplingOptions, paint);
164     AddOp(std::move(op));
165 }
166 #else
getGrContext()167 GrContext* RSRecordingCanvas::getGrContext()
168 {
169     return grContext_;
170 }
171 
SetGrContext(GrContext * grContext)172 void RSRecordingCanvas::SetGrContext(GrContext* grContext)
173 {
174     grContext_ = grContext;
175 }
176 
didConcat(const SkMatrix & matrix)177 void RSRecordingCanvas::didConcat(const SkMatrix& matrix)
178 {
179     RS_DRAWOP_TRACE_FUNC();
180     std::unique_ptr<OpItem> op = std::make_unique<ConcatOpItem>(matrix);
181     AddOp(std::move(op));
182 }
183 
didSetMatrix(const SkMatrix & matrix)184 void RSRecordingCanvas::didSetMatrix(const SkMatrix& matrix)
185 {
186     RS_DRAWOP_TRACE_FUNC();
187     std::unique_ptr<OpItem> op = std::make_unique<MatrixOpItem>(matrix);
188     AddOp(std::move(op));
189 }
190 
onDrawBitmap(const SkBitmap & bm,SkScalar x,SkScalar y,const SkPaint * paint)191 void RSRecordingCanvas::onDrawBitmap(const SkBitmap& bm, SkScalar x, SkScalar y, const SkPaint* paint)
192 {
193     RS_DRAWOP_TRACE_FUNC();
194     std::unique_ptr<OpItem> op = std::make_unique<BitmapOpItem>(SkImage::MakeFromBitmap(bm), x, y, paint);
195     AddOp(std::move(op));
196 }
197 
onDrawBitmapLattice(const SkBitmap & bm,const SkCanvas::Lattice & lattice,const SkRect & dst,const SkPaint * paint)198 void RSRecordingCanvas::onDrawBitmapLattice(
199     const SkBitmap& bm, const SkCanvas::Lattice& lattice, const SkRect& dst, const SkPaint* paint)
200 {
201     // use DrawImageLatticeAsBitmap instead of BitmapLatticeOpItem
202     sk_sp<SkImage> image =  SkImage::MakeFromBitmap(bm);
203     DrawImageLatticeAsBitmap(image.get(), lattice, dst, paint);
204 }
205 
onDrawBitmapNine(const SkBitmap & bm,const SkIRect & center,const SkRect & dst,const SkPaint * paint)206 void RSRecordingCanvas::onDrawBitmapNine(
207     const SkBitmap& bm, const SkIRect& center, const SkRect& dst, const SkPaint* paint)
208 {
209     RS_DRAWOP_TRACE_FUNC();
210     std::unique_ptr<OpItem> op = std::make_unique<BitmapNineOpItem>(SkImage::MakeFromBitmap(bm), center, dst, paint);
211     AddOp(std::move(op));
212 }
213 
onDrawBitmapRect(const SkBitmap & bm,const SkRect * src,const SkRect & dst,const SkPaint * paint,SrcRectConstraint constraint)214 void RSRecordingCanvas::onDrawBitmapRect(
215     const SkBitmap& bm, const SkRect* src, const SkRect& dst, const SkPaint* paint, SrcRectConstraint constraint)
216 {
217     RS_DRAWOP_TRACE_FUNC();
218     std::unique_ptr<OpItem> op = std::make_unique<BitmapRectOpItem>(SkImage::MakeFromBitmap(bm), src, dst, paint);
219     AddOp(std::move(op));
220 }
221 
onDrawImage(const SkImage * img,SkScalar x,SkScalar y,const SkPaint * paint)222 void RSRecordingCanvas::onDrawImage(const SkImage* img, SkScalar x, SkScalar y, const SkPaint* paint)
223 {
224     RS_DRAWOP_TRACE_FUNC();
225     std::unique_ptr<OpItem> op = std::make_unique<BitmapOpItem>(sk_ref_sp(img), x, y, paint);
226     AddOp(std::move(op));
227 }
228 
onDrawImageLattice(const SkImage * img,const SkCanvas::Lattice & lattice,const SkRect & dst,const SkPaint * paint)229 void RSRecordingCanvas::onDrawImageLattice(
230     const SkImage* img, const SkCanvas::Lattice& lattice, const SkRect& dst, const SkPaint* paint)
231 {
232     // use DrawImageLatticeAsBitmap instead of BitmapLatticeOpItem
233     DrawImageLatticeAsBitmap(img, lattice, dst, paint);
234 }
235 
onDrawImageNine(const SkImage * img,const SkIRect & center,const SkRect & dst,const SkPaint * paint)236 void RSRecordingCanvas::onDrawImageNine(
237     const SkImage* img, const SkIRect& center, const SkRect& dst, const SkPaint* paint)
238 {
239     RS_DRAWOP_TRACE_FUNC();
240     std::unique_ptr<OpItem> op = std::make_unique<BitmapNineOpItem>(sk_ref_sp(img), center, dst, paint);
241     AddOp(std::move(op));
242 }
243 
onDrawImageRect(const SkImage * img,const SkRect * src,const SkRect & dst,const SkPaint * paint,SrcRectConstraint constraint)244 void RSRecordingCanvas::onDrawImageRect(
245     const SkImage* img, const SkRect* src, const SkRect& dst, const SkPaint* paint, SrcRectConstraint constraint)
246 {
247     RS_DRAWOP_TRACE_FUNC();
248     std::unique_ptr<OpItem> op = std::make_unique<BitmapRectOpItem>(sk_ref_sp(img), src, dst, paint);
249     AddOp(std::move(op));
250 }
251 
onDrawVerticesObject(const SkVertices * vertices,const SkVertices::Bone bones[],int boneCount,SkBlendMode mode,const SkPaint & paint)252 void RSRecordingCanvas::onDrawVerticesObject(
253     const SkVertices* vertices, const SkVertices::Bone bones[], int boneCount, SkBlendMode mode, const SkPaint& paint)
254 {
255     RS_DRAWOP_TRACE_FUNC();
256     std::unique_ptr<OpItem> op = std::make_unique<VerticesOpItem>(vertices, bones, boneCount, mode, paint);
257     AddOp(std::move(op));
258 }
259 
onDrawAtlas(const SkImage * atlas,const SkRSXform xforms[],const SkRect texs[],const SkColor colors[],int count,SkBlendMode bmode,const SkRect * cull,const SkPaint * paint)260 void RSRecordingCanvas::onDrawAtlas(const SkImage* atlas, const SkRSXform xforms[], const SkRect texs[],
261     const SkColor colors[], int count, SkBlendMode bmode, const SkRect* cull, const SkPaint* paint)
262 {
263     // [PLANNING]: To be implemented
264     ROSEN_LOGE("RSRecordingCanvas::onDrawAtlas not support yet");
265 }
266 
DrawPixelMapRect(const std::shared_ptr<Media::PixelMap> & pixelmap,const SkRect & src,const SkRect & dst,const SkPaint * paint,SrcRectConstraint constraint)267 void RSRecordingCanvas::DrawPixelMapRect(const std::shared_ptr<Media::PixelMap>& pixelmap, const SkRect& src,
268     const SkRect& dst, const SkPaint* paint, SrcRectConstraint constraint)
269 {
270     RS_DRAWOP_TRACE_FUNC();
271     std::unique_ptr<OpItem> op = std::make_unique<PixelMapRectOpItem>(pixelmap, src, dst, paint);
272     AddOp(std::move(op));
273 }
274 
DrawPixelMapRect(const std::shared_ptr<Media::PixelMap> & pixelmap,const SkRect & dst,const SkPaint * paint)275 void RSRecordingCanvas::DrawPixelMapRect(
276     const std::shared_ptr<Media::PixelMap>& pixelmap, const SkRect& dst, const SkPaint* paint)
277 {
278     DrawPixelMapRect(pixelmap, SkRect::MakeIWH(pixelmap->GetWidth(), pixelmap->GetHeight()), dst, paint);
279 }
280 
DrawPixelMap(const std::shared_ptr<Media::PixelMap> & pixelmap,SkScalar x,SkScalar y,const SkPaint * paint)281 void RSRecordingCanvas::DrawPixelMap(
282     const std::shared_ptr<Media::PixelMap>& pixelmap, SkScalar x, SkScalar y, const SkPaint* paint)
283 {
284     RS_DRAWOP_TRACE_FUNC();
285     std::unique_ptr<OpItem> op = std::make_unique<PixelMapOpItem>(pixelmap, x, y, paint);
286     AddOp(std::move(op));
287 }
288 
DrawImageWithParm(const sk_sp<SkImage> img,const sk_sp<SkData> data,const Rosen::RsImageInfo & rsimageInfo,const SkPaint & paint)289 void RSRecordingCanvas::DrawImageWithParm(const sk_sp<SkImage>img, const sk_sp<SkData> data,
290     const Rosen::RsImageInfo& rsimageInfo, const SkPaint& paint)
291 {
292     RS_DRAWOP_TRACE_FUNC();
293     std::unique_ptr<OpItem> op = std::make_unique<ImageWithParmOpItem>(img, data, rsimageInfo, paint);
294     AddOp(std::move(op));
295 }
296 
DrawPixelMapWithParm(const std::shared_ptr<Media::PixelMap> & pixelmap,const Rosen::RsImageInfo & rsImageInfo,const SkPaint & paint)297 void RSRecordingCanvas::DrawPixelMapWithParm(
298     const std::shared_ptr<Media::PixelMap>& pixelmap, const Rosen::RsImageInfo& rsImageInfo, const SkPaint& paint)
299 {
300     RS_DRAWOP_TRACE_FUNC();
301     std::unique_ptr<OpItem> op = std::make_unique<ImageWithParmOpItem>(pixelmap, rsImageInfo, paint);
302     AddOp(std::move(op));
303 }
304 #endif
305 
DrawImageLatticeAsBitmap(const SkImage * image,const SkCanvas::Lattice & lattice,const SkRect & dst,const SkPaint * paint)306 void RSRecordingCanvas::DrawImageLatticeAsBitmap(
307     const SkImage* image, const SkCanvas::Lattice& lattice, const SkRect& dst, const SkPaint* paint)
308 {
309     SkBitmap bitmap;
310     auto imageInfo = SkImageInfo::Make(dst.width(), dst.height(), kRGBA_8888_SkColorType, kPremul_SkAlphaType);
311     bitmap.allocPixels(imageInfo);
312     SkCanvas tempCanvas(bitmap);
313     // align to [0, 0]
314     tempCanvas.translate(-dst.left(), -dst.top());
315 #ifdef NEW_SKIA
316     tempCanvas.drawImageLattice(image, lattice, dst, SkFilterMode::kNearest, paint);
317 #else
318     tempCanvas.drawImageLattice(image, lattice, dst, paint);
319 #endif
320     tempCanvas.flush();
321     // draw on canvas with correct offset
322 #ifdef NEW_SKIA
323     drawImage(bitmap.asImage(), dst.left(), dst.top());
324 #else
325     drawBitmap(bitmap, dst.left(), dst.top());
326 #endif
327 }
328 
Clear() const329 void RSRecordingCanvas::Clear() const
330 {
331     if (drawCmdList_ == nullptr) {
332         return;
333     }
334     drawCmdList_->ClearOp();
335 }
336 
AddOp(std::unique_ptr<OpItem> && opItem)337 void RSRecordingCanvas::AddOp(std::unique_ptr<OpItem>&& opItem)
338 {
339     if (drawCmdList_ == nullptr || opItem == nullptr) {
340         ROSEN_LOGE("RSRecordingCanvas:AddOp, drawCmdList_ or opItem is nullptr");
341         return;
342     }
343     drawCmdList_->AddOp(std::move(opItem));
344 }
345 
onNewSurface(const SkImageInfo & info,const SkSurfaceProps & props)346 sk_sp<SkSurface> RSRecordingCanvas::onNewSurface(const SkImageInfo& info, const SkSurfaceProps& props)
347 {
348     return nullptr;
349 }
350 
onFlush()351 void RSRecordingCanvas::onFlush()
352 {
353     RS_DRAWOP_TRACE_FUNC();
354     std::unique_ptr<OpItem> op = std::make_unique<FlushOpItem>();
355     AddOp(std::move(op));
356 }
357 
willSave()358 void RSRecordingCanvas::willSave()
359 {
360     RS_DRAWOP_TRACE_FUNC();
361     std::unique_ptr<OpItem> op = std::make_unique<SaveOpItem>();
362     AddOp(std::move(op));
363     saveCount_++;
364 }
365 
getSaveLayerStrategy(const SaveLayerRec & rec)366 SkCanvas::SaveLayerStrategy RSRecordingCanvas::getSaveLayerStrategy(const SaveLayerRec& rec)
367 {
368     RS_DRAWOP_TRACE_FUNC();
369     std::unique_ptr<OpItem> op = std::make_unique<SaveLayerOpItem>(rec);
370     AddOp(std::move(op));
371     saveCount_++;
372     return SkCanvas::kNoLayer_SaveLayerStrategy;
373 }
374 
willRestore()375 void RSRecordingCanvas::willRestore()
376 {
377     if (saveCount_ > 0) {
378         RS_DRAWOP_TRACE_FUNC();
379         std::unique_ptr<OpItem> op = std::make_unique<RestoreOpItem>();
380         AddOp(std::move(op));
381         --saveCount_;
382     }
383 }
384 
didTranslate(SkScalar dx,SkScalar dy)385 void RSRecordingCanvas::didTranslate(SkScalar dx, SkScalar dy)
386 {
387     RS_DRAWOP_TRACE_FUNC();
388     std::unique_ptr<OpItem> op = std::make_unique<TranslateOpItem>(dx, dy);
389     AddOp(std::move(op));
390 }
391 
onClipRect(const SkRect & rect,SkClipOp clipOp,ClipEdgeStyle style)392 void RSRecordingCanvas::onClipRect(const SkRect& rect, SkClipOp clipOp, ClipEdgeStyle style)
393 {
394     RS_DRAWOP_TRACE_FUNC();
395     std::unique_ptr<OpItem> op = std::make_unique<ClipRectOpItem>(rect, clipOp, style == kSoft_ClipEdgeStyle);
396     AddOp(std::move(op));
397 }
398 
onClipRRect(const SkRRect & rrect,SkClipOp clipOp,ClipEdgeStyle style)399 void RSRecordingCanvas::onClipRRect(const SkRRect& rrect, SkClipOp clipOp, ClipEdgeStyle style)
400 {
401     RS_DRAWOP_TRACE_FUNC();
402     std::unique_ptr<OpItem> op = std::make_unique<ClipRRectOpItem>(rrect, clipOp, style == kSoft_ClipEdgeStyle);
403     AddOp(std::move(op));
404 }
405 
onClipPath(const SkPath & path,SkClipOp clipOp,ClipEdgeStyle style)406 void RSRecordingCanvas::onClipPath(const SkPath& path, SkClipOp clipOp, ClipEdgeStyle style)
407 {
408     RS_DRAWOP_TRACE_FUNC();
409     std::unique_ptr<OpItem> op = std::make_unique<ClipPathOpItem>(path, clipOp, style == kSoft_ClipEdgeStyle);
410     AddOp(std::move(op));
411 }
412 
onClipRegion(const SkRegion & region,SkClipOp clipop)413 void RSRecordingCanvas::onClipRegion(const SkRegion& region, SkClipOp clipop)
414 {
415     RS_DRAWOP_TRACE_FUNC();
416     std::unique_ptr<OpItem> op = std::make_unique<ClipRegionOpItem>(region, clipop);
417     AddOp(std::move(op));
418 }
419 
onDrawPaint(const SkPaint & paint)420 void RSRecordingCanvas::onDrawPaint(const SkPaint& paint)
421 {
422     RS_DRAWOP_TRACE_FUNC();
423     std::unique_ptr<OpItem> op = std::make_unique<PaintOpItem>(paint);
424     AddOp(std::move(op));
425 }
426 
427 #ifdef ROSEN_OHOS
DrawSurfaceBuffer(const RSSurfaceBufferInfo & surfaceBufferInfo)428 void RSRecordingCanvas::DrawSurfaceBuffer(const RSSurfaceBufferInfo& surfaceBufferInfo)
429 {
430     RS_DRAWOP_TRACE_FUNC();
431     std::unique_ptr<OpItem> op = std::make_unique<SurfaceBufferOpItem>(surfaceBufferInfo);
432     AddOp(std::move(op));
433 }
434 #endif
435 
onDrawBehind(const SkPaint & paint)436 void RSRecordingCanvas::onDrawBehind(const SkPaint& paint)
437 {
438     // [PLANNING]: To be implemented
439     ROSEN_LOGE("RSRecordingCanvas::onDrawBehind not support yet");
440 }
441 
onDrawPath(const SkPath & path,const SkPaint & paint)442 void RSRecordingCanvas::onDrawPath(const SkPath& path, const SkPaint& paint)
443 {
444     RS_DRAWOP_TRACE_FUNC();
445     std::unique_ptr<OpItem> op = std::make_unique<PathOpItem>(path, paint);
446     AddOp(std::move(op));
447 }
448 
onDrawRect(const SkRect & rect,const SkPaint & paint)449 void RSRecordingCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint)
450 {
451     RS_DRAWOP_TRACE_FUNC();
452     std::unique_ptr<OpItem> op = std::make_unique<RectOpItem>(rect, paint);
453     AddOp(std::move(op));
454 }
455 
onDrawRegion(const SkRegion & region,const SkPaint & paint)456 void RSRecordingCanvas::onDrawRegion(const SkRegion& region, const SkPaint& paint)
457 {
458     RS_DRAWOP_TRACE_FUNC();
459     std::unique_ptr<OpItem> op = std::make_unique<RegionOpItem>(region, paint);
460     AddOp(std::move(op));
461 }
462 
onDrawOval(const SkRect & oval,const SkPaint & paint)463 void RSRecordingCanvas::onDrawOval(const SkRect& oval, const SkPaint& paint)
464 {
465     RS_DRAWOP_TRACE_FUNC();
466     std::unique_ptr<OpItem> op = std::make_unique<OvalOpItem>(oval, paint);
467     AddOp(std::move(op));
468 }
469 
onDrawArc(const SkRect & oval,SkScalar startAngle,SkScalar sweepAngle,bool useCenter,const SkPaint & paint)470 void RSRecordingCanvas::onDrawArc(
471     const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, bool useCenter, const SkPaint& paint)
472 {
473     RS_DRAWOP_TRACE_FUNC();
474     std::unique_ptr<OpItem> op = std::make_unique<ArcOpItem>(oval, startAngle, sweepAngle, useCenter, paint);
475     AddOp(std::move(op));
476 }
477 
onDrawRRect(const SkRRect & rrect,const SkPaint & paint)478 void RSRecordingCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint)
479 {
480     RS_DRAWOP_TRACE_FUNC();
481     std::unique_ptr<OpItem> op = std::make_unique<RoundRectOpItem>(rrect, paint);
482     AddOp(std::move(op));
483 }
484 
onDrawDRRect(const SkRRect & out,const SkRRect & in,const SkPaint & paint)485 void RSRecordingCanvas::onDrawDRRect(const SkRRect& out, const SkRRect& in, const SkPaint& paint)
486 {
487     RS_DRAWOP_TRACE_FUNC();
488     std::unique_ptr<OpItem> op = std::make_unique<DRRectOpItem>(out, in, paint);
489     AddOp(std::move(op));
490 }
491 
onDrawDrawable(SkDrawable * drawable,const SkMatrix * matrix)492 void RSRecordingCanvas::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix)
493 {
494     RS_DRAWOP_TRACE_FUNC();
495     std::unique_ptr<OpItem> op = std::make_unique<DrawableOpItem>(drawable, matrix);
496     AddOp(std::move(op));
497 }
498 
onDrawPicture(const SkPicture * picture,const SkMatrix * matrix,const SkPaint * paint)499 void RSRecordingCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix, const SkPaint* paint)
500 {
501     RS_DRAWOP_TRACE_FUNC();
502     std::unique_ptr<OpItem> op = std::make_unique<PictureOpItem>(sk_ref_sp(picture), matrix, paint);
503     AddOp(std::move(op));
504 }
505 
onDrawAnnotation(const SkRect & rect,const char key[],SkData * val)506 void RSRecordingCanvas::onDrawAnnotation(const SkRect& rect, const char key[], SkData* val)
507 {
508     // [PLANNING]: To be implemented
509     ROSEN_LOGE("RSRecordingCanvas::onDrawAnnotation not support yet");
510 }
511 
onDrawTextBlob(const SkTextBlob * blob,SkScalar x,SkScalar y,const SkPaint & paint)512 void RSRecordingCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint)
513 {
514     RS_DRAWOP_TRACE_FUNC();
515     std::unique_ptr<OpItem> op = std::make_unique<TextBlobOpItem>(sk_ref_sp(blob), x, y, paint);
516     if (IsCustomTextType()) {
517         // replace drawOpItem with cached one (generated by CPU)
518         ROSEN_LOGD("RSRecordingCanvas::onDrawTextBlob replace drawOpItem with cached one");
519         op = op->GenerateCachedOpItem();
520     }
521     AddOp(std::move(op));
522 }
523 
DrawAdaptiveRRect(float radius,const SkPaint & paint)524 void RSRecordingCanvas::DrawAdaptiveRRect(float radius, const SkPaint& paint)
525 {
526     RS_DRAWOP_TRACE_FUNC();
527     std::unique_ptr<OpItem> op = std::make_unique<AdaptiveRRectOpItem>(radius, paint);
528     AddOp(std::move(op));
529 }
530 
DrawAdaptiveRRectScale(float radiusRatio,const SkPaint & paint)531 void RSRecordingCanvas::DrawAdaptiveRRectScale(float radiusRatio, const SkPaint& paint)
532 {
533     RS_DRAWOP_TRACE_FUNC();
534     std::unique_ptr<OpItem> op = std::make_unique<AdaptiveRRectScaleOpItem>(radiusRatio, paint);
535     AddOp(std::move(op));
536 }
537 
ClipAdaptiveRRect(const SkVector radius[])538 void RSRecordingCanvas::ClipAdaptiveRRect(const SkVector radius[])
539 {
540     RS_DRAWOP_TRACE_FUNC();
541     std::unique_ptr<OpItem> op = std::make_unique<ClipAdaptiveRRectOpItem>(radius);
542     AddOp(std::move(op));
543 }
544 
ClipOutsetRect(float dx,float dy)545 void RSRecordingCanvas::ClipOutsetRect(float dx, float dy)
546 {
547     RS_DRAWOP_TRACE_FUNC();
548     std::unique_ptr<OpItem> op = std::make_unique<ClipOutsetRectOpItem>(dx, dy);
549     AddOp(std::move(op));
550 }
551 
onDrawPatch(const SkPoint cubics[12],const SkColor colors[4],const SkPoint texCoords[4],SkBlendMode bmode,const SkPaint & paint)552 void RSRecordingCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], const SkPoint texCoords[4],
553     SkBlendMode bmode, const SkPaint& paint)
554 {
555     // [PLANNING]: To be implemented
556     ROSEN_LOGE("RSRecordingCanvas::onDrawPatch not support yet");
557 }
558 
onDrawPoints(SkCanvas::PointMode mode,size_t count,const SkPoint pts[],const SkPaint & paint)559 void RSRecordingCanvas::onDrawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint)
560 {
561     RS_DRAWOP_TRACE_FUNC();
562     std::unique_ptr<OpItem> op = std::make_unique<PointsOpItem>(mode, count, pts, paint);
563     AddOp(std::move(op));
564 }
565 
onDrawShadowRec(const SkPath & path,const SkDrawShadowRec & rec)566 void RSRecordingCanvas::onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rec)
567 {
568     RS_DRAWOP_TRACE_FUNC();
569     std::unique_ptr<OpItem> op = std::make_unique<ShadowRecOpItem>(path, rec);
570     AddOp(std::move(op));
571 }
572 
MultiplyAlpha(float alpha)573 void RSRecordingCanvas::MultiplyAlpha(float alpha)
574 {
575     RS_DRAWOP_TRACE_FUNC();
576     std::unique_ptr<OpItem> op = std::make_unique<MultiplyAlphaOpItem>(alpha);
577     AddOp(std::move(op));
578 }
579 
SaveAlpha()580 void RSRecordingCanvas::SaveAlpha()
581 {
582     RS_DRAWOP_TRACE_FUNC();
583     std::unique_ptr<OpItem> op = std::make_unique<SaveAlphaOpItem>();
584     AddOp(std::move(op));
585 }
586 
RestoreAlpha()587 void RSRecordingCanvas::RestoreAlpha()
588 {
589     RS_DRAWOP_TRACE_FUNC();
590     std::unique_ptr<OpItem> op = std::make_unique<RestoreAlphaOpItem>();
591     AddOp(std::move(op));
592 }
593 
SetIsCustomTextType(bool isCustomTextType)594 void RSRecordingCanvas::SetIsCustomTextType(bool isCustomTextType)
595 {
596     isCustomTextType_ = isCustomTextType;
597 }
598 
IsCustomTextType() const599 bool RSRecordingCanvas::IsCustomTextType() const
600 {
601     return isCustomTextType_;
602 }
603 } // namespace Rosen
604 } // namespace OHOS
605 #endif // USE_ROSEN_DRAWING
606