blob: 7e41ad1d0e9c719e708386964ca61e771d722aa7 [file] [log] [blame]
Greg Daniel8cd3edf2017-01-09 14:15:41 -05001/*
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 Daniel45ec62b2017-01-04 14:27:00 -050021#include <SkImage.h>
Greg Daniel8cd3edf2017-01-09 14:15:41 -050022
23namespace android {
24namespace uirenderer {
25/**
26 * A layer has dimensions and is backed by a VkImage.
27 */
28class VkLayer : public Layer {
29public:
sergeyv3e9999b2017-01-19 15:37:02 -080030 VkLayer(RenderState& renderState, uint32_t layerWidth, uint32_t layerHeight,
31 SkColorFilter* colorFilter, int alpha, SkBlendMode mode, bool blend)
32 : Layer(renderState, Api::Vulkan, colorFilter, alpha, mode)
33 , mWidth(layerWidth)
34 , mHeight(layerHeight)
35 , mBlend(blend) {}
Greg Daniel8cd3edf2017-01-09 14:15:41 -050036
37 virtual ~VkLayer() {}
38
39 uint32_t getWidth() const override {
40 return mWidth;
41 }
42
43 uint32_t getHeight() const override {
44 return mHeight;
45 }
46
47 void setSize(uint32_t width, uint32_t height) override {
48 mWidth = width;
49 mHeight = height;
50 }
51
52 void setBlend(bool blend) override {
53 mBlend = blend;
54 }
55
56 bool isBlend() const override {
57 return mBlend;
58 }
59
Greg Daniel45ec62b2017-01-04 14:27:00 -050060 sk_sp<SkImage> getImage() {
61 return mImage;
Greg Daniel8cd3edf2017-01-09 14:15:41 -050062 }
63
Greg Daniel45ec62b2017-01-04 14:27:00 -050064 void updateTexture();
65
66 // If we've destroyed the vulkan context (VkInstance, VkDevice, etc.), we must make sure to
67 // destroy any VkImages that were made with that context.
68 void onVkContextDestroyed();
69
Greg Daniel8cd3edf2017-01-09 14:15:41 -050070private:
71 int mWidth;
72 int mHeight;
73 bool mBlend;
74
Greg Daniel45ec62b2017-01-04 14:27:00 -050075 sk_sp<SkImage> mImage;
Greg Daniel8cd3edf2017-01-09 14:15:41 -050076
77}; // struct VkLayer
78
79}; // namespace uirenderer
80}; // namespace android