The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 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 | #ifndef ANDROID_LAYER_BASE_H |
| 18 | #define ANDROID_LAYER_BASE_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
| 22 | |
Mathias Agopian | 1fed11c | 2009-06-23 18:08:22 -0700 | [diff] [blame] | 23 | #include <EGL/egl.h> |
| 24 | #include <EGL/eglext.h> |
Mathias Agopian | eda6540 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 25 | #include <GLES/gl.h> |
Mathias Agopian | 1fed11c | 2009-06-23 18:08:22 -0700 | [diff] [blame] | 26 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 27 | #include <utils/RefBase.h> |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 28 | #include <utils/String8.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 29 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | #include <ui/Region.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | |
Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 32 | #include <gui/ISurfaceComposerClient.h> |
Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 33 | |
Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 34 | #include <private/gui/LayerState.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | |
| 36 | #include "Transform.h" |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 37 | #include "DisplayHardware/HWComposer.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | |
| 39 | namespace android { |
| 40 | |
| 41 | // --------------------------------------------------------------------------- |
| 42 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | class Client; |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 44 | class DisplayDevice; |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 45 | class GraphicBuffer; |
Mathias Agopian | 670a899 | 2011-09-20 15:13:14 -0700 | [diff] [blame] | 46 | class Layer; |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 47 | class LayerBaseClient; |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 48 | class SurfaceFlinger; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | |
| 50 | // --------------------------------------------------------------------------- |
| 51 | |
Andy McFadden | 882e3a3 | 2013-01-08 16:06:15 -0800 | [diff] [blame] | 52 | /* |
| 53 | * Layers are rectangular graphic entities, internal to SurfaceFlinger. |
| 54 | * They have properties including width, height, Z-depth, and 2D |
| 55 | * transformations (chiefly translation and 90-degree rotations). |
| 56 | * |
| 57 | * Layers are organized into "layer stacks". Each layer is a member of |
| 58 | * exactly one layer stack, identified by an integer in Layer::State. A |
| 59 | * given layer stack may appear on more than one display. |
| 60 | * |
Mathias Agopian | 089a152 | 2013-03-05 14:51:39 -0800 | [diff] [blame^] | 61 | * Notable subclasses (below LayerBaseClient) include Layer and LayerDim. |
Andy McFadden | 882e3a3 | 2013-01-08 16:06:15 -0800 | [diff] [blame] | 62 | */ |
Igor Murashkin | a4a3149 | 2012-10-29 13:36:11 -0700 | [diff] [blame] | 63 | class LayerBase : virtual public RefBase |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | { |
Mathias Agopian | f6679fc | 2010-08-10 18:09:09 -0700 | [diff] [blame] | 65 | static int32_t sSequence; |
| 66 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | public: |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 68 | LayerBase(SurfaceFlinger* flinger); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | mutable bool contentDirty; |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 71 | // regions below are in window-manager space |
| 72 | Region visibleRegion; |
| 73 | Region coveredRegion; |
Jesse Hall | a8026d2 | 2012-09-25 13:25:04 -0700 | [diff] [blame] | 74 | Region visibleNonTransparentRegion; |
Mathias Agopian | f6679fc | 2010-08-10 18:09:09 -0700 | [diff] [blame] | 75 | int32_t sequence; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | |
Mathias Agopian | 93ffb86 | 2012-05-16 17:07:49 -0700 | [diff] [blame] | 77 | struct Geometry { |
Mathias Agopian | b30c415 | 2012-05-16 18:21:32 -0700 | [diff] [blame] | 78 | uint32_t w; |
| 79 | uint32_t h; |
| 80 | Rect crop; |
| 81 | inline bool operator == (const Geometry& rhs) const { |
| 82 | return (w==rhs.w && h==rhs.h && crop==rhs.crop); |
| 83 | } |
| 84 | inline bool operator != (const Geometry& rhs) const { |
| 85 | return !operator == (rhs); |
| 86 | } |
Mathias Agopian | 93ffb86 | 2012-05-16 17:07:49 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | struct State { |
| 90 | Geometry active; |
| 91 | Geometry requested; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | uint32_t z; |
Mathias Agopian | 8785578 | 2012-07-24 21:41:09 -0700 | [diff] [blame] | 93 | uint32_t layerStack; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | uint8_t alpha; |
| 95 | uint8_t flags; |
| 96 | uint8_t reserved[2]; |
| 97 | int32_t sequence; // changes when visible regions can change |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | Transform transform; |
| 99 | Region transparentRegion; |
| 100 | }; |
| 101 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 102 | class LayerMesh { |
| 103 | friend class LayerBase; |
| 104 | GLfloat mVertices[4][2]; |
| 105 | size_t mNumVertices; |
| 106 | public: |
| 107 | LayerMesh() : mNumVertices(4) { } |
| 108 | GLfloat const* getVertices() const { |
| 109 | return &mVertices[0][0]; |
| 110 | } |
| 111 | size_t getVertexCount() const { |
| 112 | return mNumVertices; |
| 113 | } |
| 114 | }; |
| 115 | |
Jamie Gennis | a249f2d | 2011-09-16 17:31:54 -0700 | [diff] [blame] | 116 | virtual void setName(const String8& name); |
Mathias Agopian | d129659 | 2010-03-09 19:17:47 -0800 | [diff] [blame] | 117 | String8 getName() const; |
| 118 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | // modify current state |
Mathias Agopian | 41b6aab | 2011-08-30 18:51:54 -0700 | [diff] [blame] | 120 | bool setPosition(float x, float y); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 121 | bool setLayer(uint32_t z); |
| 122 | bool setSize(uint32_t w, uint32_t h); |
| 123 | bool setAlpha(uint8_t alpha); |
| 124 | bool setMatrix(const layer_state_t::matrix22_t& matrix); |
Jesse Hall | a8026d2 | 2012-09-25 13:25:04 -0700 | [diff] [blame] | 125 | bool setTransparentRegionHint(const Region& transparent); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | bool setFlags(uint8_t flags, uint8_t mask); |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 127 | bool setCrop(const Rect& crop); |
Mathias Agopian | 8785578 | 2012-07-24 21:41:09 -0700 | [diff] [blame] | 128 | bool setLayerStack(uint32_t layerStack); |
| 129 | |
Mathias Agopian | ba6be54 | 2009-09-29 22:32:36 -0700 | [diff] [blame] | 130 | void commitTransaction(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | bool requestTransaction(); |
| 132 | void forceVisibilityTransaction(); |
| 133 | |
| 134 | uint32_t getTransactionFlags(uint32_t flags); |
| 135 | uint32_t setTransactionFlags(uint32_t flags); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 136 | |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 137 | void computeGeometry(const sp<const DisplayDevice>& hw, LayerMesh* mesh) const; |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 138 | Rect computeBounds() const; |
| 139 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 141 | virtual sp<LayerBaseClient> getLayerBaseClient() const; |
| 142 | virtual sp<Layer> getLayer() const; |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 143 | |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 144 | virtual const char* getTypeId() const { return "LayerBase"; } |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 145 | |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 146 | virtual void setGeometry(const sp<const DisplayDevice>& hw, |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 147 | HWComposer::HWCLayerInterface& layer); |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 148 | virtual void setPerFrameData(const sp<const DisplayDevice>& hw, |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 149 | HWComposer::HWCLayerInterface& layer); |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 150 | virtual void setAcquireFence(const sp<const DisplayDevice>& hw, |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 151 | HWComposer::HWCLayerInterface& layer); |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 152 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | /** |
| 154 | * draw - performs some global clipping optimizations |
| 155 | * and calls onDraw(). |
| 156 | * Typically this method is not overridden, instead implement onDraw() |
| 157 | * to perform the actual drawing. |
| 158 | */ |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 159 | virtual void draw(const sp<const DisplayDevice>& hw, const Region& clip) const; |
| 160 | virtual void draw(const sp<const DisplayDevice>& hw); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 161 | |
| 162 | /** |
| 163 | * onDraw - draws the surface. |
| 164 | */ |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 165 | virtual void onDraw(const sp<const DisplayDevice>& hw, const Region& clip) const = 0; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | |
| 167 | /** |
| 168 | * initStates - called just after construction |
| 169 | */ |
| 170 | virtual void initStates(uint32_t w, uint32_t h, uint32_t flags); |
| 171 | |
| 172 | /** |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 173 | * doTransaction - process the transaction. This is a good place to figure |
| 174 | * out which attributes of the surface have changed. |
| 175 | */ |
| 176 | virtual uint32_t doTransaction(uint32_t transactionFlags); |
| 177 | |
| 178 | /** |
| 179 | * setVisibleRegion - called to set the new visible region. This gives |
| 180 | * a chance to update the new visible region or record the fact it changed. |
| 181 | */ |
| 182 | virtual void setVisibleRegion(const Region& visibleRegion); |
| 183 | |
| 184 | /** |
| 185 | * setCoveredRegion - called when the covered region changes. The covered |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 186 | * region corresponds to any area of the surface that is covered |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | * (transparently or not) by another surface. |
| 188 | */ |
| 189 | virtual void setCoveredRegion(const Region& coveredRegion); |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 190 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | /** |
Jesse Hall | a8026d2 | 2012-09-25 13:25:04 -0700 | [diff] [blame] | 192 | * setVisibleNonTransparentRegion - called when the visible and |
| 193 | * non-transparent region changes. |
| 194 | */ |
| 195 | virtual void setVisibleNonTransparentRegion(const Region& |
| 196 | visibleNonTransparentRegion); |
| 197 | |
| 198 | /** |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 199 | * latchBuffer - called each time the screen is redrawn and returns whether |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 200 | * the visible regions need to be recomputed (this is a fairly heavy |
| 201 | * operation, so this should be set only if needed). Typically this is used |
| 202 | * to figure out if the content or size of a surface has changed. |
| 203 | */ |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 204 | virtual Region latchBuffer(bool& recomputeVisibleRegions); |
| 205 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 206 | /** |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 207 | * isOpaque - true if this surface is opaque |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 208 | */ |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 209 | virtual bool isOpaque() const { return true; } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 210 | |
| 211 | /** |
Mathias Agopian | 401c257 | 2009-09-23 19:16:27 -0700 | [diff] [blame] | 212 | * needsDithering - true if this surface needs dithering |
| 213 | */ |
| 214 | virtual bool needsDithering() const { return false; } |
| 215 | |
| 216 | /** |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 217 | * needsLinearFiltering - true if this surface's state requires filtering |
Mathias Agopian | a7f6692 | 2010-05-26 22:08:52 -0700 | [diff] [blame] | 218 | */ |
Mathias Agopian | eba8c68 | 2012-09-19 23:14:45 -0700 | [diff] [blame] | 219 | virtual bool needsFiltering(const sp<const DisplayDevice>& hw) const; |
Mathias Agopian | a7f6692 | 2010-05-26 22:08:52 -0700 | [diff] [blame] | 220 | |
| 221 | /** |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | * isSecure - true if this surface is secure, that is if it prevents |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 223 | * screenshots or VNC servers. |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 | */ |
| 225 | virtual bool isSecure() const { return false; } |
| 226 | |
Glenn Kasten | 16f0453 | 2011-01-19 15:27:27 -0800 | [diff] [blame] | 227 | /** |
Jamie Gennis | 7a4d0df | 2011-03-09 17:05:02 -0800 | [diff] [blame] | 228 | * isProtected - true if the layer may contain protected content in the |
| 229 | * GRALLOC_USAGE_PROTECTED sense. |
Glenn Kasten | 16f0453 | 2011-01-19 15:27:27 -0800 | [diff] [blame] | 230 | */ |
Jamie Gennis | 7a4d0df | 2011-03-09 17:05:02 -0800 | [diff] [blame] | 231 | virtual bool isProtected() const { return false; } |
Glenn Kasten | 16f0453 | 2011-01-19 15:27:27 -0800 | [diff] [blame] | 232 | |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 233 | /* |
| 234 | * isVisible - true if this layer is visibile, false otherwise |
| 235 | */ |
| 236 | virtual bool isVisible() const; |
| 237 | |
Mathias Agopian | 0b3ad46 | 2009-10-02 18:12:30 -0700 | [diff] [blame] | 238 | /** called with the state lock when the surface is removed from the |
| 239 | * current list */ |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 240 | virtual void onRemoved() { } |
Jamie Gennis | e8696a4 | 2012-01-15 18:54:57 -0800 | [diff] [blame] | 241 | |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 242 | /** called after page-flip |
| 243 | */ |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 244 | virtual void onLayerDisplayed(const sp<const DisplayDevice>& hw, |
Mathias Agopian | c397360 | 2012-08-31 17:51:25 -0700 | [diff] [blame] | 245 | HWComposer::HWCLayerInterface* layer); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 246 | |
| 247 | /** called before composition. |
| 248 | * returns true if the layer has pending updates. |
| 249 | */ |
| 250 | virtual bool onPreComposition() { return false; } |
Jamie Gennis | e8696a4 | 2012-01-15 18:54:57 -0800 | [diff] [blame] | 251 | |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 252 | /** called before composition. |
| 253 | */ |
| 254 | virtual void onPostComposition() { } |
| 255 | |
Andy McFadden | 6905205 | 2012-09-14 16:10:11 -0700 | [diff] [blame] | 256 | /** |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 257 | * Updates the GLConsumer's transform hint, for layers that have |
| 258 | * a GLConsumer. |
Andy McFadden | 6905205 | 2012-09-14 16:10:11 -0700 | [diff] [blame] | 259 | */ |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 260 | virtual void updateTransformHint(const sp<const DisplayDevice>& hw) const { } |
Andy McFadden | 6905205 | 2012-09-14 16:10:11 -0700 | [diff] [blame] | 261 | |
Mathias Agopian | a8bca8d | 2013-02-27 22:03:19 -0800 | [diff] [blame] | 262 | /** |
| 263 | * returns the rectangle that crops the content of the layer and scales it |
| 264 | * to the layer's size. |
| 265 | */ |
| 266 | virtual Rect getContentCrop() const; |
| 267 | |
| 268 | /* |
| 269 | * returns the transform bits (90 rotation / h-flip / v-flip) of the |
| 270 | * layer's content |
| 271 | */ |
| 272 | virtual uint32_t getContentTransform() const; |
| 273 | |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 274 | /** always call base class first */ |
| 275 | virtual void dump(String8& result, char* scratch, size_t size) const; |
Mathias Agopian | 48b888a | 2011-01-19 16:15:53 -0800 | [diff] [blame] | 276 | virtual void shortDump(String8& result, char* scratch, size_t size) const; |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 277 | virtual void dumpStats(String8& result, char* buffer, size_t SIZE) const; |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 278 | virtual void clearStats(); |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 279 | |
| 280 | |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 281 | enum { // flags for doTransaction() |
Mathias Agopian | 05cec9d | 2012-05-23 14:35:49 -0700 | [diff] [blame] | 282 | eDontUpdateGeometryState = 0x00000001, |
| 283 | eVisibleRegion = 0x00000002, |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 284 | }; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 285 | |
| 286 | |
| 287 | inline const State& drawingState() const { return mDrawingState; } |
| 288 | inline const State& currentState() const { return mCurrentState; } |
| 289 | inline State& currentState() { return mCurrentState; } |
| 290 | |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 291 | void clearWithOpenGL(const sp<const DisplayDevice>& hw, const Region& clip) const; |
Mathias Agopian | a2f4e56 | 2012-04-15 23:34:59 -0700 | [diff] [blame] | 292 | |
Mathias Agopian | fcb239d | 2012-08-02 16:01:34 -0700 | [diff] [blame] | 293 | void setFiltering(bool filtering); |
| 294 | bool getFiltering() const; |
| 295 | |
Mathias Agopian | a8bca8d | 2013-02-27 22:03:19 -0800 | [diff] [blame] | 296 | private: |
| 297 | Rect computeCrop(const sp<const DisplayDevice>& hw) const; |
| 298 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 299 | protected: |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 300 | void clearWithOpenGL(const sp<const DisplayDevice>& hw, const Region& clip, |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 301 | GLclampf r, GLclampf g, GLclampf b, GLclampf alpha) const; |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 302 | void drawWithOpenGL(const sp<const DisplayDevice>& hw, const Region& clip) const; |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 303 | |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 304 | sp<SurfaceFlinger> mFlinger; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 305 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 306 | private: |
| 307 | // accessed only in the main thread |
| 308 | // Whether filtering is forced on or not |
| 309 | bool mFiltering; |
Mathias Agopian | b661d66 | 2010-08-19 17:01:19 -0700 | [diff] [blame] | 310 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 311 | // Whether filtering is needed b/c of the drawingstate |
Mathias Agopian | a7f6692 | 2010-05-26 22:08:52 -0700 | [diff] [blame] | 312 | bool mNeedsFiltering; |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 313 | |
| 314 | protected: |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 315 | // these are protected by an external lock |
| 316 | State mCurrentState; |
| 317 | State mDrawingState; |
| 318 | volatile int32_t mTransactionFlags; |
| 319 | |
| 320 | // don't change, don't need a lock |
| 321 | bool mPremultipliedAlpha; |
Mathias Agopian | d129659 | 2010-03-09 19:17:47 -0800 | [diff] [blame] | 322 | String8 mName; |
| 323 | mutable bool mDebug; |
| 324 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 325 | |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 326 | public: |
| 327 | // called from class SurfaceFlinger |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 328 | virtual ~LayerBase(); |
| 329 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 330 | private: |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 331 | LayerBase(const LayerBase& rhs); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 332 | }; |
| 333 | |
| 334 | |
| 335 | // --------------------------------------------------------------------------- |
| 336 | |
Andy McFadden | 882e3a3 | 2013-01-08 16:06:15 -0800 | [diff] [blame] | 337 | /* |
| 338 | * This adds some additional fields and methods to support some Binder IPC |
| 339 | * interactions. In particular, the LayerBaseClient's lifetime can be |
| 340 | * managed by references to an ISurface object in another process. |
| 341 | */ |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 342 | class LayerBaseClient : public LayerBase |
| 343 | { |
| 344 | public: |
Andy McFadden | 882e3a3 | 2013-01-08 16:06:15 -0800 | [diff] [blame] | 345 | LayerBaseClient(SurfaceFlinger* flinger, const sp<Client>& client); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 346 | |
Andy McFadden | 882e3a3 | 2013-01-08 16:06:15 -0800 | [diff] [blame] | 347 | virtual ~LayerBaseClient(); |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 348 | |
Andy McFadden | 882e3a3 | 2013-01-08 16:06:15 -0800 | [diff] [blame] | 349 | // Creates an ISurface associated with this object. This may only be |
| 350 | // called once (see also getSurfaceBinder()). |
| 351 | sp<ISurface> getSurface(); |
| 352 | |
| 353 | // Returns the Binder object for the ISurface associated with |
| 354 | // this object. |
| 355 | wp<IBinder> getSurfaceBinder() const; |
| 356 | |
| 357 | virtual wp<IBinder> getSurfaceTextureBinder() const; |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 358 | |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 359 | virtual sp<LayerBaseClient> getLayerBaseClient() const { |
| 360 | return const_cast<LayerBaseClient*>(this); } |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 361 | |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 362 | virtual const char* getTypeId() const { return "LayerBaseClient"; } |
Mathias Agopian | 285dbde | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 363 | |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 364 | protected: |
| 365 | virtual void dump(String8& result, char* scratch, size_t size) const; |
Mathias Agopian | 48b888a | 2011-01-19 16:15:53 -0800 | [diff] [blame] | 366 | virtual void shortDump(String8& result, char* scratch, size_t size) const; |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 367 | |
Andy McFadden | 882e3a3 | 2013-01-08 16:06:15 -0800 | [diff] [blame] | 368 | /* |
| 369 | * Trivial class, used to ensure that mFlinger->onLayerDestroyed(mLayer) |
| 370 | * is called. |
| 371 | */ |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 372 | class LayerCleaner { |
| 373 | sp<SurfaceFlinger> mFlinger; |
| 374 | wp<LayerBaseClient> mLayer; |
| 375 | protected: |
| 376 | ~LayerCleaner(); |
| 377 | public: |
| 378 | LayerCleaner(const sp<SurfaceFlinger>& flinger, |
| 379 | const sp<LayerBaseClient>& layer); |
| 380 | }; |
| 381 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 382 | private: |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 383 | virtual sp<ISurface> createSurface(); |
| 384 | |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 385 | mutable Mutex mLock; |
Andy McFadden | 882e3a3 | 2013-01-08 16:06:15 -0800 | [diff] [blame] | 386 | |
| 387 | // Set to true if an ISurface has been associated with this object. |
Mathias Agopian | a1f47b9 | 2011-02-15 19:01:06 -0800 | [diff] [blame] | 388 | mutable bool mHasSurface; |
Andy McFadden | 882e3a3 | 2013-01-08 16:06:15 -0800 | [diff] [blame] | 389 | |
| 390 | // The ISurface's Binder object, set by getSurface(). |
Mathias Agopian | 0d15612 | 2011-01-25 20:17:45 -0800 | [diff] [blame] | 391 | wp<IBinder> mClientSurfaceBinder; |
Andy McFadden | 882e3a3 | 2013-01-08 16:06:15 -0800 | [diff] [blame] | 392 | |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 393 | const wp<Client> mClientRef; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 394 | }; |
| 395 | |
| 396 | // --------------------------------------------------------------------------- |
| 397 | |
| 398 | }; // namespace android |
| 399 | |
| 400 | #endif // ANDROID_LAYER_BASE_H |