blob: ea3bfc9e80cb242a53b4b9f0cc9448516d2632df [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 Reck1bcacfd2017-11-03 10:12:19 -070019#include <utils/RefBase.h>
Romain Guydda57022010-07-06 11:39:32 -070020
John Recke170fb62018-05-07 08:12:07 -070021#include <SkBlendMode.h>
Derek Sollenbergerbe3876c2018-04-20 16:13:31 -040022#include <SkColorFilter.h>
23#include <SkColorSpace.h>
John Reck1bcacfd2017-11-03 10:12:19 -070024#include <SkPaint.h>
Stan Iliev564ca3e2018-09-04 22:00:00 +000025#include <SkImage.h>
26#include <SkMatrix.h>
27#include <system/graphics.h>
Romain Guydda57022010-07-06 11:39:32 -070028
29namespace android {
30namespace uirenderer {
31
Romain Guy8550c4c2010-10-08 15:49:53 -070032///////////////////////////////////////////////////////////////////////////////
33// Layers
34///////////////////////////////////////////////////////////////////////////////
Romain Guydda57022010-07-06 11:39:32 -070035
John Reck3b202512014-06-23 13:13:08 -070036class RenderState;
Romain Guy2bf68f02012-03-02 13:37:47 -080037
Romain Guydda57022010-07-06 11:39:32 -070038/**
Greg Daniel8cd3edf2017-01-09 14:15:41 -050039 * A layer has dimensions and is backed by a backend specific texture or framebuffer.
Romain Guydda57022010-07-06 11:39:32 -070040 */
Stan Iliev1a025a72018-09-05 16:35:11 -040041class Layer : public VirtualLightRefBase {
Chris Craik564acf72014-01-02 16:46:18 -080042public:
Stan Iliev564ca3e2018-09-04 22:00:00 +000043 Layer(RenderState& renderState, sk_sp<SkColorFilter>, int alpha, SkBlendMode mode);
Greg Daniel8cd3edf2017-01-09 14:15:41 -050044
Chet Haased15ebf22012-09-05 11:40:29 -070045 ~Layer();
Romain Guy8550c4c2010-10-08 15:49:53 -070046
Stan Iliev1a025a72018-09-05 16:35:11 -040047 uint32_t getWidth() const { return mWidth; }
Romain Guy9ace8f52011-07-07 20:50:11 -070048
Stan Iliev1a025a72018-09-05 16:35:11 -040049 uint32_t getHeight() const { return mHeight; }
Romain Guy9ace8f52011-07-07 20:50:11 -070050
Stan Iliev1a025a72018-09-05 16:35:11 -040051 void setSize(uint32_t width, uint32_t height) { mWidth = width; mHeight = height; }
Romain Guy9ace8f52011-07-07 20:50:11 -070052
Stan Iliev1a025a72018-09-05 16:35:11 -040053 void setBlend(bool blend) { mBlend = blend; }
Romain Guy9ace8f52011-07-07 20:50:11 -070054
Stan Iliev1a025a72018-09-05 16:35:11 -040055 bool isBlend() const { return mBlend; }
Romain Guy9ace8f52011-07-07 20:50:11 -070056
John Reck1bcacfd2017-11-03 10:12:19 -070057 inline void setForceFilter(bool forceFilter) { this->forceFilter = forceFilter; }
Chris Craik9757ac02014-02-25 18:50:17 -080058
John Reck1bcacfd2017-11-03 10:12:19 -070059 inline bool getForceFilter() const { return forceFilter; }
Chris Craik9757ac02014-02-25 18:50:17 -080060
John Reck1bcacfd2017-11-03 10:12:19 -070061 inline void setAlpha(int alpha) { this->alpha = alpha; }
Romain Guy9ace8f52011-07-07 20:50:11 -070062
Mike Reed260ab722016-10-07 15:59:20 -040063 inline void setAlpha(int alpha, SkBlendMode mode) {
Romain Guy9ace8f52011-07-07 20:50:11 -070064 this->alpha = alpha;
65 this->mode = mode;
66 }
67
John Reck1bcacfd2017-11-03 10:12:19 -070068 inline int getAlpha() const { return alpha; }
Romain Guy9ace8f52011-07-07 20:50:11 -070069
Stan Iliev8fc3d8e2018-09-28 18:44:26 -040070 SkBlendMode getMode() const;
Romain Guy9ace8f52011-07-07 20:50:11 -070071
Derek Sollenbergerd01b5912018-10-19 15:55:33 -040072 inline sk_sp<SkColorFilter> getColorFilter() const { return mColorFilter; }
Romain Guy9ace8f52011-07-07 20:50:11 -070073
Derek Sollenbergerd01b5912018-10-19 15:55:33 -040074 void setColorFilter(sk_sp<SkColorFilter> filter) { mColorFilter = filter; };
Romain Guy9ace8f52011-07-07 20:50:11 -070075
Stan Iliev564ca3e2018-09-04 22:00:00 +000076 inline SkMatrix& getTexTransform() { return texTransform; }
Romain Guy9fc27812011-04-27 14:21:41 -070077
Stan Iliev564ca3e2018-09-04 22:00:00 +000078 inline SkMatrix& getTransform() { return transform; }
Romain Guy302a9df2011-08-16 13:55:02 -070079
Romain Guy9fc27812011-04-27 14:21:41 -070080 /**
John Reck0e89e2b2014-10-31 14:49:06 -070081 * Posts a decStrong call to the appropriate thread.
82 * Thread-safe.
83 */
84 void postDecStrong();
85
Stan Iliev564ca3e2018-09-04 22:00:00 +000086 inline void setImage(const sk_sp<SkImage>& image) { this->layerImage = image; }
87
88 inline sk_sp<SkImage> getImage() const { return this->layerImage; }
89
Greg Daniel8cd3edf2017-01-09 14:15:41 -050090protected:
Greg Daniel8cd3edf2017-01-09 14:15:41 -050091
92 RenderState& mRenderState;
John Reck57998012015-01-29 10:17:57 -080093
Romain Guy9ace8f52011-07-07 20:50:11 -070094private:
Romain Guyaa6c24c2011-04-28 18:40:04 -070095 /**
Romain Guy9ace8f52011-07-07 20:50:11 -070096 * Color filter used to draw this layer. Optional.
97 */
Derek Sollenbergerbe3876c2018-04-20 16:13:31 -040098 sk_sp<SkColorFilter> mColorFilter;
99
100 /**
Chris Craik9757ac02014-02-25 18:50:17 -0800101 * Indicates raster data backing the layer is scaled, requiring filtration.
102 */
Chris Craike5c65842015-03-02 17:50:26 -0800103 bool forceFilter = false;
Chris Craik9757ac02014-02-25 18:50:17 -0800104
105 /**
Romain Guy9ace8f52011-07-07 20:50:11 -0700106 * Opacity of the layer.
107 */
sergeyv3e9999b2017-01-19 15:37:02 -0800108 int alpha;
Chris Craik9757ac02014-02-25 18:50:17 -0800109
Romain Guy9ace8f52011-07-07 20:50:11 -0700110 /**
111 * Blending mode of the layer.
112 */
sergeyv3e9999b2017-01-19 15:37:02 -0800113 SkBlendMode mode;
Romain Guyaa6c24c2011-04-28 18:40:04 -0700114
115 /**
116 * Optional texture coordinates transform.
117 */
Stan Iliev564ca3e2018-09-04 22:00:00 +0000118 SkMatrix texTransform;
Romain Guy8f0095c2011-05-02 17:24:22 -0700119
Romain Guy302a9df2011-08-16 13:55:02 -0700120 /**
121 * Optional transform.
122 */
Stan Iliev564ca3e2018-09-04 22:00:00 +0000123 SkMatrix transform;
124
125 /**
126 * An image backing the layer.
127 */
128 sk_sp<SkImage> layerImage;
129
130 /**
131 * layer width.
132 */
133 uint32_t mWidth = 0;
134
135 /**
136 * layer height.
137 */
138 uint32_t mHeight = 0;
139
140 /**
141 * enable blending
142 */
143 bool mBlend = false;
Romain Guy302a9df2011-08-16 13:55:02 -0700144
John Reck1bcacfd2017-11-03 10:12:19 -0700145}; // struct Layer
Romain Guydda57022010-07-06 11:39:32 -0700146
Chris Blume7b8a8082018-11-30 15:51:58 -0800147} // namespace uirenderer
148} // namespace android