blob: 69213817f8afd23af78cff6d1ff406741b09e782 [file] [log] [blame]
Romain Guydda57022010-07-06 11:39:32 -07001/*
2 * Copyright (C) 2010 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
Chris Craik5e00c7c2016-07-06 16:10:09 -070017#pragma once
Romain Guydda57022010-07-06 11:39:32 -070018
John Reck38e0c322015-11-10 12:19:17 -080019#include <GpuMemoryTracker.h>
John Reck1bcacfd2017-11-03 10:12:19 -070020#include <utils/RefBase.h>
Romain Guydda57022010-07-06 11:39:32 -070021
Mike Reed260ab722016-10-07 15:59:20 -040022#include <SkBlendMode.h>
John Reck1bcacfd2017-11-03 10:12:19 -070023#include <SkPaint.h>
Romain Guydda57022010-07-06 11:39:32 -070024
Derek Sollenberger76d3a1b2013-12-10 12:28:58 -050025#include "Matrix.h"
Romain Guydda57022010-07-06 11:39:32 -070026
27namespace android {
28namespace uirenderer {
29
Romain Guy8550c4c2010-10-08 15:49:53 -070030///////////////////////////////////////////////////////////////////////////////
31// Layers
32///////////////////////////////////////////////////////////////////////////////
Romain Guydda57022010-07-06 11:39:32 -070033
John Reck3b202512014-06-23 13:13:08 -070034class RenderState;
Romain Guy2bf68f02012-03-02 13:37:47 -080035
Romain Guydda57022010-07-06 11:39:32 -070036/**
Greg Daniel8cd3edf2017-01-09 14:15:41 -050037 * A layer has dimensions and is backed by a backend specific texture or framebuffer.
Romain Guydda57022010-07-06 11:39:32 -070038 */
John Reck38e0c322015-11-10 12:19:17 -080039class Layer : public VirtualLightRefBase, GpuMemoryTracker {
Chris Craik564acf72014-01-02 16:46:18 -080040public:
Greg Daniel8cd3edf2017-01-09 14:15:41 -050041 enum class Api {
42 OpenGL = 0,
43 Vulkan = 1,
Chris Craikbfd1cd62014-09-10 13:04:31 -070044 };
Chris Craikbfd1cd62014-09-10 13:04:31 -070045
John Reck1bcacfd2017-11-03 10:12:19 -070046 Api getApi() const { return mApi; }
Greg Daniel8cd3edf2017-01-09 14:15:41 -050047
Chet Haased15ebf22012-09-05 11:40:29 -070048 ~Layer();
Romain Guy8550c4c2010-10-08 15:49:53 -070049
Greg Daniel8cd3edf2017-01-09 14:15:41 -050050 virtual uint32_t getWidth() const = 0;
Romain Guy9ace8f52011-07-07 20:50:11 -070051
Greg Daniel8cd3edf2017-01-09 14:15:41 -050052 virtual uint32_t getHeight() const = 0;
Romain Guy9ace8f52011-07-07 20:50:11 -070053
Greg Daniel8cd3edf2017-01-09 14:15:41 -050054 virtual void setSize(uint32_t width, uint32_t height) = 0;
Romain Guy9ace8f52011-07-07 20:50:11 -070055
Greg Daniel8cd3edf2017-01-09 14:15:41 -050056 virtual void setBlend(bool blend) = 0;
Romain Guy9ace8f52011-07-07 20:50:11 -070057
Greg Daniel8cd3edf2017-01-09 14:15:41 -050058 virtual bool isBlend() const = 0;
Romain Guy9ace8f52011-07-07 20:50:11 -070059
John Reck1bcacfd2017-11-03 10:12:19 -070060 inline void setForceFilter(bool forceFilter) { this->forceFilter = forceFilter; }
Chris Craik9757ac02014-02-25 18:50:17 -080061
John Reck1bcacfd2017-11-03 10:12:19 -070062 inline bool getForceFilter() const { return forceFilter; }
Chris Craik9757ac02014-02-25 18:50:17 -080063
John Reck1bcacfd2017-11-03 10:12:19 -070064 inline void setAlpha(int alpha) { this->alpha = alpha; }
Romain Guy9ace8f52011-07-07 20:50:11 -070065
Mike Reed260ab722016-10-07 15:59:20 -040066 inline void setAlpha(int alpha, SkBlendMode mode) {
Romain Guy9ace8f52011-07-07 20:50:11 -070067 this->alpha = alpha;
68 this->mode = mode;
69 }
70
John Reck1bcacfd2017-11-03 10:12:19 -070071 inline int getAlpha() const { return alpha; }
Romain Guy9ace8f52011-07-07 20:50:11 -070072
John Reck1bcacfd2017-11-03 10:12:19 -070073 inline SkBlendMode getMode() const { return mode; }
Romain Guy9ace8f52011-07-07 20:50:11 -070074
John Reck1bcacfd2017-11-03 10:12:19 -070075 inline SkColorFilter* getColorFilter() const { return colorFilter; }
Romain Guy9ace8f52011-07-07 20:50:11 -070076
Chris Craik5e00c7c2016-07-06 16:10:09 -070077 void setColorFilter(SkColorFilter* filter);
Romain Guy9ace8f52011-07-07 20:50:11 -070078
John Reck1bcacfd2017-11-03 10:12:19 -070079 inline mat4& getTexTransform() { return texTransform; }
Romain Guy9fc27812011-04-27 14:21:41 -070080
John Reck1bcacfd2017-11-03 10:12:19 -070081 inline mat4& getTransform() { return transform; }
Romain Guy302a9df2011-08-16 13:55:02 -070082
Romain Guy9fc27812011-04-27 14:21:41 -070083 /**
John Reck0e89e2b2014-10-31 14:49:06 -070084 * Posts a decStrong call to the appropriate thread.
85 * Thread-safe.
86 */
87 void postDecStrong();
88
Greg Daniel8cd3edf2017-01-09 14:15:41 -050089protected:
sergeyv3e9999b2017-01-19 15:37:02 -080090 Layer(RenderState& renderState, Api api, SkColorFilter* colorFilter, int alpha,
John Reck1bcacfd2017-11-03 10:12:19 -070091 SkBlendMode mode);
Greg Daniel8cd3edf2017-01-09 14:15:41 -050092
93 RenderState& mRenderState;
John Reck57998012015-01-29 10:17:57 -080094
Romain Guy9ace8f52011-07-07 20:50:11 -070095private:
Greg Daniel8cd3edf2017-01-09 14:15:41 -050096 Api mApi;
Romain Guy9ace8f52011-07-07 20:50:11 -070097
Romain Guyaa6c24c2011-04-28 18:40:04 -070098 /**
Romain Guy9ace8f52011-07-07 20:50:11 -070099 * Color filter used to draw this layer. Optional.
100 */
sergeyv3e9999b2017-01-19 15:37:02 -0800101 SkColorFilter* colorFilter;
Romain Guy9ace8f52011-07-07 20:50:11 -0700102
103 /**
Chris Craik9757ac02014-02-25 18:50:17 -0800104 * Indicates raster data backing the layer is scaled, requiring filtration.
105 */
Chris Craike5c65842015-03-02 17:50:26 -0800106 bool forceFilter = false;
Chris Craik9757ac02014-02-25 18:50:17 -0800107
108 /**
Romain Guy9ace8f52011-07-07 20:50:11 -0700109 * Opacity of the layer.
110 */
sergeyv3e9999b2017-01-19 15:37:02 -0800111 int alpha;
Chris Craik9757ac02014-02-25 18:50:17 -0800112
Romain Guy9ace8f52011-07-07 20:50:11 -0700113 /**
114 * Blending mode of the layer.
115 */
sergeyv3e9999b2017-01-19 15:37:02 -0800116 SkBlendMode mode;
Romain Guyaa6c24c2011-04-28 18:40:04 -0700117
118 /**
119 * Optional texture coordinates transform.
120 */
121 mat4 texTransform;
Romain Guy8f0095c2011-05-02 17:24:22 -0700122
Romain Guy302a9df2011-08-16 13:55:02 -0700123 /**
124 * Optional transform.
125 */
126 mat4 transform;
127
John Reck1bcacfd2017-11-03 10:12:19 -0700128}; // struct Layer
Romain Guydda57022010-07-06 11:39:32 -0700129
John Reck1bcacfd2017-11-03 10:12:19 -0700130}; // namespace uirenderer
131}; // namespace android