blob: 9297604197c025bc402fb1624b27e06942a8affc [file] [log] [blame]
John Reck013127b2020-10-29 20:53:51 -04001/*
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
27namespace android::uirenderer {
28
29void 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
John Reck90b0a1c2020-11-12 12:37:30 -050035 source.for_each([&]<CanvasOpType T>(const CanvasOpContainer<T> * op) {
John Reck064650b2021-01-19 21:29:24 -050036 if constexpr (CanvasOpTraits::can_draw<CanvasOp<T>>) {
John Reck013127b2020-10-29 20:53:51 -040037 // Generic OP
38 // First apply the current transformation
39 destination->setMatrix(SkMatrix::Concat(currentGlobalTransform, op->transform()));
40 // Now draw it
41 (*op)->draw(destination);
John Reck064650b2021-01-19 21:29:24 -050042 return;
John Reck013127b2020-10-29 20:53:51 -040043 }
John Reck064650b2021-01-19 21:29:24 -050044 LOG_ALWAYS_FATAL("TODO, unable to rasterize %d", static_cast<int>(T));
John Reck013127b2020-10-29 20:53:51 -040045 });
46}
47
48} // namespace android::uirenderer