Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | #pragma once |
| 18 | |
| 19 | #include "Layer.h" |
| 20 | |
Greg Daniel | 45ec62b | 2017-01-04 14:27:00 -0500 | [diff] [blame] | 21 | #include <SkImage.h> |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 22 | |
| 23 | namespace android { |
| 24 | namespace uirenderer { |
| 25 | /** |
| 26 | * A layer has dimensions and is backed by a VkImage. |
| 27 | */ |
| 28 | class VkLayer : public Layer { |
| 29 | public: |
sergeyv | 3e9999b | 2017-01-19 15:37:02 -0800 | [diff] [blame] | 30 | VkLayer(RenderState& renderState, uint32_t layerWidth, uint32_t layerHeight, |
Derek Sollenberger | be3876c | 2018-04-20 16:13:31 -0400 | [diff] [blame] | 31 | sk_sp<SkColorFilter> colorFilter, int alpha, SkBlendMode mode, bool blend) |
sergeyv | 3e9999b | 2017-01-19 15:37:02 -0800 | [diff] [blame] | 32 | : Layer(renderState, Api::Vulkan, colorFilter, alpha, mode) |
| 33 | , mWidth(layerWidth) |
| 34 | , mHeight(layerHeight) |
| 35 | , mBlend(blend) {} |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 36 | |
| 37 | virtual ~VkLayer() {} |
| 38 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 39 | uint32_t getWidth() const override { return mWidth; } |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 40 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 41 | uint32_t getHeight() const override { return mHeight; } |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 42 | |
| 43 | void setSize(uint32_t width, uint32_t height) override { |
| 44 | mWidth = width; |
| 45 | mHeight = height; |
| 46 | } |
| 47 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 48 | void setBlend(bool blend) override { mBlend = blend; } |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 49 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 50 | bool isBlend() const override { return mBlend; } |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 51 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 52 | sk_sp<SkImage> getImage() { return mImage; } |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 53 | |
Greg Daniel | 45ec62b | 2017-01-04 14:27:00 -0500 | [diff] [blame] | 54 | void updateTexture(); |
| 55 | |
| 56 | // If we've destroyed the vulkan context (VkInstance, VkDevice, etc.), we must make sure to |
| 57 | // destroy any VkImages that were made with that context. |
| 58 | void onVkContextDestroyed(); |
| 59 | |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 60 | private: |
| 61 | int mWidth; |
| 62 | int mHeight; |
| 63 | bool mBlend; |
| 64 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 65 | sk_sp<SkImage> mImage; |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 66 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 67 | }; // struct VkLayer |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 68 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 69 | }; // namespace uirenderer |
| 70 | }; // namespace android |