John Reck | 013127b | 2020-10-29 20:53:51 -0400 | [diff] [blame] | 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 | |
| 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 | |
John Reck | 90b0a1c | 2020-11-12 12:37:30 -0500 | [diff] [blame] | 35 | source.for_each([&]<CanvasOpType T>(const CanvasOpContainer<T> * op) { |
John Reck | 064650b | 2021-01-19 21:29:24 -0500 | [diff] [blame] | 36 | if constexpr (CanvasOpTraits::can_draw<CanvasOp<T>>) { |
John Reck | 013127b | 2020-10-29 20:53:51 -0400 | [diff] [blame] | 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); |
John Reck | 064650b | 2021-01-19 21:29:24 -0500 | [diff] [blame] | 42 | return; |
John Reck | 013127b | 2020-10-29 20:53:51 -0400 | [diff] [blame] | 43 | } |
John Reck | 064650b | 2021-01-19 21:29:24 -0500 | [diff] [blame] | 44 | LOG_ALWAYS_FATAL("TODO, unable to rasterize %d", static_cast<int>(T)); |
John Reck | 013127b | 2020-10-29 20:53:51 -0400 | [diff] [blame] | 45 | }); |
| 46 | } |
| 47 | |
| 48 | } // namespace android::uirenderer |