• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include "TransformCanvas.h"
17 
18 #include "FunctorDrawable.h"
19 #include "HolePunch.h"
20 #include "SkData.h"
21 #include "SkDrawable.h"
22 
23 using namespace android::uirenderer::skiapipeline;
24 
onDrawAnnotation(const SkRect & rect,const char * key,SkData * value)25 void TransformCanvas::onDrawAnnotation(const SkRect& rect, const char* key, SkData* value) {
26     if (HOLE_PUNCH_ANNOTATION == key) {
27         auto* rectParams = reinterpret_cast<const float*>(value->data());
28         float radiusX = rectParams[0];
29         float radiusY = rectParams[1];
30         SkRRect roundRect = SkRRect::MakeRectXY(rect, radiusX, radiusY);
31 
32         SkPaint paint;
33         paint.setColor(SkColors::kBlack);
34         paint.setBlendMode(mHolePunchBlendMode);
35         mWrappedCanvas->drawRRect(roundRect, paint);
36     }
37 }
38 
onDrawDrawable(SkDrawable * drawable,const SkMatrix * matrix)39 void TransformCanvas::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) {
40     // TransformCanvas filters all drawing commands while maintaining the current
41     // clip stack and transformation. We need to draw most SkDrawables, since their
42     // draw calls may call methods that affect the clip stack and transformation. (Any
43     // actual draw commands will then be filtered out.) But FunctorDrawables are used
44     // as leaf nodes which issue self-contained OpenGL/Vulkan commands. These won't
45     // affect the clip stack + transformation, and in some cases cause problems (e.g. if
46     // the surface only has an alpha channel). See b/203960959
47     const auto* drawableName = drawable->getTypeName();
48     if (drawableName == nullptr || strcmp(drawableName, FunctorDrawable::TYPE_NAME) != 0) {
49         drawable->draw(this, matrix);
50     }
51 }
52 
onFilter(SkPaint & paint) const53 bool TransformCanvas::onFilter(SkPaint& paint) const {
54     return false;
55 }
56