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 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17 | #include <stdlib.h> |
| 18 | #include <stdint.h> |
| 19 | #include <sys/types.h> |
| 20 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 21 | #include <cutils/compiler.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 22 | #include <cutils/native_handle.h> |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 23 | #include <cutils/properties.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | |
| 25 | #include <utils/Errors.h> |
| 26 | #include <utils/Log.h> |
| 27 | #include <utils/StopWatch.h> |
| 28 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 29 | #include <ui/GraphicBuffer.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | #include <ui/PixelFormat.h> |
Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 31 | |
| 32 | #include <surfaceflinger/Surface.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | |
| 34 | #include "clz.h" |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 35 | #include "DisplayHardware/DisplayHardware.h" |
| 36 | #include "DisplayHardware/HWComposer.h" |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 37 | #include "GLExtensions.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | #include "Layer.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | #include "SurfaceFlinger.h" |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 40 | #include "SurfaceTextureLayer.h" |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 41 | #include <math.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | |
| 43 | #define DEBUG_RESIZE 0 |
| 44 | |
| 45 | |
| 46 | namespace android { |
| 47 | |
| 48 | // --------------------------------------------------------------------------- |
| 49 | |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 50 | Layer::Layer(SurfaceFlinger* flinger, |
| 51 | DisplayID display, const sp<Client>& client) |
| 52 | : LayerBaseClient(flinger, display, client), |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 53 | mTextureName(-1U), |
| 54 | mQueuedFrames(0), |
| 55 | mCurrentTransform(0), |
Mathias Agopian | 933389f | 2011-07-18 16:15:08 -0700 | [diff] [blame] | 56 | mCurrentScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE), |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 57 | mCurrentOpacity(true), |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 58 | mRefreshPending(0), |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 59 | mFrameLatencyNeeded(false), |
| 60 | mFrameLatencyOffset(0), |
Mathias Agopian | 5bf3abe | 2011-03-11 17:01:07 -0800 | [diff] [blame] | 61 | mFormat(PIXEL_FORMAT_NONE), |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 62 | mGLExtensions(GLExtensions::getInstance()), |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 63 | mOpaqueLayer(true), |
Mathias Agopian | d606de6 | 2010-05-10 20:06:11 -0700 | [diff] [blame] | 64 | mNeedsDithering(false), |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 65 | mSecure(false), |
Mathias Agopian | 933389f | 2011-07-18 16:15:08 -0700 | [diff] [blame] | 66 | mProtectedByApp(false) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 68 | mCurrentCrop.makeInvalid(); |
| 69 | glGenTextures(1, &mTextureName); |
Jamie Gennis | e8696a4 | 2012-01-15 18:54:57 -0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | void Layer::onLayerDisplayed() { |
| 73 | if (mFrameLatencyNeeded) { |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 74 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
| 75 | mFrameStats[mFrameLatencyOffset].timestamp = mSurfaceTexture->getTimestamp(); |
| 76 | mFrameStats[mFrameLatencyOffset].set = systemTime(); |
| 77 | mFrameStats[mFrameLatencyOffset].vsync = hw.getRefreshTimestamp(); |
Jamie Gennis | e8696a4 | 2012-01-15 18:54:57 -0800 | [diff] [blame] | 78 | mFrameLatencyOffset = (mFrameLatencyOffset + 1) % 128; |
| 79 | mFrameLatencyNeeded = false; |
| 80 | } |
Mathias Agopian | d606de6 | 2010-05-10 20:06:11 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 83 | void Layer::onFirstRef() |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 84 | { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 85 | LayerBaseClient::onFirstRef(); |
Mathias Agopian | ddc31c3 | 2011-06-12 18:05:53 -0700 | [diff] [blame] | 86 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 87 | struct FrameQueuedListener : public SurfaceTexture::FrameAvailableListener { |
| 88 | FrameQueuedListener(Layer* layer) : mLayer(layer) { } |
| 89 | private: |
| 90 | wp<Layer> mLayer; |
| 91 | virtual void onFrameAvailable() { |
| 92 | sp<Layer> that(mLayer.promote()); |
| 93 | if (that != 0) { |
| 94 | that->onFrameQueued(); |
| 95 | } |
| 96 | } |
| 97 | }; |
| 98 | mSurfaceTexture = new SurfaceTextureLayer(mTextureName, this); |
| 99 | mSurfaceTexture->setFrameAvailableListener(new FrameQueuedListener(this)); |
| 100 | mSurfaceTexture->setSynchronousMode(true); |
Mathias Agopian | 303d538 | 2012-02-05 01:49:16 -0800 | [diff] [blame^] | 101 | #ifdef USE_TRIPLE_BUFFERING |
| 102 | #warning "using triple buffering" |
| 103 | mSurfaceTexture->setBufferCountServer(3); |
| 104 | #else |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 105 | mSurfaceTexture->setBufferCountServer(2); |
Mathias Agopian | 303d538 | 2012-02-05 01:49:16 -0800 | [diff] [blame^] | 106 | #endif |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 109 | Layer::~Layer() |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 110 | { |
Mathias Agopian | 118d024 | 2011-10-13 16:02:48 -0700 | [diff] [blame] | 111 | mFlinger->postMessageAsync( |
| 112 | new SurfaceFlinger::MessageDestroyGLTexture(mTextureName) ); |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 115 | void Layer::onFrameQueued() { |
Jamie Gennis | 3d8063b | 2011-06-26 18:27:47 -0700 | [diff] [blame] | 116 | android_atomic_inc(&mQueuedFrames); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 117 | mFlinger->signalLayerUpdate(); |
Mathias Agopian | 579b3f8 | 2010-06-08 19:54:15 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Mathias Agopian | d606de6 | 2010-05-10 20:06:11 -0700 | [diff] [blame] | 120 | // called with SurfaceFlinger::mStateLock as soon as the layer is entered |
| 121 | // in the purgatory list |
| 122 | void Layer::onRemoved() |
| 123 | { |
Jamie Gennis | dbe6486 | 2011-07-30 14:33:49 -0700 | [diff] [blame] | 124 | mSurfaceTexture->abandon(); |
Mathias Agopian | 48d819a | 2009-09-10 19:41:18 -0700 | [diff] [blame] | 125 | } |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 126 | |
Jamie Gennis | a249f2d | 2011-09-16 17:31:54 -0700 | [diff] [blame] | 127 | void Layer::setName(const String8& name) { |
| 128 | LayerBase::setName(name); |
| 129 | mSurfaceTexture->setName(name); |
| 130 | } |
| 131 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 132 | sp<ISurface> Layer::createSurface() |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 133 | { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 134 | class BSurface : public BnSurface, public LayerCleaner { |
| 135 | wp<const Layer> mOwner; |
| 136 | virtual sp<ISurfaceTexture> getSurfaceTexture() const { |
| 137 | sp<ISurfaceTexture> res; |
| 138 | sp<const Layer> that( mOwner.promote() ); |
| 139 | if (that != NULL) { |
| 140 | res = that->mSurfaceTexture; |
| 141 | } |
| 142 | return res; |
| 143 | } |
| 144 | public: |
| 145 | BSurface(const sp<SurfaceFlinger>& flinger, |
| 146 | const sp<Layer>& layer) |
| 147 | : LayerCleaner(flinger, layer), mOwner(layer) { } |
| 148 | }; |
| 149 | sp<ISurface> sur(new BSurface(mFlinger, this)); |
Mathias Agopian | a1f47b9 | 2011-02-15 19:01:06 -0800 | [diff] [blame] | 150 | return sur; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | } |
| 152 | |
Jamie Gennis | 582270d | 2011-08-17 18:19:00 -0700 | [diff] [blame] | 153 | wp<IBinder> Layer::getSurfaceTextureBinder() const |
| 154 | { |
| 155 | return mSurfaceTexture->asBinder(); |
| 156 | } |
| 157 | |
Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 158 | status_t Layer::setBuffers( uint32_t w, uint32_t h, |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | PixelFormat format, uint32_t flags) |
| 160 | { |
Mathias Agopian | 401c257 | 2009-09-23 19:16:27 -0700 | [diff] [blame] | 161 | // this surfaces pixel format |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | PixelFormatInfo info; |
| 163 | status_t err = getPixelFormatInfo(format, &info); |
| 164 | if (err) return err; |
| 165 | |
Mathias Agopian | 401c257 | 2009-09-23 19:16:27 -0700 | [diff] [blame] | 166 | // the display's pixel format |
| 167 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
Mathias Agopian | ca99fb8 | 2010-04-14 16:43:44 -0700 | [diff] [blame] | 168 | uint32_t const maxSurfaceDims = min( |
| 169 | hw.getMaxTextureSize(), hw.getMaxViewportDims()); |
| 170 | |
| 171 | // never allow a surface larger than what our underlying GL implementation |
| 172 | // can handle. |
| 173 | if ((uint32_t(w)>maxSurfaceDims) || (uint32_t(h)>maxSurfaceDims)) { |
| 174 | return BAD_VALUE; |
| 175 | } |
| 176 | |
Mathias Agopian | 401c257 | 2009-09-23 19:16:27 -0700 | [diff] [blame] | 177 | PixelFormatInfo displayInfo; |
| 178 | getPixelFormatInfo(hw.getFormat(), &displayInfo); |
Mathias Agopian | a4b740e | 2009-10-05 18:20:39 -0700 | [diff] [blame] | 179 | const uint32_t hwFlags = hw.getFlags(); |
| 180 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 181 | mFormat = format; |
Mathias Agopian | eff062c | 2010-08-25 14:59:15 -0700 | [diff] [blame] | 182 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 183 | mSecure = (flags & ISurfaceComposer::eSecure) ? true : false; |
Glenn Kasten | 16f0453 | 2011-01-19 15:27:27 -0800 | [diff] [blame] | 184 | mProtectedByApp = (flags & ISurfaceComposer::eProtectedByApp) ? true : false; |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 185 | mOpaqueLayer = (flags & ISurfaceComposer::eOpaque); |
| 186 | mCurrentOpacity = getOpacityForFormat(format); |
| 187 | |
| 188 | mSurfaceTexture->setDefaultBufferSize(w, h); |
| 189 | mSurfaceTexture->setDefaultBufferFormat(format); |
Mathias Agopian | ca99fb8 | 2010-04-14 16:43:44 -0700 | [diff] [blame] | 190 | |
Mathias Agopian | 401c257 | 2009-09-23 19:16:27 -0700 | [diff] [blame] | 191 | // we use the red index |
| 192 | int displayRedSize = displayInfo.getSize(PixelFormatInfo::INDEX_RED); |
| 193 | int layerRedsize = info.getSize(PixelFormatInfo::INDEX_RED); |
| 194 | mNeedsDithering = layerRedsize > displayRedSize; |
| 195 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | return NO_ERROR; |
| 197 | } |
| 198 | |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 199 | void Layer::setGeometry(hwc_layer_t* hwcl) |
| 200 | { |
Mathias Agopian | a537c0f | 2011-08-02 15:51:37 -0700 | [diff] [blame] | 201 | LayerBaseClient::setGeometry(hwcl); |
| 202 | |
| 203 | hwcl->flags &= ~HWC_SKIP_LAYER; |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 204 | |
| 205 | // we can't do alpha-fade with the hwc HAL |
| 206 | const State& s(drawingState()); |
| 207 | if (s.alpha < 0xFF) { |
| 208 | hwcl->flags = HWC_SKIP_LAYER; |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Mathias Agopian | 29a367b | 2011-07-12 14:51:45 -0700 | [diff] [blame] | 211 | /* |
| 212 | * Transformations are applied in this order: |
| 213 | * 1) buffer orientation/flip/mirror |
| 214 | * 2) state transformation (window manager) |
| 215 | * 3) layer orientation (screen orientation) |
Mathias Agopian | d992db3 | 2011-08-18 18:31:00 -0700 | [diff] [blame] | 216 | * mTransform is already the composition of (2) and (3) |
Mathias Agopian | 29a367b | 2011-07-12 14:51:45 -0700 | [diff] [blame] | 217 | * (NOTE: the matrices are multiplied in reverse order) |
| 218 | */ |
| 219 | |
| 220 | const Transform bufferOrientation(mCurrentTransform); |
Mathias Agopian | d992db3 | 2011-08-18 18:31:00 -0700 | [diff] [blame] | 221 | const Transform tr(mTransform * bufferOrientation); |
Mathias Agopian | 29a367b | 2011-07-12 14:51:45 -0700 | [diff] [blame] | 222 | |
| 223 | // this gives us only the "orientation" component of the transform |
| 224 | const uint32_t finalTransform = tr.getOrientation(); |
| 225 | |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 226 | // we can only handle simple transformation |
Mathias Agopian | 29a367b | 2011-07-12 14:51:45 -0700 | [diff] [blame] | 227 | if (finalTransform & Transform::ROT_INVALID) { |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 228 | hwcl->flags = HWC_SKIP_LAYER; |
Mathias Agopian | a537c0f | 2011-08-02 15:51:37 -0700 | [diff] [blame] | 229 | } else { |
| 230 | hwcl->transform = finalTransform; |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 231 | } |
Mathias Agopian | c7f3381 | 2011-08-30 15:02:41 -0700 | [diff] [blame] | 232 | |
| 233 | if (isCropped()) { |
| 234 | hwcl->sourceCrop.left = mCurrentCrop.left; |
| 235 | hwcl->sourceCrop.top = mCurrentCrop.top; |
| 236 | hwcl->sourceCrop.right = mCurrentCrop.right; |
| 237 | hwcl->sourceCrop.bottom = mCurrentCrop.bottom; |
| 238 | } else { |
| 239 | const sp<GraphicBuffer>& buffer(mActiveBuffer); |
| 240 | hwcl->sourceCrop.left = 0; |
| 241 | hwcl->sourceCrop.top = 0; |
| 242 | if (buffer != NULL) { |
| 243 | hwcl->sourceCrop.right = buffer->width; |
| 244 | hwcl->sourceCrop.bottom = buffer->height; |
| 245 | } else { |
| 246 | hwcl->sourceCrop.right = mTransformedBounds.width(); |
| 247 | hwcl->sourceCrop.bottom = mTransformedBounds.height(); |
| 248 | } |
| 249 | } |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | void Layer::setPerFrameData(hwc_layer_t* hwcl) { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 253 | const sp<GraphicBuffer>& buffer(mActiveBuffer); |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 254 | if (buffer == NULL) { |
Mathias Agopian | da9584d | 2010-12-13 18:51:59 -0800 | [diff] [blame] | 255 | // this can happen if the client never drew into this layer yet, |
| 256 | // or if we ran out of memory. In that case, don't let |
| 257 | // HWC handle it. |
| 258 | hwcl->flags |= HWC_SKIP_LAYER; |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 259 | hwcl->handle = NULL; |
Mathias Agopian | a537c0f | 2011-08-02 15:51:37 -0700 | [diff] [blame] | 260 | } else { |
| 261 | hwcl->handle = buffer->handle; |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 262 | } |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 263 | } |
| 264 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 265 | void Layer::onDraw(const Region& clip) const |
| 266 | { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 267 | if (CC_UNLIKELY(mActiveBuffer == 0)) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 268 | // the texture has not been created yet, this Layer has |
Mathias Agopian | 179169e | 2010-05-06 20:21:45 -0700 | [diff] [blame] | 269 | // in fact never been drawn into. This happens frequently with |
| 270 | // SurfaceView because the WindowManager can't know when the client |
| 271 | // has drawn the first time. |
| 272 | |
| 273 | // If there is nothing under us, we paint the screen in black, otherwise |
| 274 | // we just skip this update. |
| 275 | |
| 276 | // figure out if there is something below us |
| 277 | Region under; |
Mathias Agopian | f7ae69d | 2011-08-23 12:34:29 -0700 | [diff] [blame] | 278 | const SurfaceFlinger::LayerVector& drawingLayers( |
| 279 | mFlinger->mDrawingState.layersSortedByZ); |
Mathias Agopian | 179169e | 2010-05-06 20:21:45 -0700 | [diff] [blame] | 280 | const size_t count = drawingLayers.size(); |
| 281 | for (size_t i=0 ; i<count ; ++i) { |
| 282 | const sp<LayerBase>& layer(drawingLayers[i]); |
| 283 | if (layer.get() == static_cast<LayerBase const*>(this)) |
| 284 | break; |
| 285 | under.orSelf(layer->visibleRegionScreen); |
| 286 | } |
| 287 | // if not everything below us is covered, we plug the holes! |
| 288 | Region holes(clip.subtract(under)); |
| 289 | if (!holes.isEmpty()) { |
Mathias Agopian | 0a91775 | 2010-06-14 21:20:00 -0700 | [diff] [blame] | 290 | clearWithOpenGL(holes, 0, 0, 0, 1); |
Mathias Agopian | 179169e | 2010-05-06 20:21:45 -0700 | [diff] [blame] | 291 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 292 | return; |
| 293 | } |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 294 | |
Jamie Gennis | 9575f60 | 2011-10-07 14:51:16 -0700 | [diff] [blame] | 295 | if (!isProtected()) { |
Mathias Agopian | c492e67 | 2011-10-18 14:49:27 -0700 | [diff] [blame] | 296 | glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTextureName); |
| 297 | GLenum filter = GL_NEAREST; |
Jamie Gennis | 9575f60 | 2011-10-07 14:51:16 -0700 | [diff] [blame] | 298 | if (getFiltering() || needsFiltering() || isFixedSize() || isCropped()) { |
| 299 | // TODO: we could be more subtle with isFixedSize() |
Mathias Agopian | c492e67 | 2011-10-18 14:49:27 -0700 | [diff] [blame] | 300 | filter = GL_LINEAR; |
Jamie Gennis | 9575f60 | 2011-10-07 14:51:16 -0700 | [diff] [blame] | 301 | } |
Mathias Agopian | c492e67 | 2011-10-18 14:49:27 -0700 | [diff] [blame] | 302 | glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, filter); |
| 303 | glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, filter); |
Jamie Gennis | 9575f60 | 2011-10-07 14:51:16 -0700 | [diff] [blame] | 304 | glMatrixMode(GL_TEXTURE); |
| 305 | glLoadMatrixf(mTextureMatrix); |
| 306 | glMatrixMode(GL_MODELVIEW); |
Mathias Agopian | c492e67 | 2011-10-18 14:49:27 -0700 | [diff] [blame] | 307 | glDisable(GL_TEXTURE_2D); |
Xavier Ducrohet | 4c4163b | 2011-10-21 16:18:48 -0700 | [diff] [blame] | 308 | glEnable(GL_TEXTURE_EXTERNAL_OES); |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 309 | } else { |
Mathias Agopian | c492e67 | 2011-10-18 14:49:27 -0700 | [diff] [blame] | 310 | glBindTexture(GL_TEXTURE_2D, mFlinger->getProtectedTexName()); |
Jamie Gennis | 9575f60 | 2011-10-07 14:51:16 -0700 | [diff] [blame] | 311 | glMatrixMode(GL_TEXTURE); |
| 312 | glLoadIdentity(); |
| 313 | glMatrixMode(GL_MODELVIEW); |
Mathias Agopian | c492e67 | 2011-10-18 14:49:27 -0700 | [diff] [blame] | 314 | glDisable(GL_TEXTURE_EXTERNAL_OES); |
| 315 | glEnable(GL_TEXTURE_2D); |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 316 | } |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 317 | |
| 318 | drawWithOpenGL(clip); |
| 319 | |
Mathias Agopian | c492e67 | 2011-10-18 14:49:27 -0700 | [diff] [blame] | 320 | glDisable(GL_TEXTURE_EXTERNAL_OES); |
| 321 | glDisable(GL_TEXTURE_2D); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 322 | } |
| 323 | |
Eric Hassold | ac45e6b | 2011-02-10 14:41:26 -0800 | [diff] [blame] | 324 | // As documented in libhardware header, formats in the range |
| 325 | // 0x100 - 0x1FF are specific to the HAL implementation, and |
| 326 | // are known to have no alpha channel |
| 327 | // TODO: move definition for device-specific range into |
| 328 | // hardware.h, instead of using hard-coded values here. |
| 329 | #define HARDWARE_IS_DEVICE_FORMAT(f) ((f) >= 0x100 && (f) <= 0x1FF) |
| 330 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 331 | bool Layer::getOpacityForFormat(uint32_t format) |
Eric Hassold | ac45e6b | 2011-02-10 14:41:26 -0800 | [diff] [blame] | 332 | { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 333 | if (HARDWARE_IS_DEVICE_FORMAT(format)) { |
| 334 | return true; |
Eric Hassold | ac45e6b | 2011-02-10 14:41:26 -0800 | [diff] [blame] | 335 | } |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 336 | PixelFormatInfo info; |
| 337 | status_t err = getPixelFormatInfo(PixelFormat(format), &info); |
| 338 | // in case of error (unknown format), we assume no blending |
| 339 | return (err || info.h_alpha <= info.l_alpha); |
Eric Hassold | ac45e6b | 2011-02-10 14:41:26 -0800 | [diff] [blame] | 340 | } |
| 341 | |
Eric Hassold | ac45e6b | 2011-02-10 14:41:26 -0800 | [diff] [blame] | 342 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 343 | bool Layer::isOpaque() const |
Mathias Agopian | a7f6692 | 2010-05-26 22:08:52 -0700 | [diff] [blame] | 344 | { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 345 | // if we don't have a buffer yet, we're translucent regardless of the |
| 346 | // layer's opaque flag. |
Jamie Gennis | db5230f | 2011-07-28 14:54:07 -0700 | [diff] [blame] | 347 | if (mActiveBuffer == 0) { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 348 | return false; |
Jamie Gennis | db5230f | 2011-07-28 14:54:07 -0700 | [diff] [blame] | 349 | } |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 350 | |
| 351 | // if the layer has the opaque flag, then we're always opaque, |
| 352 | // otherwise we use the current buffer's format. |
| 353 | return mOpaqueLayer || mCurrentOpacity; |
Mathias Agopian | a7f6692 | 2010-05-26 22:08:52 -0700 | [diff] [blame] | 354 | } |
| 355 | |
Jamie Gennis | 7a4d0df | 2011-03-09 17:05:02 -0800 | [diff] [blame] | 356 | bool Layer::isProtected() const |
| 357 | { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 358 | const sp<GraphicBuffer>& activeBuffer(mActiveBuffer); |
Jamie Gennis | 7a4d0df | 2011-03-09 17:05:02 -0800 | [diff] [blame] | 359 | return (activeBuffer != 0) && |
| 360 | (activeBuffer->getUsage() & GRALLOC_USAGE_PROTECTED); |
| 361 | } |
Mathias Agopian | b5b7f26 | 2010-05-07 15:58:44 -0700 | [diff] [blame] | 362 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 363 | uint32_t Layer::doTransaction(uint32_t flags) |
| 364 | { |
| 365 | const Layer::State& front(drawingState()); |
| 366 | const Layer::State& temp(currentState()); |
| 367 | |
Mathias Agopian | a138f89 | 2010-05-21 17:24:35 -0700 | [diff] [blame] | 368 | const bool sizeChanged = (front.requested_w != temp.requested_w) || |
| 369 | (front.requested_h != temp.requested_h); |
| 370 | |
| 371 | if (sizeChanged) { |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 372 | // the size changed, we need to ask our client to request a new buffer |
Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 373 | ALOGD_IF(DEBUG_RESIZE, |
Mathias Agopian | 3fbce7c | 2011-07-25 19:56:08 -0700 | [diff] [blame] | 374 | "doTransaction: " |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 375 | "resize (layer=%p), requested (%dx%d), drawing (%d,%d), " |
Mathias Agopian | 3fbce7c | 2011-07-25 19:56:08 -0700 | [diff] [blame] | 376 | "scalingMode=%d", |
Mathias Agopian | a138f89 | 2010-05-21 17:24:35 -0700 | [diff] [blame] | 377 | this, |
| 378 | int(temp.requested_w), int(temp.requested_h), |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 379 | int(front.requested_w), int(front.requested_h), |
Mathias Agopian | 3fbce7c | 2011-07-25 19:56:08 -0700 | [diff] [blame] | 380 | mCurrentScalingMode); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 381 | |
Mathias Agopian | a138f89 | 2010-05-21 17:24:35 -0700 | [diff] [blame] | 382 | if (!isFixedSize()) { |
Mathias Agopian | a138f89 | 2010-05-21 17:24:35 -0700 | [diff] [blame] | 383 | // this will make sure LayerBase::doTransaction doesn't update |
| 384 | // the drawing state's size |
| 385 | Layer::State& editDraw(mDrawingState); |
| 386 | editDraw.requested_w = temp.requested_w; |
| 387 | editDraw.requested_h = temp.requested_h; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 388 | } |
Jamie Gennis | 2a0d5b6 | 2011-09-26 16:54:44 -0700 | [diff] [blame] | 389 | |
| 390 | // record the new size, form this point on, when the client request |
| 391 | // a buffer, it'll get the new size. |
| 392 | mSurfaceTexture->setDefaultBufferSize(temp.requested_w, |
| 393 | temp.requested_h); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 394 | } |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 395 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 396 | return LayerBase::doTransaction(flags); |
| 397 | } |
| 398 | |
Mathias Agopian | a138f89 | 2010-05-21 17:24:35 -0700 | [diff] [blame] | 399 | bool Layer::isFixedSize() const { |
Mathias Agopian | 933389f | 2011-07-18 16:15:08 -0700 | [diff] [blame] | 400 | return mCurrentScalingMode != NATIVE_WINDOW_SCALING_MODE_FREEZE; |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | bool Layer::isCropped() const { |
| 404 | return !mCurrentCrop.isEmpty(); |
| 405 | } |
| 406 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 407 | // ---------------------------------------------------------------------------- |
| 408 | // pageflip handling... |
| 409 | // ---------------------------------------------------------------------------- |
| 410 | |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 411 | bool Layer::onPreComposition() |
| 412 | { |
| 413 | // if there was more than one pending update, request a refresh |
| 414 | if (mRefreshPending >= 2) { |
| 415 | mRefreshPending = 0; |
| 416 | return true; |
| 417 | } |
| 418 | mRefreshPending = 0; |
| 419 | return false; |
| 420 | } |
| 421 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 422 | void Layer::lockPageFlip(bool& recomputeVisibleRegions) |
| 423 | { |
Jamie Gennis | 3d8063b | 2011-06-26 18:27:47 -0700 | [diff] [blame] | 424 | if (mQueuedFrames > 0) { |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 425 | |
| 426 | // if we've already called updateTexImage() without going through |
| 427 | // a composition step, we have to skip this layer at this point |
| 428 | // because we cannot call updateTeximage() without a corresponding |
| 429 | // compositionComplete() call. |
| 430 | // we'll trigger an update in onPreComposition(). |
| 431 | if (mRefreshPending++) { |
| 432 | return; |
| 433 | } |
| 434 | |
Jamie Gennis | 351a513 | 2011-09-14 18:23:37 -0700 | [diff] [blame] | 435 | // Capture the old state of the layer for comparisons later |
Jamie Gennis | db5230f | 2011-07-28 14:54:07 -0700 | [diff] [blame] | 436 | const bool oldOpacity = isOpaque(); |
Jamie Gennis | 351a513 | 2011-09-14 18:23:37 -0700 | [diff] [blame] | 437 | sp<GraphicBuffer> oldActiveBuffer = mActiveBuffer; |
Jamie Gennis | db5230f | 2011-07-28 14:54:07 -0700 | [diff] [blame] | 438 | |
Jamie Gennis | 3d8063b | 2011-06-26 18:27:47 -0700 | [diff] [blame] | 439 | // signal another event if we have more frames pending |
| 440 | if (android_atomic_dec(&mQueuedFrames) > 1) { |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 441 | mFlinger->signalLayerUpdate(); |
Jamie Gennis | 3d8063b | 2011-06-26 18:27:47 -0700 | [diff] [blame] | 442 | } |
| 443 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 444 | if (mSurfaceTexture->updateTexImage() < NO_ERROR) { |
| 445 | // something happened! |
| 446 | recomputeVisibleRegions = true; |
| 447 | return; |
| 448 | } |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 449 | |
Jamie Gennis | 351a513 | 2011-09-14 18:23:37 -0700 | [diff] [blame] | 450 | // update the active buffer |
| 451 | mActiveBuffer = mSurfaceTexture->getCurrentBuffer(); |
Jamie Gennis | e8696a4 | 2012-01-15 18:54:57 -0800 | [diff] [blame] | 452 | mFrameLatencyNeeded = true; |
Mathias Agopian | d343e3d | 2010-03-15 18:15:20 -0700 | [diff] [blame] | 453 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 454 | const Rect crop(mSurfaceTexture->getCurrentCrop()); |
| 455 | const uint32_t transform(mSurfaceTexture->getCurrentTransform()); |
Mathias Agopian | 933389f | 2011-07-18 16:15:08 -0700 | [diff] [blame] | 456 | const uint32_t scalingMode(mSurfaceTexture->getCurrentScalingMode()); |
| 457 | if ((crop != mCurrentCrop) || |
| 458 | (transform != mCurrentTransform) || |
| 459 | (scalingMode != mCurrentScalingMode)) |
| 460 | { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 461 | mCurrentCrop = crop; |
| 462 | mCurrentTransform = transform; |
Mathias Agopian | 933389f | 2011-07-18 16:15:08 -0700 | [diff] [blame] | 463 | mCurrentScalingMode = scalingMode; |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 464 | mFlinger->invalidateHwcGeometry(); |
| 465 | } |
Mathias Agopian | da9584d | 2010-12-13 18:51:59 -0800 | [diff] [blame] | 466 | |
Mathias Agopian | c7f3381 | 2011-08-30 15:02:41 -0700 | [diff] [blame] | 467 | GLfloat textureMatrix[16]; |
| 468 | mSurfaceTexture->getTransformMatrix(textureMatrix); |
| 469 | if (memcmp(textureMatrix, mTextureMatrix, sizeof(textureMatrix))) { |
| 470 | memcpy(mTextureMatrix, textureMatrix, sizeof(textureMatrix)); |
| 471 | mFlinger->invalidateHwcGeometry(); |
| 472 | } |
| 473 | |
Jamie Gennis | 351a513 | 2011-09-14 18:23:37 -0700 | [diff] [blame] | 474 | uint32_t bufWidth = mActiveBuffer->getWidth(); |
| 475 | uint32_t bufHeight = mActiveBuffer->getHeight(); |
| 476 | if (oldActiveBuffer != NULL) { |
| 477 | if (bufWidth != uint32_t(oldActiveBuffer->width) || |
| 478 | bufHeight != uint32_t(oldActiveBuffer->height)) { |
Mathias Agopian | c7f3381 | 2011-08-30 15:02:41 -0700 | [diff] [blame] | 479 | mFlinger->invalidateHwcGeometry(); |
| 480 | } |
| 481 | } |
| 482 | |
Jamie Gennis | 351a513 | 2011-09-14 18:23:37 -0700 | [diff] [blame] | 483 | mCurrentOpacity = getOpacityForFormat(mActiveBuffer->format); |
Jamie Gennis | db5230f | 2011-07-28 14:54:07 -0700 | [diff] [blame] | 484 | if (oldOpacity != isOpaque()) { |
Eric Hassold | ac45e6b | 2011-02-10 14:41:26 -0800 | [diff] [blame] | 485 | recomputeVisibleRegions = true; |
| 486 | } |
| 487 | |
Mathias Agopian | f7ae69d | 2011-08-23 12:34:29 -0700 | [diff] [blame] | 488 | glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 489 | glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 490 | |
Jamie Gennis | a402c4c | 2011-10-14 16:44:08 -0700 | [diff] [blame] | 491 | // update the layer size if needed |
Mathias Agopian | d343e3d | 2010-03-15 18:15:20 -0700 | [diff] [blame] | 492 | const Layer::State& front(drawingState()); |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 493 | |
| 494 | // FIXME: mPostedDirtyRegion = dirty & bounds |
| 495 | mPostedDirtyRegion.set(front.w, front.h); |
| 496 | |
Mathias Agopian | 97c602c | 2011-07-19 15:24:46 -0700 | [diff] [blame] | 497 | if ((front.w != front.requested_w) || |
| 498 | (front.h != front.requested_h)) |
Mathias Agopian | df3e0b9 | 2009-09-30 14:07:22 -0700 | [diff] [blame] | 499 | { |
Mathias Agopian | 97c602c | 2011-07-19 15:24:46 -0700 | [diff] [blame] | 500 | // check that we received a buffer of the right size |
| 501 | // (Take the buffer's orientation into account) |
Mathias Agopian | 97c602c | 2011-07-19 15:24:46 -0700 | [diff] [blame] | 502 | if (mCurrentTransform & Transform::ROT_90) { |
| 503 | swap(bufWidth, bufHeight); |
| 504 | } |
| 505 | |
| 506 | if (isFixedSize() || |
| 507 | (bufWidth == front.requested_w && |
| 508 | bufHeight == front.requested_h)) |
Mathias Agopian | d343e3d | 2010-03-15 18:15:20 -0700 | [diff] [blame] | 509 | { |
| 510 | // Here we pretend the transaction happened by updating the |
| 511 | // current and drawing states. Drawing state is only accessed |
| 512 | // in this thread, no need to have it locked |
| 513 | Layer::State& editDraw(mDrawingState); |
| 514 | editDraw.w = editDraw.requested_w; |
| 515 | editDraw.h = editDraw.requested_h; |
Mathias Agopian | df3e0b9 | 2009-09-30 14:07:22 -0700 | [diff] [blame] | 516 | |
Mathias Agopian | d343e3d | 2010-03-15 18:15:20 -0700 | [diff] [blame] | 517 | // We also need to update the current state so that we don't |
| 518 | // end-up doing too much work during the next transaction. |
| 519 | // NOTE: We actually don't need hold the transaction lock here |
| 520 | // because State::w and State::h are only accessed from |
| 521 | // this thread |
| 522 | Layer::State& editTemp(currentState()); |
| 523 | editTemp.w = editDraw.w; |
| 524 | editTemp.h = editDraw.h; |
Mathias Agopian | df3e0b9 | 2009-09-30 14:07:22 -0700 | [diff] [blame] | 525 | |
Mathias Agopian | d343e3d | 2010-03-15 18:15:20 -0700 | [diff] [blame] | 526 | // recompute visible region |
| 527 | recomputeVisibleRegions = true; |
Mathias Agopian | 97c602c | 2011-07-19 15:24:46 -0700 | [diff] [blame] | 528 | } |
Mathias Agopian | 3fbce7c | 2011-07-25 19:56:08 -0700 | [diff] [blame] | 529 | |
Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 530 | ALOGD_IF(DEBUG_RESIZE, |
Mathias Agopian | 3fbce7c | 2011-07-25 19:56:08 -0700 | [diff] [blame] | 531 | "lockPageFlip : " |
| 532 | " (layer=%p), buffer (%ux%u, tr=%02x), " |
| 533 | "requested (%dx%d)", |
| 534 | this, |
| 535 | bufWidth, bufHeight, mCurrentTransform, |
| 536 | front.requested_w, front.requested_h); |
Mathias Agopian | df3e0b9 | 2009-09-30 14:07:22 -0700 | [diff] [blame] | 537 | } |
Mathias Agopian | caa600c | 2009-09-16 18:27:24 -0700 | [diff] [blame] | 538 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | void Layer::unlockPageFlip( |
| 542 | const Transform& planeTransform, Region& outDirtyRegion) |
| 543 | { |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 544 | if (mRefreshPending >= 2) { |
| 545 | return; |
| 546 | } |
| 547 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 548 | Region dirtyRegion(mPostedDirtyRegion); |
| 549 | if (!dirtyRegion.isEmpty()) { |
| 550 | mPostedDirtyRegion.clear(); |
| 551 | // The dirty region is given in the layer's coordinate space |
| 552 | // transform the dirty region by the surface's transformation |
| 553 | // and the global transformation. |
| 554 | const Layer::State& s(drawingState()); |
| 555 | const Transform tr(planeTransform * s.transform); |
| 556 | dirtyRegion = tr.transform(dirtyRegion); |
| 557 | |
| 558 | // At this point, the dirty region is in screen space. |
| 559 | // Make sure it's constrained by the visible region (which |
| 560 | // is in screen space as well). |
| 561 | dirtyRegion.andSelf(visibleRegionScreen); |
| 562 | outDirtyRegion.orSelf(dirtyRegion); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 563 | } |
| 564 | } |
| 565 | |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 566 | void Layer::dump(String8& result, char* buffer, size_t SIZE) const |
| 567 | { |
| 568 | LayerBaseClient::dump(result, buffer, SIZE); |
| 569 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 570 | sp<const GraphicBuffer> buf0(mActiveBuffer); |
| 571 | uint32_t w0=0, h0=0, s0=0, f0=0; |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 572 | if (buf0 != 0) { |
| 573 | w0 = buf0->getWidth(); |
| 574 | h0 = buf0->getHeight(); |
| 575 | s0 = buf0->getStride(); |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 576 | f0 = buf0->format; |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 577 | } |
| 578 | snprintf(buffer, SIZE, |
| 579 | " " |
Mathias Agopian | ad795ba | 2011-08-08 16:02:13 -0700 | [diff] [blame] | 580 | "format=%2d, activeBuffer=[%4ux%4u:%4u,%3X]," |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 581 | " transform-hint=0x%02x, queued-frames=%d, mRefreshPending=%d\n", |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 582 | mFormat, w0, h0, s0,f0, |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 583 | getTransformHint(), mQueuedFrames, mRefreshPending); |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 584 | |
| 585 | result.append(buffer); |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 586 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 587 | if (mSurfaceTexture != 0) { |
| 588 | mSurfaceTexture->dump(result, " ", buffer, SIZE); |
Mathias Agopian | 579b3f8 | 2010-06-08 19:54:15 -0700 | [diff] [blame] | 589 | } |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 590 | } |
| 591 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 592 | void Layer::dumpStats(String8& result, char* buffer, size_t SIZE) const |
| 593 | { |
| 594 | LayerBaseClient::dumpStats(result, buffer, SIZE); |
| 595 | const size_t o = mFrameLatencyOffset; |
| 596 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
| 597 | const nsecs_t period = hw.getRefreshPeriod(); |
| 598 | result.appendFormat("%lld\n", period); |
| 599 | for (size_t i=0 ; i<128 ; i++) { |
| 600 | const size_t index = (o+i) % 128; |
| 601 | const nsecs_t time_app = mFrameStats[index].timestamp; |
| 602 | const nsecs_t time_set = mFrameStats[index].set; |
| 603 | const nsecs_t time_vsync = mFrameStats[index].vsync; |
| 604 | result.appendFormat("%lld\t%lld\t%lld\n", |
| 605 | time_app, |
| 606 | time_vsync, |
| 607 | time_set); |
| 608 | } |
| 609 | result.append("\n"); |
| 610 | } |
| 611 | |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 612 | void Layer::clearStats() |
| 613 | { |
| 614 | LayerBaseClient::clearStats(); |
| 615 | memset(mFrameStats, 0, sizeof(mFrameStats)); |
| 616 | } |
| 617 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 618 | uint32_t Layer::getEffectiveUsage(uint32_t usage) const |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 619 | { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 620 | // TODO: should we do something special if mSecure is set? |
| 621 | if (mProtectedByApp) { |
| 622 | // need a hardware-protected path to external video sink |
| 623 | usage |= GraphicBuffer::USAGE_PROTECTED; |
Jamie Gennis | 54cc83e | 2010-11-02 11:51:32 -0700 | [diff] [blame] | 624 | } |
Jamie Gennis | 3599bf2 | 2011-08-10 11:48:07 -0700 | [diff] [blame] | 625 | usage |= GraphicBuffer::USAGE_HW_COMPOSER; |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 626 | return usage; |
Mathias Agopian | b5b7f26 | 2010-05-07 15:58:44 -0700 | [diff] [blame] | 627 | } |
| 628 | |
Mathias Agopian | a458364 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 629 | uint32_t Layer::getTransformHint() const { |
| 630 | uint32_t orientation = 0; |
| 631 | if (!mFlinger->mDebugDisableTransformHint) { |
Jamie Gennis | 8d91b42 | 2011-09-23 15:54:34 -0700 | [diff] [blame] | 632 | orientation = getPlaneOrientation(); |
Mathias Agopian | a458364 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 633 | if (orientation & Transform::ROT_INVALID) { |
| 634 | orientation = 0; |
| 635 | } |
| 636 | } |
| 637 | return orientation; |
| 638 | } |
| 639 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 640 | // --------------------------------------------------------------------------- |
| 641 | |
| 642 | |
| 643 | }; // namespace android |