Romain Guy | dda5702 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 1 | /* |
| 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 Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 17 | #pragma once |
Romain Guy | dda5702 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 18 | |
Nick Kralevich | bfed827 | 2014-11-01 18:37:39 -0700 | [diff] [blame] | 19 | #include <utils/RefBase.h> |
John Reck | 38e0c32 | 2015-11-10 12:19:17 -0800 | [diff] [blame] | 20 | #include <GpuMemoryTracker.h> |
Romain Guy | dda5702 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 21 | |
Derek Sollenberger | ca79cf6 | 2012-08-14 16:44:52 -0400 | [diff] [blame] | 22 | #include <SkPaint.h> |
Mike Reed | 260ab72 | 2016-10-07 15:59:20 -0400 | [diff] [blame] | 23 | #include <SkBlendMode.h> |
Romain Guy | dda5702 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 24 | |
Derek Sollenberger | 76d3a1b | 2013-12-10 12:28:58 -0500 | [diff] [blame] | 25 | #include "Matrix.h" |
Romain Guy | dda5702 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 26 | |
| 27 | namespace android { |
| 28 | namespace uirenderer { |
| 29 | |
Romain Guy | 8550c4c | 2010-10-08 15:49:53 -0700 | [diff] [blame] | 30 | /////////////////////////////////////////////////////////////////////////////// |
| 31 | // Layers |
| 32 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | dda5702 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 33 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 34 | class RenderState; |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 35 | |
Romain Guy | dda5702 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 36 | /** |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 37 | * A layer has dimensions and is backed by a backend specific texture or framebuffer. |
Romain Guy | dda5702 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 38 | */ |
John Reck | 38e0c32 | 2015-11-10 12:19:17 -0800 | [diff] [blame] | 39 | class Layer : public VirtualLightRefBase, GpuMemoryTracker { |
Chris Craik | 564acf7 | 2014-01-02 16:46:18 -0800 | [diff] [blame] | 40 | public: |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 41 | enum class Api { |
| 42 | OpenGL = 0, |
| 43 | Vulkan = 1, |
Chris Craik | bfd1cd6 | 2014-09-10 13:04:31 -0700 | [diff] [blame] | 44 | }; |
Chris Craik | bfd1cd6 | 2014-09-10 13:04:31 -0700 | [diff] [blame] | 45 | |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 46 | Api getApi() const { |
| 47 | return mApi; |
| 48 | } |
| 49 | |
Chet Haase | d15ebf2 | 2012-09-05 11:40:29 -0700 | [diff] [blame] | 50 | ~Layer(); |
Romain Guy | 8550c4c | 2010-10-08 15:49:53 -0700 | [diff] [blame] | 51 | |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 52 | virtual uint32_t getWidth() const = 0; |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 53 | |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 54 | virtual uint32_t getHeight() const = 0; |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 55 | |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 56 | virtual void setSize(uint32_t width, uint32_t height) = 0; |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 57 | |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 58 | virtual void setBlend(bool blend) = 0; |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 59 | |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 60 | virtual bool isBlend() const = 0; |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 61 | |
Chris Craik | 9757ac0 | 2014-02-25 18:50:17 -0800 | [diff] [blame] | 62 | inline void setForceFilter(bool forceFilter) { |
| 63 | this->forceFilter = forceFilter; |
| 64 | } |
| 65 | |
| 66 | inline bool getForceFilter() const { |
| 67 | return forceFilter; |
| 68 | } |
| 69 | |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 70 | inline void setAlpha(int alpha) { |
| 71 | this->alpha = alpha; |
| 72 | } |
| 73 | |
Mike Reed | 260ab72 | 2016-10-07 15:59:20 -0400 | [diff] [blame] | 74 | inline void setAlpha(int alpha, SkBlendMode mode) { |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 75 | this->alpha = alpha; |
| 76 | this->mode = mode; |
| 77 | } |
| 78 | |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 79 | inline int getAlpha() const { |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 80 | return alpha; |
| 81 | } |
| 82 | |
Mike Reed | 260ab72 | 2016-10-07 15:59:20 -0400 | [diff] [blame] | 83 | inline SkBlendMode getMode() const { |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 84 | return mode; |
| 85 | } |
| 86 | |
Derek Sollenberger | 76d3a1b | 2013-12-10 12:28:58 -0500 | [diff] [blame] | 87 | inline SkColorFilter* getColorFilter() const { |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 88 | return colorFilter; |
| 89 | } |
| 90 | |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 91 | void setColorFilter(SkColorFilter* filter); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 92 | |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 93 | inline mat4& getTexTransform() { |
| 94 | return texTransform; |
Romain Guy | 9fc2781 | 2011-04-27 14:21:41 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Romain Guy | 302a9df | 2011-08-16 13:55:02 -0700 | [diff] [blame] | 97 | inline mat4& getTransform() { |
| 98 | return transform; |
| 99 | } |
| 100 | |
Romain Guy | 9fc2781 | 2011-04-27 14:21:41 -0700 | [diff] [blame] | 101 | /** |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 102 | * Posts a decStrong call to the appropriate thread. |
| 103 | * Thread-safe. |
| 104 | */ |
| 105 | void postDecStrong(); |
| 106 | |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 107 | protected: |
sergeyv | 3e9999b | 2017-01-19 15:37:02 -0800 | [diff] [blame] | 108 | Layer(RenderState& renderState, Api api, SkColorFilter* colorFilter, int alpha, |
| 109 | SkBlendMode mode); |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 110 | |
| 111 | RenderState& mRenderState; |
John Reck | 5799801 | 2015-01-29 10:17:57 -0800 | [diff] [blame] | 112 | |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 113 | private: |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 114 | Api mApi; |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 115 | |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 116 | /** |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 117 | * Color filter used to draw this layer. Optional. |
| 118 | */ |
sergeyv | 3e9999b | 2017-01-19 15:37:02 -0800 | [diff] [blame] | 119 | SkColorFilter* colorFilter; |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 120 | |
| 121 | /** |
Chris Craik | 9757ac0 | 2014-02-25 18:50:17 -0800 | [diff] [blame] | 122 | * Indicates raster data backing the layer is scaled, requiring filtration. |
| 123 | */ |
Chris Craik | e5c6584 | 2015-03-02 17:50:26 -0800 | [diff] [blame] | 124 | bool forceFilter = false; |
Chris Craik | 9757ac0 | 2014-02-25 18:50:17 -0800 | [diff] [blame] | 125 | |
| 126 | /** |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 127 | * Opacity of the layer. |
| 128 | */ |
sergeyv | 3e9999b | 2017-01-19 15:37:02 -0800 | [diff] [blame] | 129 | int alpha; |
Chris Craik | 9757ac0 | 2014-02-25 18:50:17 -0800 | [diff] [blame] | 130 | |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 131 | /** |
| 132 | * Blending mode of the layer. |
| 133 | */ |
sergeyv | 3e9999b | 2017-01-19 15:37:02 -0800 | [diff] [blame] | 134 | SkBlendMode mode; |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 135 | |
| 136 | /** |
| 137 | * Optional texture coordinates transform. |
| 138 | */ |
| 139 | mat4 texTransform; |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 140 | |
Romain Guy | 302a9df | 2011-08-16 13:55:02 -0700 | [diff] [blame] | 141 | /** |
| 142 | * Optional transform. |
| 143 | */ |
| 144 | mat4 transform; |
| 145 | |
Romain Guy | dda5702 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 146 | }; // struct Layer |
| 147 | |
| 148 | }; // namespace uirenderer |
| 149 | }; // namespace android |