1 /*
2  * Copyright (C) 2020 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 
17 #include "CanvasOpRasterizer.h"
18 
19 #include <SkCanvas.h>
20 #include <log/log.h>
21 
22 #include <vector>
23 
24 #include "CanvasOpBuffer.h"
25 #include "CanvasOps.h"
26 
27 namespace android::uirenderer {
28 
rasterizeCanvasBuffer(const CanvasOpBuffer & source,SkCanvas * destination)29 void rasterizeCanvasBuffer(const CanvasOpBuffer& source, SkCanvas* destination) {
30     // Tracks the global transform from the current display list back toward the display space
31     // Push on beginning a RenderNode draw, pop on ending one
32     std::vector<SkMatrix> globalMatrixStack;
33     SkMatrix& currentGlobalTransform = globalMatrixStack.emplace_back(SkMatrix::I());
34 
35     source.for_each([&]<CanvasOpType T>(const CanvasOpContainer<T> * op) {
36         if constexpr (CanvasOpTraits::can_draw<CanvasOp<T>>) {
37             // Generic OP
38             // First apply the current transformation
39             destination->setMatrix(SkMatrix::Concat(currentGlobalTransform, op->transform()));
40             // Now draw it
41             (*op)->draw(destination);
42             return;
43         }
44         LOG_ALWAYS_FATAL("TODO, unable to rasterize %d", static_cast<int>(T));
45     });
46 }
47 
48 }  // namespace android::uirenderer
49