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 #include "pipeline/rs_paint_filter_canvas.h"
17
18 #include <algorithm>
19
20 #include "common/rs_rect.h"
21 #include "draw/canvas.h"
22
23 #include "platform/common/rs_log.h"
24 #include "utils/rect.h"
25 #include "utils/region.h"
26
27 #ifdef _WIN32
28 #include <windows.h>
29 #define gettid GetCurrentThreadId
30 #endif
31 #ifdef __APPLE__
32 #define gettid getpid
33 #endif
34
35 #ifdef __gnu_linux__
36 #include <sys/types.h>
37 #include <sys/syscall.h>
38 #define gettid []()->int32_t { return static_cast<int32_t>(syscall(SYS_gettid)); }
39 #endif
40
41 namespace OHOS {
42 namespace Rosen {
43
44 using namespace Drawing;
45
RSPaintFilterCanvasBase(Drawing::Canvas * canvas)46 RSPaintFilterCanvasBase::RSPaintFilterCanvasBase(Drawing::Canvas* canvas)
47 : Canvas(canvas ? canvas->GetWidth() : 0, canvas ? canvas->GetHeight() : 0), canvas_(canvas)
48 {
49 #ifdef SKP_RECORDING_ENABLED
50 this->AddCanvas(canvas);
51 #endif
52 }
53
SetParallelRender(bool parallelEnable)54 void RSPaintFilterCanvasBase::SetParallelRender(bool parallelEnable)
55 {
56 canvas_->SetParallelRender(parallelEnable);
57 }
58
GetTotalMatrix() const59 Drawing::Matrix RSPaintFilterCanvasBase::GetTotalMatrix() const
60 {
61 return canvas_->GetTotalMatrix();
62 }
63
GetLocalClipBounds() const64 Drawing::Rect RSPaintFilterCanvasBase::GetLocalClipBounds() const
65 {
66 return canvas_->GetLocalClipBounds();
67 }
68
GetDeviceClipBounds() const69 Drawing::RectI RSPaintFilterCanvasBase::GetDeviceClipBounds() const
70 {
71 return canvas_->GetDeviceClipBounds();
72 }
73
GetRoundInDeviceClipBounds() const74 Drawing::RectI RSPaintFilterCanvasBase::GetRoundInDeviceClipBounds() const
75 {
76 return canvas_->GetRoundInDeviceClipBounds();
77 }
78
GetSaveCount() const79 CM_INLINE uint32_t RSPaintFilterCanvasBase::GetSaveCount() const
80 {
81 return canvas_->GetSaveCount();
82 }
83
84 #ifdef RS_ENABLE_GPU
GetGPUContext()85 std::shared_ptr<Drawing::GPUContext> RSPaintFilterCanvasBase::GetGPUContext()
86 {
87 return canvas_ != nullptr ? canvas_->GetGPUContext() : nullptr;
88 }
89 #endif
90
DrawPoint(const Point & point)91 void RSPaintFilterCanvasBase::DrawPoint(const Point& point)
92 {
93 #ifdef SKP_RECORDING_ENABLED
94 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
95 if ((*iter) != nullptr && OnFilter()) {
96 (*iter)->DrawPoint(point);
97 }
98 }
99 #else
100 if (canvas_ != nullptr && OnFilter()) {
101 canvas_->DrawPoint(point);
102 }
103 #endif
104 }
105
DrawSdf(const SDFShapeBase & shape)106 void RSPaintFilterCanvasBase::DrawSdf(const SDFShapeBase& shape)
107 {
108 #ifdef SKP_RECORDING_ENABLED
109 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
110 if ((*iter) != nullptr && OnFilter()) {
111 (*iter)->DrawSdf(shape);
112 }
113 }
114 #else
115 if (canvas_ != nullptr && OnFilter()) {
116 canvas_->DrawSdf(shape);
117 }
118 #endif
119 }
120
DrawPoints(PointMode mode,size_t count,const Point pts[])121 void RSPaintFilterCanvasBase::DrawPoints(PointMode mode, size_t count, const Point pts[])
122 {
123 #ifdef SKP_RECORDING_ENABLED
124 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
125 if ((*iter) != nullptr && OnFilter()) {
126 (*iter)->DrawPoints(mode, count, pts);
127 }
128 }
129 #else
130 if (canvas_ != nullptr && OnFilter()) {
131 canvas_->DrawPoints(mode, count, pts);
132 }
133 #endif
134 }
135
DrawLine(const Point & startPt,const Point & endPt)136 void RSPaintFilterCanvasBase::DrawLine(const Point& startPt, const Point& endPt)
137 {
138 #ifdef SKP_RECORDING_ENABLED
139 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
140 if ((*iter) != nullptr && OnFilter()) {
141 (*iter)->DrawLine(startPt, endPt);
142 }
143 }
144 #else
145 if (canvas_ != nullptr && OnFilter()) {
146 canvas_->DrawLine(startPt, endPt);
147 }
148 #endif
149 }
150
DrawRect(const Rect & rect)151 void RSPaintFilterCanvasBase::DrawRect(const Rect& rect)
152 {
153 #ifdef SKP_RECORDING_ENABLED
154 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
155 if ((*iter) != nullptr && OnFilter()) {
156 (*iter)->DrawRect(rect);
157 }
158 }
159 #else
160 if (canvas_ != nullptr && OnFilter()) {
161 canvas_->DrawRect(rect);
162 }
163 #endif
164 }
165
DrawRoundRect(const RoundRect & roundRect)166 void RSPaintFilterCanvasBase::DrawRoundRect(const RoundRect& roundRect)
167 {
168 #ifdef SKP_RECORDING_ENABLED
169 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
170 if ((*iter) != nullptr && OnFilter()) {
171 (*iter)->DrawRoundRect(roundRect);
172 }
173 }
174 #else
175 if (canvas_ != nullptr && OnFilter()) {
176 canvas_->DrawRoundRect(roundRect);
177 }
178 #endif
179 }
180
DrawNestedRoundRect(const RoundRect & outer,const RoundRect & inner)181 void RSPaintFilterCanvasBase::DrawNestedRoundRect(const RoundRect& outer, const RoundRect& inner)
182 {
183 #ifdef SKP_RECORDING_ENABLED
184 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
185 if ((*iter) != nullptr && OnFilter()) {
186 (*iter)->DrawNestedRoundRect(outer, inner);
187 }
188 }
189 #else
190 if (canvas_ != nullptr && OnFilter()) {
191 canvas_->DrawNestedRoundRect(outer, inner);
192 }
193 #endif
194 }
195
DrawArc(const Rect & oval,scalar startAngle,scalar sweepAngle)196 void RSPaintFilterCanvasBase::DrawArc(const Rect& oval, scalar startAngle, scalar sweepAngle)
197 {
198 #ifdef SKP_RECORDING_ENABLED
199 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
200 if ((*iter) != nullptr && OnFilter()) {
201 (*iter)->DrawArc(oval, startAngle, sweepAngle);
202 }
203 }
204 #else
205 if (canvas_ != nullptr && OnFilter()) {
206 canvas_->DrawArc(oval, startAngle, sweepAngle);
207 }
208 #endif
209 }
210
DrawPie(const Rect & oval,scalar startAngle,scalar sweepAngle)211 void RSPaintFilterCanvasBase::DrawPie(const Rect& oval, scalar startAngle, scalar sweepAngle)
212 {
213 #ifdef SKP_RECORDING_ENABLED
214 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
215 if ((*iter) != nullptr && OnFilter()) {
216 (*iter)->DrawPie(oval, startAngle, sweepAngle);
217 }
218 }
219 #else
220 if (canvas_ != nullptr && OnFilter()) {
221 canvas_->DrawPie(oval, startAngle, sweepAngle);
222 }
223 #endif
224 }
225
DrawOval(const Rect & oval)226 void RSPaintFilterCanvasBase::DrawOval(const Rect& oval)
227 {
228 #ifdef SKP_RECORDING_ENABLED
229 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
230 if ((*iter) != nullptr && OnFilter()) {
231 (*iter)->DrawOval(oval);
232 }
233 }
234 #else
235 if (canvas_ != nullptr && OnFilter()) {
236 canvas_->DrawOval(oval);
237 }
238 #endif
239 }
240
DrawCircle(const Point & centerPt,scalar radius)241 void RSPaintFilterCanvasBase::DrawCircle(const Point& centerPt, scalar radius)
242 {
243 #ifdef SKP_RECORDING_ENABLED
244 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
245 if ((*iter) != nullptr && OnFilter()) {
246 (*iter)->DrawCircle(centerPt, radius);
247 }
248 }
249 #else
250 if (canvas_ != nullptr && OnFilter()) {
251 canvas_->DrawCircle(centerPt, radius);
252 }
253 #endif
254 }
255
DrawPath(const Path & path)256 void RSPaintFilterCanvasBase::DrawPath(const Path& path)
257 {
258 #ifdef SKP_RECORDING_ENABLED
259 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
260 if ((*iter) != nullptr && OnFilter()) {
261 (*iter)->DrawPath(path);
262 }
263 }
264 #else
265 if (canvas_ != nullptr && OnFilter()) {
266 canvas_->DrawPath(path);
267 }
268 #endif
269 }
270
DrawPathWithStencil(const Drawing::Path & path,uint32_t stencilVal)271 void RSPaintFilterCanvasBase::DrawPathWithStencil(const Drawing::Path& path, uint32_t stencilVal)
272 {
273 #ifdef SKP_RECORDING_ENABLED
274 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
275 if ((*iter) != nullptr && OnFilter()) {
276 (*iter)->DrawPathWithStencil(path, stencilVal);
277 }
278 }
279 #else
280 if (canvas_ != nullptr && OnFilter()) {
281 canvas_->DrawPathWithStencil(path, stencilVal);
282 }
283 #endif
284 }
285
DrawBackground(const Brush & brush)286 void RSPaintFilterCanvasBase::DrawBackground(const Brush& brush)
287 {
288 Brush b(brush);
289 #ifdef SKP_RECORDING_ENABLED
290 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
291 if ((*iter) != nullptr && OnFilterWithBrush(b)) {
292 (*iter)->DrawBackground(b);
293 }
294 }
295 #else
296 if (canvas_ != nullptr && OnFilterWithBrush(b)) {
297 canvas_->DrawBackground(b);
298 }
299 #endif
300 }
301
DrawShadow(const Path & path,const Point3 & planeParams,const Point3 & devLightPos,scalar lightRadius,Color ambientColor,Color spotColor,ShadowFlags flag)302 void RSPaintFilterCanvasBase::DrawShadow(const Path& path, const Point3& planeParams, const Point3& devLightPos,
303 scalar lightRadius, Color ambientColor, Color spotColor, ShadowFlags flag)
304 {
305 #ifdef SKP_RECORDING_ENABLED
306 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
307 if ((*iter) != nullptr && OnFilter()) {
308 (*iter)->DrawShadow(path, planeParams, devLightPos, lightRadius, ambientColor, spotColor, flag);
309 }
310 }
311 #else
312 if (canvas_ != nullptr && OnFilter()) {
313 canvas_->DrawShadow(path, planeParams, devLightPos, lightRadius, ambientColor, spotColor, flag);
314 }
315 #endif
316 }
317
DrawShadowStyle(const Path & path,const Point3 & planeParams,const Point3 & devLightPos,scalar lightRadius,Color ambientColor,Color spotColor,ShadowFlags flag,bool isLimitElevation)318 void RSPaintFilterCanvasBase::DrawShadowStyle(const Path& path, const Point3& planeParams, const Point3& devLightPos,
319 scalar lightRadius, Color ambientColor, Color spotColor, ShadowFlags flag, bool isLimitElevation)
320 {
321 #ifdef SKP_RECORDING_ENABLED
322 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
323 if ((*iter) != nullptr && OnFilter()) {
324 (*iter)->DrawShadowStyle(
325 path, planeParams, devLightPos, lightRadius, ambientColor, spotColor, flag, isLimitElevation);
326 }
327 }
328 #else
329 if (canvas_ != nullptr && OnFilter()) {
330 canvas_->DrawShadowStyle(
331 path, planeParams, devLightPos, lightRadius, ambientColor, spotColor, flag, isLimitElevation);
332 }
333 #endif
334 }
335
DrawColor(Drawing::ColorQuad color,Drawing::BlendMode mode)336 void RSPaintFilterCanvasBase::DrawColor(Drawing::ColorQuad color, Drawing::BlendMode mode)
337 {
338 #ifdef SKP_RECORDING_ENABLED
339 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
340 if ((*iter) != nullptr && OnFilter()) {
341 (*iter)->DrawColor(color, mode);
342 }
343 }
344 #else
345 if (canvas_ != nullptr && OnFilter()) {
346 canvas_->DrawColor(color, mode);
347 }
348 #endif
349 }
350
DrawRegion(const Drawing::Region & region)351 void RSPaintFilterCanvasBase::DrawRegion(const Drawing::Region& region)
352 {
353 #ifdef SKP_RECORDING_ENABLED
354 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
355 if ((*iter) != nullptr && OnFilter()) {
356 (*iter)->DrawRegion(region);
357 }
358 }
359 #else
360 if (canvas_ != nullptr && OnFilter()) {
361 canvas_->DrawRegion(region);
362 }
363 #endif
364 }
365
DrawPatch(const Drawing::Point cubics[12],const Drawing::ColorQuad colors[4],const Drawing::Point texCoords[4],Drawing::BlendMode mode)366 void RSPaintFilterCanvasBase::DrawPatch(const Drawing::Point cubics[12], const Drawing::ColorQuad colors[4],
367 const Drawing::Point texCoords[4], Drawing::BlendMode mode)
368 {
369 #ifdef SKP_RECORDING_ENABLED
370 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
371 if ((*iter) != nullptr && OnFilter()) {
372 (*iter)->DrawPatch(cubics, colors, texCoords, mode);
373 }
374 }
375 #else
376 if (canvas_ != nullptr && OnFilter()) {
377 canvas_->DrawPatch(cubics, colors, texCoords, mode);
378 }
379 #endif
380 }
381
DrawVertices(const Drawing::Vertices & vertices,Drawing::BlendMode mode)382 void RSPaintFilterCanvasBase::DrawVertices(const Drawing::Vertices& vertices, Drawing::BlendMode mode)
383 {
384 #ifdef SKP_RECORDING_ENABLED
385 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
386 if ((*iter) != nullptr && OnFilter()) {
387 (*iter)->DrawVertices(vertices, mode);
388 }
389 }
390 #else
391 if (canvas_ != nullptr && OnFilter()) {
392 canvas_->DrawVertices(vertices, mode);
393 }
394 #endif
395 }
396
OpCalculateBefore(const Matrix & matrix)397 bool RSPaintFilterCanvasBase::OpCalculateBefore(const Matrix& matrix)
398 {
399 if (canvas_ != nullptr && OnFilter()) {
400 return canvas_->OpCalculateBefore(matrix);
401 }
402 return false;
403 }
404
OpCalculateAfter(const Drawing::Rect & bound)405 std::shared_ptr<Drawing::OpListHandle> RSPaintFilterCanvasBase::OpCalculateAfter(const Drawing::Rect& bound)
406 {
407 if (canvas_ != nullptr && OnFilter()) {
408 return canvas_->OpCalculateAfter(bound);
409 }
410 return nullptr;
411 }
412
DrawAtlas(const Drawing::Image * atlas,const Drawing::RSXform xform[],const Drawing::Rect tex[],const Drawing::ColorQuad colors[],int count,Drawing::BlendMode mode,const Drawing::SamplingOptions & sampling,const Drawing::Rect * cullRect)413 void RSPaintFilterCanvasBase::DrawAtlas(const Drawing::Image* atlas, const Drawing::RSXform xform[],
414 const Drawing::Rect tex[], const Drawing::ColorQuad colors[], int count, Drawing::BlendMode mode,
415 const Drawing::SamplingOptions& sampling, const Drawing::Rect* cullRect)
416 {
417 #ifdef SKP_RECORDING_ENABLED
418 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
419 if ((*iter) != nullptr && OnFilter()) {
420 (*iter)->DrawAtlas(atlas, xform, tex, colors, count, mode, sampling, cullRect);
421 }
422 }
423 #else
424 if (canvas_ != nullptr && OnFilter()) {
425 canvas_->DrawAtlas(atlas, xform, tex, colors, count, mode, sampling, cullRect);
426 }
427 #endif
428 }
429
DrawBitmap(const Bitmap & bitmap,const scalar px,const scalar py)430 void RSPaintFilterCanvasBase::DrawBitmap(const Bitmap& bitmap, const scalar px, const scalar py)
431 {
432 #ifdef SKP_RECORDING_ENABLED
433 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
434 if ((*iter) != nullptr && OnFilter()) {
435 (*iter)->DrawBitmap(bitmap, px, py);
436 }
437 }
438 #else
439 if (canvas_ != nullptr && OnFilter()) {
440 canvas_->DrawBitmap(bitmap, px, py);
441 }
442 #endif
443 }
444
DrawImageNine(const Drawing::Image * image,const Drawing::RectI & center,const Drawing::Rect & dst,Drawing::FilterMode filter,const Drawing::Brush * brush)445 void RSPaintFilterCanvasBase::DrawImageNine(const Drawing::Image* image, const Drawing::RectI& center,
446 const Drawing::Rect& dst, Drawing::FilterMode filter, const Drawing::Brush* brush)
447 {
448 #ifdef SKP_RECORDING_ENABLED
449 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
450 if ((*iter) != nullptr && OnFilter()) {
451 if (brush) {
452 Drawing::Brush b(*brush);
453 OnFilterWithBrush(b);
454 (*iter)->DrawImageNine(image, center, dst, filter, &b);
455 } else {
456 (*iter)->DrawImageNine(image, center, dst, filter, GetFilteredBrush());
457 }
458 }
459 }
460 #else
461 if (canvas_ != nullptr && OnFilter()) {
462 if (brush) {
463 Drawing::Brush b(*brush);
464 OnFilterWithBrush(b);
465 canvas_->DrawImageNine(image, center, dst, filter, &b);
466 } else {
467 canvas_->DrawImageNine(image, center, dst, filter, GetFilteredBrush());
468 }
469 }
470 #endif
471 }
472
DrawImageLattice(const Drawing::Image * image,const Drawing::Lattice & lattice,const Drawing::Rect & dst,Drawing::FilterMode filter)473 void RSPaintFilterCanvasBase::DrawImageLattice(const Drawing::Image* image, const Drawing::Lattice& lattice,
474 const Drawing::Rect& dst, Drawing::FilterMode filter)
475 {
476 #ifdef SKP_RECORDING_ENABLED
477 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
478 if ((*iter) != nullptr && OnFilter()) {
479 (*iter)->DrawImageLattice(image, lattice, dst, filter);
480 }
481 }
482 #else
483 if (canvas_ != nullptr && OnFilter()) {
484 canvas_->DrawImageLattice(image, lattice, dst, filter);
485 }
486 #endif
487 }
488
DrawImage(const Image & image,const scalar px,const scalar py,const SamplingOptions & sampling)489 void RSPaintFilterCanvasBase::DrawImage(
490 const Image& image, const scalar px, const scalar py, const SamplingOptions& sampling)
491 {
492 #ifdef SKP_RECORDING_ENABLED
493 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
494 if ((*iter) != nullptr && OnFilter()) {
495 (*iter)->DrawImage(image, px, py, sampling);
496 }
497 }
498 #else
499 if (canvas_ != nullptr && OnFilter()) {
500 canvas_->DrawImage(image, px, py, sampling);
501 }
502 #endif
503 }
504
DrawImageWithStencil(const Drawing::Image & image,const Drawing::scalar px,const Drawing::scalar py,const Drawing::SamplingOptions & sampling,uint32_t stencilVal)505 void RSPaintFilterCanvasBase::DrawImageWithStencil(const Drawing::Image& image, const Drawing::scalar px,
506 const Drawing::scalar py, const Drawing::SamplingOptions& sampling, uint32_t stencilVal)
507 {
508 #ifdef SKP_RECORDING_ENABLED
509 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
510 if ((*iter) != nullptr && OnFilter()) {
511 (*iter)->DrawImageWithStencil(image, px, py, sampling, stencilVal);
512 }
513 }
514 #else
515 if (canvas_ != nullptr && OnFilter()) {
516 canvas_->DrawImageWithStencil(image, px, py, sampling, stencilVal);
517 }
518 #endif
519 }
520
DrawImageRect(const Image & image,const Rect & src,const Rect & dst,const SamplingOptions & sampling,SrcRectConstraint constraint)521 void RSPaintFilterCanvasBase::DrawImageRect(const Image& image, const Rect& src, const Rect& dst,
522 const SamplingOptions& sampling, SrcRectConstraint constraint)
523 {
524 #ifdef SKP_RECORDING_ENABLED
525 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
526 if ((*iter) != nullptr && OnFilter()) {
527 (*iter)->DrawImageRect(image, src, dst, sampling, constraint);
528 }
529 }
530 #else
531 if (canvas_ != nullptr && OnFilter()) {
532 canvas_->DrawImageRect(image, src, dst, sampling, constraint);
533 }
534 #endif
535 }
536
DrawImageRect(const Image & image,const Rect & dst,const SamplingOptions & sampling)537 void RSPaintFilterCanvasBase::DrawImageRect(const Image& image, const Rect& dst, const SamplingOptions& sampling)
538 {
539 #ifdef SKP_RECORDING_ENABLED
540 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
541 if ((*iter) != nullptr && OnFilter()) {
542 (*iter)->DrawImageRect(image, dst, sampling);
543 }
544 }
545 #else
546 if (canvas_ != nullptr && OnFilter()) {
547 canvas_->DrawImageRect(image, dst, sampling);
548 }
549 #endif
550 }
551
DrawPicture(const Picture & picture)552 void RSPaintFilterCanvasBase::DrawPicture(const Picture& picture)
553 {
554 #ifdef SKP_RECORDING_ENABLED
555 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
556 if ((*iter) != nullptr && OnFilter()) {
557 (*iter)->DrawPicture(picture);
558 }
559 }
560 #else
561 if (canvas_ != nullptr && OnFilter()) {
562 canvas_->DrawPicture(picture);
563 }
564 #endif
565 }
566
DrawTextBlob(const Drawing::TextBlob * blob,const Drawing::scalar x,const Drawing::scalar y)567 void RSPaintFilterCanvasBase::DrawTextBlob(
568 const Drawing::TextBlob* blob, const Drawing::scalar x, const Drawing::scalar y)
569 {
570 #ifdef SKP_RECORDING_ENABLED
571 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
572 if ((*iter) != nullptr && OnFilter()) {
573 (*iter)->DrawTextBlob(blob, x, y);
574 }
575 }
576 #else
577 if (canvas_ != nullptr && OnFilter()) {
578 canvas_->DrawTextBlob(blob, x, y);
579 }
580 #endif
581 }
582
ClearStencil(const Drawing::RectI & rect,uint32_t stencilVal)583 void RSPaintFilterCanvasBase::ClearStencil(const Drawing::RectI& rect, uint32_t stencilVal)
584 {
585 #ifdef SKP_RECORDING_ENABLED
586 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
587 if ((*iter) != nullptr) {
588 (*iter)->ClearStencil(rect, stencilVal);
589 }
590 }
591 #else
592 if (canvas_ != nullptr) {
593 canvas_->ClearStencil(rect, stencilVal);
594 }
595 #endif
596 }
597
ClipRect(const Drawing::Rect & rect,Drawing::ClipOp op,bool doAntiAlias)598 void RSPaintFilterCanvasBase::ClipRect(const Drawing::Rect& rect, Drawing::ClipOp op, bool doAntiAlias)
599 {
600 #ifdef SKP_RECORDING_ENABLED
601 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
602 if ((*iter) != nullptr) {
603 (*iter)->ClipRect(rect, op, doAntiAlias);
604 }
605 }
606 #else
607 if (canvas_ != nullptr) {
608 canvas_->ClipRect(rect, op, doAntiAlias);
609 }
610 #endif
611 }
612
ClipIRect(const Drawing::RectI & rect,Drawing::ClipOp op)613 void RSPaintFilterCanvasBase::ClipIRect(const Drawing::RectI& rect, Drawing::ClipOp op)
614 {
615 #ifdef SKP_RECORDING_ENABLED
616 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
617 if ((*iter) != nullptr) {
618 (*iter)->ClipIRect(rect, op);
619 }
620 }
621 #else
622 if (canvas_ != nullptr) {
623 canvas_->ClipIRect(rect, op);
624 }
625 #endif
626 }
627
ClipRoundRect(const RoundRect & roundRect,ClipOp op,bool doAntiAlias)628 void RSPaintFilterCanvasBase::ClipRoundRect(const RoundRect& roundRect, ClipOp op, bool doAntiAlias)
629 {
630 #ifdef SKP_RECORDING_ENABLED
631 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
632 if ((*iter) != nullptr) {
633 (*iter)->ClipRoundRect(roundRect, op, doAntiAlias);
634 }
635 }
636 #else
637 if (canvas_ != nullptr) {
638 canvas_->ClipRoundRect(roundRect, op, doAntiAlias);
639 }
640 #endif
641 }
642
ClipRoundRect(const Drawing::Rect & rect,std::vector<Drawing::Point> & pts,bool doAntiAlias)643 void RSPaintFilterCanvasBase::ClipRoundRect(const Drawing::Rect& rect,
644 std::vector<Drawing::Point>& pts, bool doAntiAlias)
645 {
646 #ifdef SKP_RECORDING_ENABLED
647 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
648 if ((*iter) != nullptr) {
649 (*iter)->ClipRoundRect(rect, pts, doAntiAlias);
650 }
651 }
652 #else
653 if (canvas_ != nullptr) {
654 canvas_->ClipRoundRect(rect, pts, doAntiAlias);
655 }
656 #endif
657 }
658
ClipPath(const Path & path,ClipOp op,bool doAntiAlias)659 void RSPaintFilterCanvasBase::ClipPath(const Path& path, ClipOp op, bool doAntiAlias)
660 {
661 #ifdef SKP_RECORDING_ENABLED
662 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
663 if ((*iter) != nullptr) {
664 (*iter)->ClipPath(path, op, doAntiAlias);
665 }
666 }
667 #else
668 if (canvas_ != nullptr) {
669 canvas_->ClipPath(path, op, doAntiAlias);
670 }
671 #endif
672 }
673
ClipRegion(const Region & region,ClipOp op)674 void RSPaintFilterCanvasBase::ClipRegion(const Region& region, ClipOp op)
675 {
676 #ifdef SKP_RECORDING_ENABLED
677 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
678 if ((*iter) != nullptr) {
679 (*iter)->ClipRegion(region, op);
680 }
681 }
682 #else
683 if (canvas_ != nullptr) {
684 canvas_->ClipRegion(region, op);
685 }
686 #endif
687 }
688
ResetClip()689 void RSPaintFilterCanvasBase::ResetClip()
690 {
691 #ifdef SKP_RECORDING_ENABLED
692 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
693 if ((*iter) != nullptr) {
694 (*iter)->ResetClip();
695 }
696 }
697 #else
698 if (canvas_ != nullptr) {
699 canvas_->ResetClip();
700 }
701 #endif
702 }
703
SetMatrix(const Matrix & matrix)704 void RSPaintFilterCanvasBase::SetMatrix(const Matrix& matrix)
705 {
706 #ifdef SKP_RECORDING_ENABLED
707 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
708 if ((*iter) != nullptr) {
709 (*iter)->SetMatrix(matrix);
710 }
711 }
712 #else
713 if (canvas_ != nullptr) {
714 canvas_->SetMatrix(matrix);
715 }
716 #endif
717 }
718
ResetMatrix()719 void RSPaintFilterCanvasBase::ResetMatrix()
720 {
721 #ifdef SKP_RECORDING_ENABLED
722 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
723 if ((*iter) != nullptr) {
724 (*iter)->ResetMatrix();
725 }
726 }
727 #else
728 if (canvas_ != nullptr) {
729 canvas_->ResetMatrix();
730 }
731 #endif
732 }
733
ConcatMatrix(const Matrix & matrix)734 void RSPaintFilterCanvasBase::ConcatMatrix(const Matrix& matrix)
735 {
736 #ifdef SKP_RECORDING_ENABLED
737 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
738 if ((*iter) != nullptr) {
739 (*iter)->ConcatMatrix(matrix);
740 }
741 }
742 #else
743 if (canvas_ != nullptr) {
744 canvas_->ConcatMatrix(matrix);
745 }
746 #endif
747 }
748
Translate(scalar dx,scalar dy)749 void RSPaintFilterCanvasBase::Translate(scalar dx, scalar dy)
750 {
751 #ifdef SKP_RECORDING_ENABLED
752 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
753 if ((*iter) != nullptr) {
754 (*iter)->Translate(dx, dy);
755 }
756 }
757 #else
758 if (canvas_ != nullptr) {
759 canvas_->Translate(dx, dy);
760 }
761 #endif
762 }
763
Scale(scalar sx,scalar sy)764 void RSPaintFilterCanvasBase::Scale(scalar sx, scalar sy)
765 {
766 #ifdef SKP_RECORDING_ENABLED
767 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
768 if ((*iter) != nullptr) {
769 (*iter)->Scale(sx, sy);
770 }
771 }
772 #else
773 if (canvas_ != nullptr) {
774 canvas_->Scale(sx, sy);
775 }
776 #endif
777 }
778
Rotate(scalar deg,scalar sx,scalar sy)779 void RSPaintFilterCanvasBase::Rotate(scalar deg, scalar sx, scalar sy)
780 {
781 #ifdef SKP_RECORDING_ENABLED
782 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
783 if ((*iter) != nullptr) {
784 (*iter)->Rotate(deg, sx, sy);
785 }
786 }
787 #else
788 if (canvas_ != nullptr) {
789 canvas_->Rotate(deg, sx, sy);
790 }
791 #endif
792 }
793
Shear(scalar sx,scalar sy)794 void RSPaintFilterCanvasBase::Shear(scalar sx, scalar sy)
795 {
796 #ifdef SKP_RECORDING_ENABLED
797 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
798 if ((*iter) != nullptr) {
799 (*iter)->Shear(sx, sy);
800 }
801 }
802 #else
803 if (canvas_ != nullptr) {
804 canvas_->Shear(sx, sy);
805 }
806 #endif
807 }
808
Flush()809 void RSPaintFilterCanvasBase::Flush()
810 {
811 #ifdef SKP_RECORDING_ENABLED
812 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
813 if ((*iter) != nullptr) {
814 (*iter)->Flush();
815 }
816 }
817 #else
818 if (canvas_ != nullptr) {
819 canvas_->Flush();
820 }
821 #endif
822 }
823
Clear(ColorQuad color)824 void RSPaintFilterCanvasBase::Clear(ColorQuad color)
825 {
826 #ifdef SKP_RECORDING_ENABLED
827 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
828 if ((*iter) != nullptr) {
829 (*iter)->Clear(color);
830 }
831 }
832 #else
833 if (canvas_ != nullptr) {
834 canvas_->Clear(color);
835 }
836 #endif
837 }
838
Save()839 uint32_t RSPaintFilterCanvasBase::Save()
840 {
841 #ifdef SKP_RECORDING_ENABLED
842 uint32_t count = 0U;
843 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
844 if ((*iter) != nullptr) {
845 auto c = (*iter)->Save();
846 if ((*iter) == canvas_) {
847 count = c;
848 }
849 }
850 }
851 return count;
852 #else
853 if (canvas_ != nullptr) {
854 return canvas_->Save();
855 }
856 return 0;
857 #endif
858 }
859
SaveLayer(const SaveLayerOps & saveLayerRec)860 void RSPaintFilterCanvasBase::SaveLayer(const SaveLayerOps& saveLayerRec)
861 {
862 if (canvas_ == nullptr) {
863 return;
864 }
865 Brush brush;
866 if (saveLayerRec.GetBrush() != nullptr) {
867 brush = *saveLayerRec.GetBrush();
868 OnFilterWithBrush(brush);
869 }
870 SaveLayerOps slo(saveLayerRec.GetBounds(), &brush, saveLayerRec.GetSaveLayerFlags());
871 #ifdef SKP_RECORDING_ENABLED
872 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
873 if ((*iter) != nullptr) {
874 (*iter)->SaveLayer(slo);
875 }
876 }
877 #else
878 canvas_->SaveLayer(slo);
879 #endif
880 }
881
Restore()882 void RSPaintFilterCanvasBase::Restore()
883 {
884 #ifdef SKP_RECORDING_ENABLED
885 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
886 if ((*iter) != nullptr) {
887 (*iter)->Restore();
888 }
889 }
890 #else
891 if (canvas_ != nullptr) {
892 canvas_->Restore();
893 }
894 #endif
895 }
896
Discard()897 void RSPaintFilterCanvasBase::Discard()
898 {
899 #ifdef SKP_RECORDING_ENABLED
900 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
901 if ((*iter) != nullptr) {
902 (*iter)->Discard();
903 }
904 }
905 #else
906 if (canvas_ != nullptr) {
907 canvas_->Discard();
908 }
909 #endif
910 }
911
AttachPen(const Pen & pen)912 CoreCanvas& RSPaintFilterCanvasBase::AttachPen(const Pen& pen)
913 {
914 #ifdef SKP_RECORDING_ENABLED
915 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
916 if ((*iter) != nullptr) {
917 (*iter)->AttachPen(pen);
918 }
919 }
920 #else
921 if (canvas_ != nullptr) {
922 canvas_->AttachPen(pen);
923 }
924 #endif
925 return *this;
926 }
927
AttachBrush(const Brush & brush)928 CoreCanvas& RSPaintFilterCanvasBase::AttachBrush(const Brush& brush)
929 {
930 #ifdef SKP_RECORDING_ENABLED
931 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
932 if ((*iter) != nullptr) {
933 (*iter)->AttachBrush(brush);
934 }
935 }
936 #else
937 if (canvas_ != nullptr) {
938 canvas_->AttachBrush(brush);
939 }
940 #endif
941 return *this;
942 }
943
AttachPaint(const Drawing::Paint & paint)944 CoreCanvas& RSPaintFilterCanvasBase::AttachPaint(const Drawing::Paint& paint)
945 {
946 #ifdef SKP_RECORDING_ENABLED
947 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
948 if ((*iter) != nullptr) {
949 (*iter)->AttachPaint(paint);
950 }
951 }
952 #else
953 if (canvas_ != nullptr) {
954 canvas_->AttachPaint(paint);
955 }
956 #endif
957 return *this;
958 }
959
DetachPen()960 CoreCanvas& RSPaintFilterCanvasBase::DetachPen()
961 {
962 #ifdef SKP_RECORDING_ENABLED
963 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
964 if ((*iter) != nullptr) {
965 (*iter)->DetachPen();
966 }
967 }
968 #else
969 if (canvas_ != nullptr) {
970 canvas_->DetachPen();
971 }
972 #endif
973 return *this;
974 }
975
DetachBrush()976 CoreCanvas& RSPaintFilterCanvasBase::DetachBrush()
977 {
978 #ifdef SKP_RECORDING_ENABLED
979 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
980 if ((*iter) != nullptr) {
981 (*iter)->DetachBrush();
982 }
983 }
984 #else
985 if (canvas_ != nullptr) {
986 canvas_->DetachBrush();
987 }
988 #endif
989 return *this;
990 }
991
DetachPaint()992 CoreCanvas& RSPaintFilterCanvasBase::DetachPaint()
993 {
994 #ifdef SKP_RECORDING_ENABLED
995 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
996 if ((*iter) != nullptr) {
997 (*iter)->DetachPaint();
998 }
999 }
1000 #else
1001 if (canvas_ != nullptr) {
1002 canvas_->DetachPaint();
1003 }
1004 #endif
1005 return *this;
1006 }
1007
DrawImageEffectHPS(const Drawing::Image & image,const std::vector<std::shared_ptr<Drawing::HpsEffectParameter>> & hpsEffectParams)1008 bool RSPaintFilterCanvasBase::DrawImageEffectHPS(const Drawing::Image& image,
1009 const std::vector<std::shared_ptr<Drawing::HpsEffectParameter>>& hpsEffectParams)
1010 {
1011 bool result = false;
1012 #ifdef SKP_RECORDING_ENABLED
1013 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
1014 if ((*iter) != nullptr) {
1015 result = ((*iter)->DrawImageEffectHPS(image, hpsEffectParams) || result);
1016 }
1017 }
1018 #else
1019 if (canvas_ != nullptr) {
1020 result = canvas_->DrawImageEffectHPS(image, hpsEffectParams);
1021 }
1022 #endif
1023 return result;
1024 }
1025
DrawBlurImage(const Drawing::Image & image,const Drawing::HpsBlurParameter & blurParams)1026 bool RSPaintFilterCanvasBase::DrawBlurImage(const Drawing::Image& image, const Drawing::HpsBlurParameter& blurParams)
1027 {
1028 bool result = false;
1029 #ifdef SKP_RECORDING_ENABLED
1030 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
1031 if ((*iter) != nullptr && OnFilter()) {
1032 result = ((*iter)->DrawBlurImage(image, blurParams) || result);
1033 }
1034 }
1035 #else
1036 if (canvas_ != nullptr && OnFilter()) {
1037 result = canvas_->DrawBlurImage(image, blurParams);
1038 }
1039 #endif
1040 return result;
1041 }
1042
CalcHpsBluredImageDimension(const Drawing::HpsBlurParameter & blurParams)1043 std::array<int, 2> RSPaintFilterCanvasBase::CalcHpsBluredImageDimension(const Drawing::HpsBlurParameter& blurParams)
1044 {
1045 std::array<int, 2> result = {0, 0}; // There are 2 variables
1046 #ifdef SKP_RECORDING_ENABLED
1047 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
1048 if ((*iter) != nullptr) {
1049 result = (*iter)->CalcHpsBluredImageDimension(blurParams);
1050 }
1051 }
1052 #else
1053 if (canvas_ != nullptr) {
1054 result = canvas_->CalcHpsBluredImageDimension(blurParams);
1055 }
1056 #endif
1057 return result;
1058 }
1059
IsClipRect()1060 bool RSPaintFilterCanvasBase::IsClipRect()
1061 {
1062 bool result = false;
1063 #ifdef SKP_RECORDING_ENABLED
1064 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
1065 if ((*iter) != nullptr) {
1066 result = result || (*iter)->IsClipRect();
1067 }
1068 }
1069 #else
1070 if (canvas_ != nullptr) {
1071 result = canvas_->IsClipRect();
1072 }
1073 #endif
1074 return result;
1075 }
1076
RSPaintFilterCanvas(Drawing::Canvas * canvas,float alpha)1077 RSPaintFilterCanvas::RSPaintFilterCanvas(Drawing::Canvas* canvas, float alpha)
1078 : RSPaintFilterCanvasBase(canvas), alphaStack_({ 1.0f }),
1079 envStack_({ Env { .envForegroundColor_ = RSColor(0xFF000000), .hasOffscreenLayer_ = false } }),
1080 threadId_(gettid())
1081 {
1082 (void)alpha; // alpha is no longer used, but we keep it for backward compatibility
1083 }
1084
RSPaintFilterCanvas(Drawing::Surface * surface,float alpha)1085 RSPaintFilterCanvas::RSPaintFilterCanvas(Drawing::Surface* surface, float alpha)
1086 : RSPaintFilterCanvasBase(surface ? surface->GetCanvas().get() : nullptr), surface_(surface), alphaStack_({ 1.0f }),
1087 envStack_({ Env { .envForegroundColor_ = RSColor(0xFF000000), .hasOffscreenLayer_ = false } }),
1088 threadId_(gettid())
1089 {
1090 (void)alpha; // alpha is no longer used, but we keep it for backward compatibility
1091 }
1092
GetSurface() const1093 Drawing::Surface* RSPaintFilterCanvas::GetSurface() const
1094 {
1095 return surface_;
1096 }
1097
AttachPen(const Pen & pen)1098 CoreCanvas& RSPaintFilterCanvas::AttachPen(const Pen& pen)
1099 {
1100 if (canvas_ == nullptr) {
1101 return *this;
1102 }
1103
1104 Pen p(pen);
1105 if (p.GetColor() == 0x00000001) { // foreground color and foreground color strategy identification
1106 p.SetColor(envStack_.top().envForegroundColor_.AsArgbInt());
1107 }
1108
1109 // use alphaStack_.top() to multiply alpha
1110 if (alphaStack_.top() < 1 && alphaStack_.top() > 0) {
1111 p.SetAlpha(p.GetAlpha() * alphaStack_.top());
1112 }
1113
1114 // use envStack_.top().blender_ to set blender
1115 if (auto& blender = envStack_.top().blender_) {
1116 if (p.GetBlenderEnabled()) {
1117 p.SetBlender(blender);
1118 }
1119 }
1120
1121 #ifdef SKP_RECORDING_ENABLED
1122 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
1123 if ((*iter) != nullptr) {
1124 (*iter)->AttachPen(p);
1125 }
1126 }
1127 #else
1128 canvas_->AttachPen(p);
1129 #endif
1130 return *this;
1131 }
1132
AttachBrush(const Brush & brush)1133 CoreCanvas& RSPaintFilterCanvas::AttachBrush(const Brush& brush)
1134 {
1135 if (canvas_ == nullptr) {
1136 return *this;
1137 }
1138
1139 Brush b(brush);
1140 if (b.GetColor() == 0x00000001) { // foreground color and foreground color strategy identification
1141 b.SetColor(envStack_.top().envForegroundColor_.AsArgbInt());
1142 }
1143
1144 // use alphaStack_.top() to multiply alpha
1145 if (alphaStack_.top() < 1 && alphaStack_.top() > 0) {
1146 b.SetAlpha(b.GetAlpha() * alphaStack_.top());
1147 }
1148
1149 // use envStack_.top().blender_ to set blender
1150 if (auto& blender = envStack_.top().blender_) {
1151 if (b.GetBlenderEnabled()) {
1152 b.SetBlender(blender);
1153 }
1154 }
1155
1156 #ifdef SKP_RECORDING_ENABLED
1157 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
1158 if ((*iter) != nullptr) {
1159 (*iter)->AttachBrush(b);
1160 }
1161 }
1162 #else
1163 canvas_->AttachBrush(b);
1164 #endif
1165 return *this;
1166 }
1167
AttachPaint(const Drawing::Paint & paint)1168 CoreCanvas& RSPaintFilterCanvas::AttachPaint(const Drawing::Paint& paint)
1169 {
1170 if (canvas_ == nullptr) {
1171 return *this;
1172 }
1173
1174 Paint p(paint);
1175 if (p.GetColor() == 0x00000001) { // foreground color and foreground color strategy identification
1176 p.SetColor(envStack_.top().envForegroundColor_.AsArgbInt());
1177 }
1178
1179 // use alphaStack_.top() to multiply alpha
1180 if (alphaStack_.top() < 1 && alphaStack_.top() > 0) {
1181 p.SetAlpha(p.GetAlpha() * alphaStack_.top());
1182 }
1183
1184 // use envStack_.top().blender_ to set blender
1185 if (auto& blender = envStack_.top().blender_) {
1186 if (p.GetBlenderEnabled()) {
1187 p.SetBlender(blender);
1188 }
1189 }
1190
1191 #ifdef SKP_RECORDING_ENABLED
1192 for (auto iter = pCanvasList_.begin(); iter != pCanvasList_.end(); ++iter) {
1193 if ((*iter) != nullptr) {
1194 (*iter)->AttachPaint(p);
1195 }
1196 }
1197 #else
1198 canvas_->AttachPaint(p);
1199 #endif
1200 return *this;
1201 }
1202
OnFilter() const1203 bool RSPaintFilterCanvas::OnFilter() const
1204 {
1205 return alphaStack_.top() > 0.f && !IsQuickGetDrawState();
1206 }
1207
GetRecordingCanvas() const1208 Drawing::Canvas* RSPaintFilterCanvas::GetRecordingCanvas() const
1209 {
1210 return recordingState_ ? canvas_ : nullptr;
1211 }
1212
GetRecordingState() const1213 bool RSPaintFilterCanvas::GetRecordingState() const
1214 {
1215 return recordingState_;
1216 }
1217
SetRecordingState(bool flag)1218 void RSPaintFilterCanvas::SetRecordingState(bool flag)
1219 {
1220 recordingState_ = flag;
1221 }
1222
MultiplyAlpha(float alpha)1223 void RSPaintFilterCanvas::MultiplyAlpha(float alpha)
1224 {
1225 // multiply alpha to top of stack
1226 alphaStack_.top() *= std::clamp(alpha, 0.f, 1.f);
1227 }
1228
SetAlpha(float alpha)1229 void RSPaintFilterCanvas::SetAlpha(float alpha)
1230 {
1231 alphaStack_.top() = std::clamp(alpha, 0.f, 1.f);
1232 }
1233
SaveAlpha()1234 int RSPaintFilterCanvas::SaveAlpha()
1235 {
1236 // make a copy of top of stack
1237 alphaStack_.push(alphaStack_.top());
1238 // return prev stack height
1239 return alphaStack_.size() - 1;
1240 }
1241
GetAlpha() const1242 float RSPaintFilterCanvas::GetAlpha() const
1243 {
1244 // return top of stack
1245 return alphaStack_.top();
1246 }
1247
RestoreAlpha()1248 void RSPaintFilterCanvas::RestoreAlpha()
1249 {
1250 // sanity check, stack should not be empty
1251 if (alphaStack_.size() <= 1u) {
1252 return;
1253 }
1254 alphaStack_.pop();
1255 }
1256
GetAlphaSaveCount() const1257 int RSPaintFilterCanvas::GetAlphaSaveCount() const
1258 {
1259 return alphaStack_.size();
1260 }
1261
RestoreAlphaToCount(int count)1262 void RSPaintFilterCanvas::RestoreAlphaToCount(int count)
1263 {
1264 // sanity check, stack should not be empty
1265 if (count < 1) {
1266 count = 1;
1267 }
1268 // poo stack until stack height equals count
1269 int n = static_cast<int>(alphaStack_.size()) - count;
1270 for (int i = 0; i < n; ++i) {
1271 alphaStack_.pop();
1272 }
1273 }
1274
SetBlendMode(std::optional<int> blendMode)1275 void RSPaintFilterCanvas::SetBlendMode(std::optional<int> blendMode)
1276 {
1277 std::shared_ptr<Drawing::Blender> blender = nullptr;
1278 if (blendMode) {
1279 // map blendMode to Drawing::BlendMode and convert to Blender
1280 blender = Drawing::Blender::CreateWithBlendMode(static_cast<Drawing::BlendMode>(*blendMode));
1281 }
1282 RSPaintFilterCanvas::SetBlender(blender);
1283 }
1284
SetBlender(std::shared_ptr<Drawing::Blender> blender)1285 void RSPaintFilterCanvas::SetBlender(std::shared_ptr<Drawing::Blender> blender)
1286 {
1287 envStack_.top().blender_ = blender;
1288 }
1289
SaveEnv()1290 int RSPaintFilterCanvas::SaveEnv()
1291 {
1292 // make a copy of top of stack
1293 envStack_.push(envStack_.top());
1294 // return prev stack height
1295 return envStack_.size() - 1;
1296 }
1297
RestoreEnv()1298 void RSPaintFilterCanvas::RestoreEnv()
1299 {
1300 // sanity check, stack should not be empty
1301 if (envStack_.size() <= 1) {
1302 return;
1303 }
1304 envStack_.pop();
1305 }
1306
RestoreEnvToCount(int count)1307 void RSPaintFilterCanvas::RestoreEnvToCount(int count)
1308 {
1309 // sanity check, stack should not be empty
1310 if (count < 1) {
1311 count = 1;
1312 }
1313 // poo stack until stack height equals count
1314 int n = static_cast<int>(envStack_.size()) - count;
1315 for (int i = 0; i < n; ++i) {
1316 envStack_.pop();
1317 }
1318 }
1319
GetEnvSaveCount() const1320 int RSPaintFilterCanvas::GetEnvSaveCount() const
1321 {
1322 return envStack_.size();
1323 }
1324
SetEnvForegroundColor(Rosen::RSColor color)1325 void RSPaintFilterCanvas::SetEnvForegroundColor(Rosen::RSColor color)
1326 {
1327 // sanity check, stack should not be empty
1328 if (envStack_.empty()) {
1329 return;
1330 }
1331 envStack_.top().envForegroundColor_ = color;
1332 }
1333
GetEnvForegroundColor() const1334 Drawing::ColorQuad RSPaintFilterCanvas::GetEnvForegroundColor() const
1335 {
1336 // sanity check, stack should not be empty
1337 if (envStack_.empty()) {
1338 return Drawing::Color::COLOR_BLACK; // 0xFF000000 is default value -- black
1339 }
1340 return envStack_.top().envForegroundColor_.AsArgbInt();
1341 }
1342
SaveAllStatus(SaveType type)1343 RSPaintFilterCanvas::SaveStatus RSPaintFilterCanvas::SaveAllStatus(SaveType type)
1344 {
1345 // save and return status on demand
1346 return { (RSPaintFilterCanvas::kCanvas & type) ? Save() : GetSaveCount(),
1347 (RSPaintFilterCanvas::kAlpha & type) ? SaveAlpha() : GetAlphaSaveCount(),
1348 (RSPaintFilterCanvas::kEnv & type) ? SaveEnv() : GetEnvSaveCount() };
1349 }
1350
GetSaveStatus() const1351 RSPaintFilterCanvas::SaveStatus RSPaintFilterCanvas::GetSaveStatus() const
1352 {
1353 return { GetSaveCount(), GetAlphaSaveCount(), GetEnvSaveCount() };
1354 }
1355
RestoreStatus(const SaveStatus & status)1356 void RSPaintFilterCanvas::RestoreStatus(const SaveStatus& status)
1357 {
1358 // simultaneously restore canvas and alpha
1359 RestoreToCount(status.canvasSaveCount);
1360 RestoreAlphaToCount(status.alphaSaveCount);
1361 RestoreEnvToCount(status.envSaveCount);
1362 }
1363
PushDirtyRegion(Drawing::Region & resultRegion)1364 void RSPaintFilterCanvas::PushDirtyRegion(Drawing::Region& resultRegion)
1365 {
1366 dirtyRegionStack_.push(std::move(resultRegion));
1367 }
1368
PopDirtyRegion()1369 void RSPaintFilterCanvas::PopDirtyRegion()
1370 {
1371 if (dirtyRegionStack_.empty()) {
1372 return;
1373 }
1374 dirtyRegionStack_.pop();
1375 }
1376
GetCurDirtyRegion()1377 Drawing::Region& RSPaintFilterCanvas::GetCurDirtyRegion()
1378 {
1379 return dirtyRegionStack_.top();
1380 }
1381
IsDirtyRegionStackEmpty()1382 bool RSPaintFilterCanvas::IsDirtyRegionStackEmpty()
1383 {
1384 return dirtyRegionStack_.empty();
1385 }
1386
CopyHDRConfiguration(const RSPaintFilterCanvas & other)1387 void RSPaintFilterCanvas::CopyHDRConfiguration(const RSPaintFilterCanvas& other)
1388 {
1389 brightnessRatio_ = other.brightnessRatio_;
1390 screenId_ = other.screenId_;
1391 targetColorGamut_ = other.targetColorGamut_;
1392 isHdrOn_ = other.isHdrOn_;
1393 hdrProperties_ = other.hdrProperties_;
1394 }
1395
CopyConfigurationToOffscreenCanvas(const RSPaintFilterCanvas & other)1396 void RSPaintFilterCanvas::CopyConfigurationToOffscreenCanvas(const RSPaintFilterCanvas& other)
1397 {
1398 // Note:
1399 // 1. we don't need to copy alpha status, alpha will be applied when drawing cache.
1400 // 2. This function should only be called when creating offscreen canvas.
1401 // copy high contrast flag
1402 isHighContrastEnabled_.store(other.isHighContrastEnabled_.load());
1403 // copy env
1404 envStack_.top() = other.envStack_.top();
1405 // update effect matrix
1406 auto effectData = other.envStack_.top().effectData_;
1407 if (effectData != nullptr) {
1408 // make a deep copy of effect data, and calculate the mapping matrix from
1409 // local coordinate system to global coordinate system.
1410 auto copiedEffectData = std::make_shared<CachedEffectData>(*effectData);
1411 if (copiedEffectData == nullptr) {
1412 ROSEN_LOGE("RSPaintFilterCanvas::CopyConfigurationToOffscreenCanvas fail to create effectData");
1413 return;
1414 }
1415 Drawing::Matrix inverse;
1416 if (other.GetTotalMatrix().Invert(inverse)) {
1417 copiedEffectData->cachedMatrix_.PostConcat(inverse);
1418 } else {
1419 ROSEN_LOGE("RSPaintFilterCanvas::CopyConfigurationToOffscreenCanvas get invert matrix failed!");
1420 }
1421 envStack_.top().effectData_ = copiedEffectData;
1422 }
1423 // cache related
1424 if (other.isHighContrastEnabled()) {
1425 // explicit disable cache for high contrast mode
1426 SetCacheType(RSPaintFilterCanvas::CacheType::DISABLED);
1427 } else {
1428 // planning: maybe we should copy source cache status
1429 SetCacheType(other.GetCacheType());
1430 }
1431 isParallelCanvas_ = other.isParallelCanvas_;
1432 disableFilterCache_ = other.disableFilterCache_;
1433 threadIndex_ = other.threadIndex_;
1434 }
1435
SetHighContrast(bool enabled)1436 void RSPaintFilterCanvas::SetHighContrast(bool enabled)
1437 {
1438 isHighContrastEnabled_ = enabled;
1439 }
isHighContrastEnabled() const1440 bool RSPaintFilterCanvas::isHighContrastEnabled() const
1441 {
1442 return isHighContrastEnabled_;
1443 }
1444
SetCacheType(CacheType type)1445 void RSPaintFilterCanvas::SetCacheType(CacheType type)
1446 {
1447 cacheType_ = type;
1448 }
GetCacheType() const1449 Drawing::CacheType RSPaintFilterCanvas::GetCacheType() const
1450 {
1451 return cacheType_;
1452 }
1453
SetVisibleRect(Drawing::Rect visibleRect)1454 void RSPaintFilterCanvas::SetVisibleRect(Drawing::Rect visibleRect)
1455 {
1456 visibleRect_ = visibleRect;
1457 }
1458
GetVisibleRect() const1459 Drawing::Rect RSPaintFilterCanvas::GetVisibleRect() const
1460 {
1461 return visibleRect_;
1462 }
1463
GetLocalClipBounds(const Drawing::Canvas & canvas,const Drawing::RectI * clipRect)1464 std::optional<Drawing::Rect> RSPaintFilterCanvas::GetLocalClipBounds(const Drawing::Canvas& canvas,
1465 const Drawing::RectI* clipRect)
1466 {
1467 // if clipRect is explicitly specified, use it as the device clip bounds
1468 Drawing::Rect bounds = Rect((clipRect != nullptr) ? *clipRect : canvas.GetDeviceClipBounds());
1469
1470 if (!bounds.IsValid()) {
1471 return std::nullopt;
1472 }
1473
1474 Drawing::Matrix inverse;
1475 // if we can't invert the CTM, we can't return local clip bounds
1476 if (!(canvas.GetTotalMatrix().Invert(inverse))) {
1477 return std::nullopt;
1478 }
1479 // return the inverse of the CTM applied to the device clip bounds as local clip bounds
1480 Drawing::Rect dst;
1481 inverse.MapRect(dst, bounds);
1482 return dst;
1483 }
1484
1485
SetEffectData(const std::shared_ptr<RSPaintFilterCanvas::CachedEffectData> & effectData)1486 void RSPaintFilterCanvas::SetEffectData(const std::shared_ptr<RSPaintFilterCanvas::CachedEffectData>& effectData)
1487 {
1488 envStack_.top().effectData_ = effectData;
1489 }
1490
SetDrawnRegion(const Occlusion::Region & region)1491 void RSPaintFilterCanvas::SetDrawnRegion(const Occlusion::Region& region)
1492 {
1493 drawnRegion_ = region;
1494 }
1495
GetDrawnRegion() const1496 const Occlusion::Region& RSPaintFilterCanvas::GetDrawnRegion() const
1497 {
1498 return drawnRegion_;
1499 }
1500
GetEffectData() const1501 const std::shared_ptr<RSPaintFilterCanvas::CachedEffectData>& RSPaintFilterCanvas::GetEffectData() const
1502 {
1503 return envStack_.top().effectData_;
1504 }
1505
SetBehindWindowData(const std::shared_ptr<RSPaintFilterCanvas::CachedEffectData> & behindWindowData)1506 void RSPaintFilterCanvas::SetBehindWindowData(
1507 const std::shared_ptr<RSPaintFilterCanvas::CachedEffectData>& behindWindowData)
1508 {
1509 envStack_.top().behindWindowData_ = behindWindowData;
1510 }
1511
GetBehindWindowData() const1512 const std::shared_ptr<RSPaintFilterCanvas::CachedEffectData>& RSPaintFilterCanvas::GetBehindWindowData() const
1513 {
1514 return envStack_.top().behindWindowData_;
1515 }
1516
ReplaceMainScreenData(std::shared_ptr<Drawing::Surface> & offscreenSurface,std::shared_ptr<RSPaintFilterCanvas> & offscreenCanvas)1517 void RSPaintFilterCanvas::ReplaceMainScreenData(std::shared_ptr<Drawing::Surface>& offscreenSurface,
1518 std::shared_ptr<RSPaintFilterCanvas>& offscreenCanvas)
1519 {
1520 if (offscreenSurface != nullptr && offscreenCanvas != nullptr) {
1521 storeMainScreenSurface_.push(surface_);
1522 storeMainScreenCanvas_.push(canvas_);
1523 surface_ = offscreenSurface.get();
1524 canvas_ = offscreenCanvas.get();
1525 OffscreenData offscreenData = {offscreenSurface, offscreenCanvas};
1526 offscreenDataList_.push(offscreenData);
1527 }
1528 }
1529
SwapBackMainScreenData()1530 void RSPaintFilterCanvas::SwapBackMainScreenData()
1531 {
1532 if (!storeMainScreenSurface_.empty() && !storeMainScreenCanvas_.empty() && !offscreenDataList_.empty()) {
1533 surface_ = storeMainScreenSurface_.top();
1534 canvas_ = storeMainScreenCanvas_.top();
1535 storeMainScreenSurface_.pop();
1536 storeMainScreenCanvas_.pop();
1537 offscreenDataList_.pop();
1538 }
1539 }
1540
SavePCanvasList()1541 void RSPaintFilterCanvas::SavePCanvasList()
1542 {
1543 storedPCanvasList_.push_back(pCanvasList_);
1544 }
1545
RestorePCanvasList()1546 void RSPaintFilterCanvas::RestorePCanvasList()
1547 {
1548 if (!storedPCanvasList_.empty()) {
1549 auto item = storedPCanvasList_.back();
1550 pCanvasList_.swap(item);
1551 storedPCanvasList_.pop_back();
1552 }
1553 }
1554
SetCanvasStatus(const CanvasStatus & status)1555 void RSPaintFilterCanvas::SetCanvasStatus(const CanvasStatus& status)
1556 {
1557 SetAlpha(status.alpha_);
1558 SetMatrix(status.matrix_);
1559 SetEffectData(status.effectData_);
1560 }
1561
GetCanvasStatus() const1562 RSPaintFilterCanvas::CanvasStatus RSPaintFilterCanvas::GetCanvasStatus() const
1563 {
1564 return { GetAlpha(), GetTotalMatrix(), GetEffectData() };
1565 }
1566
CachedEffectData(std::shared_ptr<Drawing::Image> && image,const Drawing::RectI & rect)1567 RSPaintFilterCanvas::CachedEffectData::CachedEffectData(std::shared_ptr<Drawing::Image>&& image,
1568 const Drawing::RectI& rect)
1569 : cachedImage_(image), cachedRect_(rect), cachedMatrix_(Drawing::Matrix())
1570 {}
1571
CachedEffectData(const std::shared_ptr<Drawing::Image> & image,const Drawing::RectI & rect)1572 RSPaintFilterCanvas::CachedEffectData::CachedEffectData(const std::shared_ptr<Drawing::Image>& image,
1573 const Drawing::RectI& rect)
1574 : cachedImage_(image), cachedRect_(rect), cachedMatrix_(Drawing::Matrix())
1575 {}
1576
GetInfo() const1577 std::string RSPaintFilterCanvas::CachedEffectData::GetInfo() const
1578 {
1579 if (cachedImage_ == nullptr) {
1580 return "No valid cacheImage found.";
1581 }
1582 std::string ss;
1583 ss += " cachedRect: " + cachedRect_.ToString() +
1584 ", CacheImageWidth: " + std::to_string(cachedImage_->GetWidth()) +
1585 ", CacheImageHeight: " + std::to_string(cachedImage_->GetHeight());
1586 return ss;
1587 }
1588
SetIsParallelCanvas(bool isParallel)1589 void RSPaintFilterCanvas::SetIsParallelCanvas(bool isParallel)
1590 {
1591 isParallelCanvas_ = isParallel;
1592 }
1593
GetIsParallelCanvas() const1594 bool RSPaintFilterCanvas::GetIsParallelCanvas() const
1595 {
1596 return isParallelCanvas_;
1597 }
1598
1599 // UNI_MAIN_THREAD_INDEX, UNI_RENDER_THREAD_INDEX, subthread 0 1 2.
SetParallelThreadIdx(uint32_t idx)1600 void RSPaintFilterCanvas::SetParallelThreadIdx(uint32_t idx)
1601 {
1602 threadIndex_ = idx;
1603 }
1604
GetParallelThreadIdx() const1605 uint32_t RSPaintFilterCanvas::GetParallelThreadIdx() const
1606 {
1607 return threadIndex_;
1608 }
1609
GetParallelThreadId()1610 uint32_t RSPaintFilterCanvas::GetParallelThreadId()
1611 {
1612 return threadId_;
1613 }
1614
SetParallelThreadId(uint32_t idx)1615 void RSPaintFilterCanvas::SetParallelThreadId(uint32_t idx)
1616 {
1617 threadId_ = idx;
1618 }
1619
SetDisableFilterCache(bool disable)1620 void RSPaintFilterCanvas::SetDisableFilterCache(bool disable)
1621 {
1622 disableFilterCache_ = disable;
1623 }
1624
GetDisableFilterCache() const1625 bool RSPaintFilterCanvas::GetDisableFilterCache() const
1626 {
1627 return disableFilterCache_;
1628 }
1629
SetRecordDrawable(bool enable)1630 void RSPaintFilterCanvas::SetRecordDrawable(bool enable)
1631 {
1632 recordDrawable_ = enable;
1633 }
1634
GetRecordDrawable() const1635 bool RSPaintFilterCanvas::GetRecordDrawable() const
1636 {
1637 return recordDrawable_;
1638 }
HasOffscreenLayer() const1639 bool RSPaintFilterCanvas::HasOffscreenLayer() const
1640 {
1641 return envStack_.top().hasOffscreenLayer_;
1642 }
SaveLayer(const Drawing::SaveLayerOps & saveLayerOps)1643 void RSPaintFilterCanvas::SaveLayer(const Drawing::SaveLayerOps& saveLayerOps)
1644 {
1645 envStack_.top().hasOffscreenLayer_ = true;
1646 RSPaintFilterCanvasBase::SaveLayer(saveLayerOps);
1647 }
1648
IsOnMultipleScreen() const1649 bool RSPaintFilterCanvas::IsOnMultipleScreen() const
1650 {
1651 return multipleScreen_;
1652 }
SetOnMultipleScreen(bool multipleScreen)1653 void RSPaintFilterCanvas::SetOnMultipleScreen(bool multipleScreen)
1654 {
1655 multipleScreen_ = multipleScreen;
1656 }
1657
GetScreenshotType() const1658 RSPaintFilterCanvas::ScreenshotType RSPaintFilterCanvas::GetScreenshotType() const
1659 {
1660 return hdrProperties_.screenshotType;
1661 }
1662
SetScreenshotType(RSPaintFilterCanvas::ScreenshotType type)1663 void RSPaintFilterCanvas::SetScreenshotType(RSPaintFilterCanvas::ScreenshotType type)
1664 {
1665 hdrProperties_.screenshotType = type;
1666 }
1667
GetScreenId() const1668 ScreenId RSPaintFilterCanvas::GetScreenId() const
1669 {
1670 return screenId_;
1671 }
1672
SetScreenId(ScreenId screenId)1673 void RSPaintFilterCanvas::SetScreenId(ScreenId screenId)
1674 {
1675 screenId_ = screenId;
1676 }
1677
GetHDREnabledVirtualScreen() const1678 bool RSPaintFilterCanvas::GetHDREnabledVirtualScreen() const
1679 {
1680 return hdrProperties_.isHDREnabledVirtualScreen;
1681 }
1682
SetHDREnabledVirtualScreen(bool isHDREnabledVirtualScreen)1683 void RSPaintFilterCanvas::SetHDREnabledVirtualScreen(bool isHDREnabledVirtualScreen)
1684 {
1685 hdrProperties_.isHDREnabledVirtualScreen = isHDREnabledVirtualScreen;
1686 }
1687
RecordState(const RSPaintFilterCanvas & other)1688 void RSPaintFilterCanvas::RecordState(const RSPaintFilterCanvas& other)
1689 {
1690 canvas_->RecordState(other.canvas_);
1691 }
1692
GetWeakSurface()1693 std::weak_ptr<Drawing::Surface> RSPaintFilterCanvas::GetWeakSurface()
1694 {
1695 return weakSurface_;
1696 }
1697
SetWeakSurface(std::shared_ptr<Drawing::Surface> surface)1698 void RSPaintFilterCanvas::SetWeakSurface(std::shared_ptr<Drawing::Surface> surface)
1699 {
1700 weakSurface_ = surface;
1701 }
1702
GetHdrOn() const1703 bool RSPaintFilterCanvas::GetHdrOn() const
1704 {
1705 return isHdrOn_;
1706 }
1707
SetHdrOn(bool isHdrOn)1708 void RSPaintFilterCanvas::SetHdrOn(bool isHdrOn)
1709 {
1710 isHdrOn_ = isHdrOn;
1711 }
1712
GetHDRBrightness() const1713 float RSPaintFilterCanvas::GetHDRBrightness() const
1714 {
1715 return hdrProperties_.hdrBrightness;
1716 }
1717
SetHDRBrightness(float hdrBrightness)1718 void RSPaintFilterCanvas::SetHDRBrightness(float hdrBrightness)
1719 {
1720 hdrProperties_.hdrBrightness = hdrBrightness;
1721 }
1722
GetHDRProperties() const1723 const RSPaintFilterCanvas::HDRProperties& RSPaintFilterCanvas::GetHDRProperties() const
1724 {
1725 return hdrProperties_;
1726 }
1727
GetTargetColorGamut() const1728 GraphicColorGamut RSPaintFilterCanvas::GetTargetColorGamut() const
1729 {
1730 return targetColorGamut_;
1731 }
1732
SetTargetColorGamut(GraphicColorGamut colorGamut)1733 void RSPaintFilterCanvas::SetTargetColorGamut(GraphicColorGamut colorGamut)
1734 {
1735 targetColorGamut_ = colorGamut;
1736 }
1737
GetBrightnessRatio() const1738 float RSPaintFilterCanvas::GetBrightnessRatio() const
1739 {
1740 return brightnessRatio_;
1741 }
1742
SetBrightnessRatio(float brightnessRatio)1743 void RSPaintFilterCanvas::SetBrightnessRatio(float brightnessRatio)
1744 {
1745 brightnessRatio_ = brightnessRatio;
1746 }
1747
GetIsWindowFreezeCapture() const1748 bool RSPaintFilterCanvas::GetIsWindowFreezeCapture() const
1749 {
1750 return isWindowFreezeCapture_;
1751 }
1752
SetIsWindowFreezeCapture(bool isWindowFreezeCapture)1753 void RSPaintFilterCanvas::SetIsWindowFreezeCapture(bool isWindowFreezeCapture)
1754 {
1755 isWindowFreezeCapture_ = isWindowFreezeCapture;
1756 }
1757
1758 #ifdef RS_ENABLE_VK
AttachPaint(const Drawing::Paint & paint)1759 CoreCanvas& RSHybridRenderPaintFilterCanvas::AttachPaint(const Drawing::Paint& paint)
1760 {
1761 if (paint.GetColor() == Color::COLOR_FOREGROUND) {
1762 SetRenderWithForegroundColor(true);
1763 }
1764 return RSPaintFilterCanvas::AttachPaint(paint);
1765 }
1766 #endif
GetIsDrawingCache() const1767 bool RSPaintFilterCanvas::GetIsDrawingCache() const
1768 {
1769 return isDrawingCache_;
1770 }
1771
SetIsDrawingCache(bool isDrawingCache)1772 void RSPaintFilterCanvas::SetIsDrawingCache(bool isDrawingCache)
1773 {
1774 isDrawingCache_ = isDrawingCache;
1775 }
1776
CacheBehindWindowData(std::shared_ptr<RSFilter> filter,const Drawing::Rect rect)1777 RSPaintFilterCanvas::CacheBehindWindowData::CacheBehindWindowData(
1778 std::shared_ptr<RSFilter> filter, const Drawing::Rect rect)
1779 : filter_(filter), rect_(rect)
1780 {}
1781
SetCacheBehindWindowData(const std::shared_ptr<CacheBehindWindowData> & data)1782 void RSPaintFilterCanvas::SetCacheBehindWindowData(const std::shared_ptr<CacheBehindWindowData>& data)
1783 {
1784 cacheBehindWindowData_ = data;
1785 }
1786
GetCacheBehindWindowData() const1787 const std::shared_ptr<RSPaintFilterCanvas::CacheBehindWindowData>& RSPaintFilterCanvas::GetCacheBehindWindowData() const
1788 {
1789 return cacheBehindWindowData_;
1790 }
1791
SetEffectIntersectWithDRM(bool intersect)1792 void RSPaintFilterCanvas::SetEffectIntersectWithDRM(bool intersect)
1793 {
1794 isIntersectWithDRM_ = intersect;
1795 }
1796
GetEffectIntersectWithDRM() const1797 bool RSPaintFilterCanvas::GetEffectIntersectWithDRM() const
1798 {
1799 return isIntersectWithDRM_;
1800 }
1801
SetDarkColorMode(bool isDark)1802 void RSPaintFilterCanvas::SetDarkColorMode(bool isDark)
1803 {
1804 isDarkColorMode_ = isDark;
1805 }
1806
GetDarkColorMode() const1807 bool RSPaintFilterCanvas::GetDarkColorMode() const
1808 {
1809 return isDarkColorMode_;
1810 }
1811 } // namespace Rosen
1812 } // namespace OHOS
1813