diff options
| author | 2017-11-07 18:07:03 +0000 | |
|---|---|---|
| committer | 2017-11-07 18:07:03 +0000 | |
| commit | 89a9d6fcd5260eb3bc052c90221f0f053e96f8db (patch) | |
| tree | ac6a0987808f88bc4906396849035f2363a6b30d | |
| parent | 6c96b71e32bd367557b92b71d9885333dc0279cd (diff) | |
| parent | 41fdfc920e2a479add53a1936c3ae76cdbea41db (diff) | |
Merge "Run clang-format on Layer/SurfaceFlinger files"
| -rw-r--r-- | services/surfaceflinger/BufferLayer.cpp | 18 | ||||
| -rw-r--r-- | services/surfaceflinger/BufferLayer.h | 8 | ||||
| -rw-r--r-- | services/surfaceflinger/ColorLayer.cpp | 14 | ||||
| -rw-r--r-- | services/surfaceflinger/ColorLayer.h | 8 | ||||
| -rw-r--r--[-rwxr-xr-x] | services/surfaceflinger/Layer.cpp | 434 | ||||
| -rw-r--r-- | services/surfaceflinger/Layer.h | 125 |
6 files changed, 252 insertions, 355 deletions
diff --git a/services/surfaceflinger/BufferLayer.cpp b/services/surfaceflinger/BufferLayer.cpp index ccb65f6df2..8f5dea2691 100644 --- a/services/surfaceflinger/BufferLayer.cpp +++ b/services/surfaceflinger/BufferLayer.cpp @@ -99,11 +99,9 @@ BufferLayer::~BufferLayer() { #endif } -bool BufferLayer::isProtected() const -{ +bool BufferLayer::isProtected() const { const sp<GraphicBuffer>& activeBuffer(mActiveBuffer); - return (activeBuffer != 0) && - (activeBuffer->getUsage() & GRALLOC_USAGE_PROTECTED); + return (activeBuffer != 0) && (activeBuffer->getUsage() & GRALLOC_USAGE_PROTECTED); } bool BufferLayer::isVisible() const { @@ -140,9 +138,9 @@ status_t BufferLayer::setBuffers(uint32_t w, uint32_t h, PixelFormat format, uin } static constexpr mat4 inverseOrientation(uint32_t transform) { - const mat4 flipH(-1,0,0,0, 0,1,0,0, 0,0,1,0, 1,0,0,1); - const mat4 flipV( 1,0,0,0, 0,-1,0,0, 0,0,1,0, 0,1,0,1); - const mat4 rot90( 0,1,0,0, -1,0,0,0, 0,0,1,0, 1,0,0,1); + const mat4 flipH(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1); + const mat4 flipV(1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1); + const mat4 rot90(0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1); mat4 tr; if (transform & NATIVE_WINDOW_TRANSFORM_ROT_90) { @@ -605,8 +603,7 @@ void BufferLayer::setPerFrameData(const sp<const DisplayDevice>& hw, } #endif -bool BufferLayer::isOpaque(const Layer::State& s) const -{ +bool BufferLayer::isOpaque(const Layer::State& s) const { // if we don't have a buffer or sidebandStream yet, we're translucent regardless of the // layer's opaque flag. if ((mSidebandStream == nullptr) && (mActiveBuffer == nullptr)) { @@ -730,8 +727,7 @@ bool BufferLayer::getOpacityForFormat(uint32_t format) { return true; } -void BufferLayer::drawWithOpenGL(const RenderArea& renderArea, - bool useIdentityTransform) const { +void BufferLayer::drawWithOpenGL(const RenderArea& renderArea, bool useIdentityTransform) const { const State& s(getDrawingState()); computeGeometry(renderArea, mMesh, useIdentityTransform); diff --git a/services/surfaceflinger/BufferLayer.h b/services/surfaceflinger/BufferLayer.h index b245f2976e..882649ba70 100644 --- a/services/surfaceflinger/BufferLayer.h +++ b/services/surfaceflinger/BufferLayer.h @@ -16,8 +16,8 @@ #pragma once -#include "Layer.h" #include "Client.h" +#include "Layer.h" #include "DisplayHardware/HWComposer.h" #include "DisplayHardware/HWComposerBufferCache.h" #include "FrameTracker.h" @@ -118,7 +118,8 @@ public: #ifdef USE_HWC2 void setPerFrameData(const sp<const DisplayDevice>& displayDevice); #else - void setPerFrameData(const sp<const DisplayDevice>& hw, HWComposer::HWCLayerInterface& layer); + void setPerFrameData(const sp<const DisplayDevice>& hw, + HWComposer::HWCLayerInterface& layer); #endif bool isOpaque(const Layer::State& s) const override; @@ -137,8 +138,7 @@ private: static bool getOpacityForFormat(uint32_t format); // drawing - void drawWithOpenGL(const RenderArea& renderArea, - bool useIdentityTransform) const; + void drawWithOpenGL(const RenderArea& renderArea, bool useIdentityTransform) const; // Temporary - Used only for LEGACY camera mode. uint32_t getProducerStickyTransform() const; diff --git a/services/surfaceflinger/ColorLayer.cpp b/services/surfaceflinger/ColorLayer.cpp index 72fdaaa654..500f81f263 100644 --- a/services/surfaceflinger/ColorLayer.cpp +++ b/services/surfaceflinger/ColorLayer.cpp @@ -18,8 +18,8 @@ #undef LOG_TAG #define LOG_TAG "ColorLayer" -#include <stdlib.h> #include <stdint.h> +#include <stdlib.h> #include <sys/types.h> #include <utils/Errors.h> @@ -28,17 +28,16 @@ #include <ui/GraphicBuffer.h> #include "ColorLayer.h" -#include "SurfaceFlinger.h" #include "DisplayDevice.h" #include "RenderEngine/RenderEngine.h" +#include "SurfaceFlinger.h" namespace android { // --------------------------------------------------------------------------- -ColorLayer::ColorLayer(SurfaceFlinger* flinger, const sp<Client>& client, - const String8& name, uint32_t w, uint32_t h, uint32_t flags) +ColorLayer::ColorLayer(SurfaceFlinger* flinger, const sp<Client>& client, const String8& name, + uint32_t w, uint32_t h, uint32_t flags) : Layer(flinger, client, name, w, h, flags) { - // drawing state & current state are identical mDrawingState = mCurrentState; } @@ -46,12 +45,12 @@ ColorLayer::ColorLayer(SurfaceFlinger* flinger, const sp<Client>& client, void ColorLayer::onDraw(const RenderArea& renderArea, const Region& /* clip */, bool useIdentityTransform) const { const State& s(getDrawingState()); - if (s.color.a>0) { + if (s.color.a > 0) { Mesh mesh(Mesh::TRIANGLE_FAN, 4, 2); computeGeometry(renderArea, mesh, useIdentityTransform); RenderEngine& engine(mFlinger->getRenderEngine()); engine.setupLayerBlending(getPremultipledAlpha(), false /* opaque */, - true /* disableTexture */, s.color); + true /* disableTexture */, s.color); engine.drawMesh(mesh); engine.disableBlending(); } @@ -62,7 +61,6 @@ bool ColorLayer::isVisible() const { return !isHiddenByPolicy() && s.color.a; } - // --------------------------------------------------------------------------- }; // namespace android diff --git a/services/surfaceflinger/ColorLayer.h b/services/surfaceflinger/ColorLayer.h index c68ad023e1..89013274af 100644 --- a/services/surfaceflinger/ColorLayer.h +++ b/services/surfaceflinger/ColorLayer.h @@ -28,16 +28,16 @@ namespace android { class ColorLayer : public Layer { public: - ColorLayer(SurfaceFlinger* flinger, const sp<Client>& client, - const String8& name, uint32_t w, uint32_t h, uint32_t flags); + ColorLayer(SurfaceFlinger* flinger, const sp<Client>& client, const String8& name, uint32_t w, + uint32_t h, uint32_t flags); virtual ~ColorLayer() = default; virtual const char* getTypeId() const { return "ColorLayer"; } virtual void onDraw(const RenderArea& renderArea, const Region& clip, - bool useIdentityTransform) const; + bool useIdentityTransform) const; bool isVisible() const override; virtual bool isOpaque(const Layer::State&) const { return false; } - virtual bool isFixedSize() const { return true; } + virtual bool isFixedSize() const { return true; } void notifyAvailableFrames() override {} PixelFormat getPixelFormat() const override { return PIXEL_FORMAT_NONE; } diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index 763488c8f5..a318a8f46a 100755..100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -19,10 +19,10 @@ #define LOG_TAG "Layer" #define ATRACE_TAG ATRACE_TAG_GRAPHICS -#include <stdlib.h> +#include <math.h> #include <stdint.h> +#include <stdlib.h> #include <sys/types.h> -#include <math.h> #include <cutils/compiler.h> #include <cutils/native_handle.h> @@ -43,13 +43,13 @@ #include <gui/LayerDebugInfo.h> #include <gui/Surface.h> -#include "clz.h" #include "Colorizer.h" #include "DisplayDevice.h" #include "Layer.h" #include "LayerRejecter.h" #include "MonitoredProducer.h" #include "SurfaceFlinger.h" +#include "clz.h" #include "DisplayHardware/HWComposer.h" @@ -58,14 +58,14 @@ #include <mutex> #include "LayerProtoHelper.h" -#define DEBUG_RESIZE 0 +#define DEBUG_RESIZE 0 namespace android { int32_t Layer::sSequence = 1; -Layer::Layer(SurfaceFlinger* flinger, const sp<Client>& client, - const String8& name, uint32_t w, uint32_t h, uint32_t flags) +Layer::Layer(SurfaceFlinger* flinger, const sp<Client>& client, const String8& name, uint32_t w, + uint32_t h, uint32_t flags) : contentDirty(false), sequence(uint32_t(android_atomic_inc(&sSequence))), mFlinger(flinger), @@ -97,18 +97,14 @@ Layer::Layer(SurfaceFlinger* flinger, const sp<Client>& client, mQueueItems(), mLastFrameNumberReceived(0), mAutoRefresh(false), - mFreezeGeometryUpdates(false) -{ + mFreezeGeometryUpdates(false) { mCurrentCrop.makeInvalid(); uint32_t layerFlags = 0; - if (flags & ISurfaceComposerClient::eHidden) - layerFlags |= layer_state_t::eLayerHidden; - if (flags & ISurfaceComposerClient::eOpaque) - layerFlags |= layer_state_t::eLayerOpaque; - if (flags & ISurfaceComposerClient::eSecure) - layerFlags |= layer_state_t::eLayerSecure; + if (flags & ISurfaceComposerClient::eHidden) layerFlags |= layer_state_t::eLayerHidden; + if (flags & ISurfaceComposerClient::eOpaque) layerFlags |= layer_state_t::eLayerOpaque; + if (flags & ISurfaceComposerClient::eSecure) layerFlags |= layer_state_t::eLayerSecure; mName = name; mTransactionName = String8("TX - ") + mName; @@ -138,8 +134,7 @@ Layer::Layer(SurfaceFlinger* flinger, const sp<Client>& client, const auto& activeConfig = hwc.getActiveConfig(HWC_DISPLAY_PRIMARY); nsecs_t displayPeriod = activeConfig->getVsyncPeriod(); #else - nsecs_t displayPeriod = - flinger->getHwComposer().getRefreshPeriod(HWC_DISPLAY_PRIMARY); + nsecs_t displayPeriod = flinger->getHwComposer().getRefreshPeriod(HWC_DISPLAY_PRIMARY); #endif mFrameTracker.setDisplayRefreshPeriod(displayPeriod); @@ -148,8 +143,7 @@ Layer::Layer(SurfaceFlinger* flinger, const sp<Client>& client, mFrameEventHistory.initializeCompositorTiming(compositorTiming); } -void Layer::onFirstRef() { -} +void Layer::onFirstRef() {} Layer::~Layer() { mFrameTracker.logAndResetStats(mName); @@ -170,7 +164,7 @@ void Layer::onLayerDisplayed(const sp<Fence>& releaseFence) { } #else void Layer::onLayerDisplayed(const sp<const DisplayDevice>& /* hw */, - HWComposer::HWCLayerInterface* layer) { + HWComposer::HWCLayerInterface* layer) { if (layer) { layer->onDisplayed(); mSurfaceFlingerConsumer->setReleaseFence(layer->getAndResetReleaseFence()); @@ -233,8 +227,7 @@ sp<IBinder> Layer::getHandle() { #ifdef USE_HWC2 bool Layer::createHwcLayer(HWComposer* hwc, int32_t hwcId) { - LOG_ALWAYS_FATAL_IF(mHwcLayers.count(hwcId) != 0, - "Already have a layer for hwcId %d", hwcId); + LOG_ALWAYS_FATAL_IF(mHwcLayers.count(hwcId) != 0, "Already have a layer for hwcId %d", hwcId); HWC2::Layer* layer = hwc->createLayer(hwcId); if (!layer) { return false; @@ -243,7 +236,7 @@ bool Layer::createHwcLayer(HWComposer* hwc, int32_t hwcId) { hwcInfo.hwc = hwc; hwcInfo.layer = layer; layer->setLayerDestroyedListener( - [this, hwcId] (HWC2::Layer* /*layer*/){mHwcLayers.erase(hwcId);}); + [this, hwcId](HWC2::Layer* /*layer*/) { mHwcLayers.erase(hwcId); }); return true; } @@ -252,14 +245,12 @@ void Layer::destroyHwcLayer(int32_t hwcId) { return; } auto& hwcInfo = mHwcLayers[hwcId]; - LOG_ALWAYS_FATAL_IF(hwcInfo.layer == nullptr, - "Attempt to destroy null layer"); + LOG_ALWAYS_FATAL_IF(hwcInfo.layer == nullptr, "Attempt to destroy null layer"); LOG_ALWAYS_FATAL_IF(hwcInfo.hwc == nullptr, "Missing HWComposer"); hwcInfo.hwc->destroyLayer(hwcId, hwcInfo.layer); // The layer destroyed listener should have cleared the entry from // mHwcLayers. Verify that. - LOG_ALWAYS_FATAL_IF(mHwcLayers.count(hwcId) != 0, - "Stale layer entry in mHwcLayers"); + LOG_ALWAYS_FATAL_IF(mHwcLayers.count(hwcId) != 0, "Stale layer entry in mHwcLayers"); } void Layer::destroyAllHwcLayers() { @@ -269,7 +260,7 @@ void Layer::destroyAllHwcLayers() { destroyHwcLayer(mHwcLayers.begin()->first); } LOG_ALWAYS_FATAL_IF(!mHwcLayers.empty(), - "All hardware composer layers should have been destroyed"); + "All hardware composer layers should have been destroyed"); } #endif @@ -393,7 +384,7 @@ Rect Layer::computeInitialCrop(const sp<const DisplayDevice>& hw) const { activeCrop.clear(); } if (!s.finalCrop.isEmpty()) { - if(!activeCrop.intersect(s.finalCrop, &activeCrop)) { + if (!activeCrop.intersect(s.finalCrop, &activeCrop)) { activeCrop.clear(); } } @@ -443,16 +434,13 @@ FloatRect Layer::computeCrop(const sp<const DisplayDevice>& hw) const { * the code below applies the primary display's inverse transform to the * buffer */ - uint32_t invTransformOrient = - DisplayDevice::getPrimaryDisplayOrientationTransform(); + uint32_t invTransformOrient = DisplayDevice::getPrimaryDisplayOrientationTransform(); // calculate the inverse transform if (invTransformOrient & NATIVE_WINDOW_TRANSFORM_ROT_90) { - invTransformOrient ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | - NATIVE_WINDOW_TRANSFORM_FLIP_H; + invTransformOrient ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | NATIVE_WINDOW_TRANSFORM_FLIP_H; } // and apply to the current transform - invTransform = (Transform(invTransformOrient) * Transform(invTransform)) - .getOrientation(); + invTransform = (Transform(invTransformOrient) * Transform(invTransform)).getOrientation(); } int winWidth = s.active.w; @@ -466,27 +454,25 @@ FloatRect Layer::computeCrop(const sp<const DisplayDevice>& hw) const { bool is_h_flipped = (invTransform & NATIVE_WINDOW_TRANSFORM_FLIP_H) != 0; bool is_v_flipped = (invTransform & NATIVE_WINDOW_TRANSFORM_FLIP_V) != 0; if (is_h_flipped == is_v_flipped) { - invTransform ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | - NATIVE_WINDOW_TRANSFORM_FLIP_H; + invTransform ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | NATIVE_WINDOW_TRANSFORM_FLIP_H; } winWidth = s.active.h; winHeight = s.active.w; } - const Rect winCrop = activeCrop.transform( - invTransform, s.active.w, s.active.h); + const Rect winCrop = activeCrop.transform(invTransform, s.active.w, s.active.h); // below, crop is intersected with winCrop expressed in crop's coordinate space - float xScale = crop.getWidth() / float(winWidth); + float xScale = crop.getWidth() / float(winWidth); float yScale = crop.getHeight() / float(winHeight); - float insetL = winCrop.left * xScale; - float insetT = winCrop.top * yScale; - float insetR = (winWidth - winCrop.right ) * xScale; + float insetL = winCrop.left * xScale; + float insetT = winCrop.top * yScale; + float insetR = (winWidth - winCrop.right) * xScale; float insetB = (winHeight - winCrop.bottom) * yScale; - crop.left += insetL; - crop.top += insetT; - crop.right -= insetR; + crop.left += insetL; + crop.top += insetT; + crop.right -= insetR; crop.bottom -= insetB; return crop; @@ -495,9 +481,7 @@ FloatRect Layer::computeCrop(const sp<const DisplayDevice>& hw) const { #ifdef USE_HWC2 void Layer::setGeometry(const sp<const DisplayDevice>& displayDevice, uint32_t z) #else -void Layer::setGeometry( - const sp<const DisplayDevice>& hw, - HWComposer::HWCLayerInterface& layer) +void Layer::setGeometry(const sp<const DisplayDevice>& hw, HWComposer::HWCLayerInterface& layer) #endif { #ifdef USE_HWC2 @@ -529,18 +513,18 @@ void Layer::setGeometry( #ifdef USE_HWC2 auto blendMode = HWC2::BlendMode::None; if (!isOpaque(s) || getAlpha() != 1.0f) { - blendMode = mPremultipliedAlpha ? - HWC2::BlendMode::Premultiplied : HWC2::BlendMode::Coverage; + blendMode = + mPremultipliedAlpha ? HWC2::BlendMode::Premultiplied : HWC2::BlendMode::Coverage; } auto error = hwcLayer->setBlendMode(blendMode); - ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set blend mode %s:" - " %s (%d)", mName.string(), to_string(blendMode).c_str(), - to_string(error).c_str(), static_cast<int32_t>(error)); + ALOGE_IF(error != HWC2::Error::None, + "[%s] Failed to set blend mode %s:" + " %s (%d)", + mName.string(), to_string(blendMode).c_str(), to_string(error).c_str(), + static_cast<int32_t>(error)); #else if (!isOpaque(s) || getAlpha() != 1.0f) { - layer.setBlending(mPremultipliedAlpha ? - HWC_BLENDING_PREMULT : - HWC_BLENDING_COVERAGE); + layer.setBlending(mPremultipliedAlpha ? HWC_BLENDING_PREMULT : HWC_BLENDING_COVERAGE); } #endif @@ -552,9 +536,9 @@ void Layer::setGeometry( Rect activeCrop(s.crop); activeCrop = t.transform(activeCrop); #ifdef USE_HWC2 - if(!activeCrop.intersect(displayDevice->getViewport(), &activeCrop)) { + if (!activeCrop.intersect(displayDevice->getViewport(), &activeCrop)) { #else - if(!activeCrop.intersect(hw->getViewport(), &activeCrop)) { + if (!activeCrop.intersect(hw->getViewport(), &activeCrop)) { #endif activeCrop.clear(); } @@ -565,22 +549,20 @@ void Layer::setGeometry( // transform.inverse().transform(transform.transform(Rect)) != Rect // in which case we need to make sure the final rect is clipped to the // display bounds. - if(!activeCrop.intersect(Rect(s.active.w, s.active.h), &activeCrop)) { + if (!activeCrop.intersect(Rect(s.active.w, s.active.h), &activeCrop)) { activeCrop.clear(); } // mark regions outside the crop as transparent activeTransparentRegion.orSelf(Rect(0, 0, s.active.w, activeCrop.top)); - activeTransparentRegion.orSelf(Rect(0, activeCrop.bottom, - s.active.w, s.active.h)); - activeTransparentRegion.orSelf(Rect(0, activeCrop.top, - activeCrop.left, activeCrop.bottom)); - activeTransparentRegion.orSelf(Rect(activeCrop.right, activeCrop.top, - s.active.w, activeCrop.bottom)); + activeTransparentRegion.orSelf(Rect(0, activeCrop.bottom, s.active.w, s.active.h)); + activeTransparentRegion.orSelf(Rect(0, activeCrop.top, activeCrop.left, activeCrop.bottom)); + activeTransparentRegion.orSelf( + Rect(activeCrop.right, activeCrop.top, s.active.w, activeCrop.bottom)); } Rect frame(t.transform(computeBounds(activeTransparentRegion))); if (!s.finalCrop.isEmpty()) { - if(!frame.intersect(s.finalCrop, &frame)) { + if (!frame.intersect(s.finalCrop, &frame)) { frame.clear(); } } @@ -592,10 +574,9 @@ void Layer::setGeometry( Rect transformedFrame = tr.transform(frame); error = hwcLayer->setDisplayFrame(transformedFrame); if (error != HWC2::Error::None) { - ALOGE("[%s] Failed to set display frame [%d, %d, %d, %d]: %s (%d)", - mName.string(), transformedFrame.left, transformedFrame.top, - transformedFrame.right, transformedFrame.bottom, - to_string(error).c_str(), static_cast<int32_t>(error)); + ALOGE("[%s] Failed to set display frame [%d, %d, %d, %d]: %s (%d)", mName.string(), + transformedFrame.left, transformedFrame.top, transformedFrame.right, + transformedFrame.bottom, to_string(error).c_str(), static_cast<int32_t>(error)); } else { hwcInfo.displayFrame = transformedFrame; } @@ -604,23 +585,23 @@ void Layer::setGeometry( error = hwcLayer->setSourceCrop(sourceCrop); if (error != HWC2::Error::None) { ALOGE("[%s] Failed to set source crop [%.3f, %.3f, %.3f, %.3f]: " - "%s (%d)", mName.string(), sourceCrop.left, sourceCrop.top, - sourceCrop.right, sourceCrop.bottom, to_string(error).c_str(), - static_cast<int32_t>(error)); + "%s (%d)", + mName.string(), sourceCrop.left, sourceCrop.top, sourceCrop.right, sourceCrop.bottom, + to_string(error).c_str(), static_cast<int32_t>(error)); } else { hwcInfo.sourceCrop = sourceCrop; } float alpha = static_cast<float>(getAlpha()); error = hwcLayer->setPlaneAlpha(alpha); - ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set plane alpha %.3f: " - "%s (%d)", mName.string(), alpha, to_string(error).c_str(), - static_cast<int32_t>(error)); + ALOGE_IF(error != HWC2::Error::None, + "[%s] Failed to set plane alpha %.3f: " + "%s (%d)", + mName.string(), alpha, to_string(error).c_str(), static_cast<int32_t>(error)); error = hwcLayer->setZOrder(z); - ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set Z %u: %s (%d)", - mName.string(), z, to_string(error).c_str(), - static_cast<int32_t>(error)); + ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set Z %u: %s (%d)", mName.string(), z, + to_string(error).c_str(), static_cast<int32_t>(error)); int type = s.type; int appId = s.appId; @@ -632,8 +613,8 @@ void Layer::setGeometry( } error = hwcLayer->setInfo(type, appId); - ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set info (%d)", - mName.string(), static_cast<int32_t>(error)); + ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set info (%d)", mName.string(), + static_cast<int32_t>(error)); #else if (!frame.intersect(hw->getViewport(), &frame)) { frame.clear(); @@ -641,7 +622,7 @@ void Layer::setGeometry( const Transform& tr(hw->getTransform()); layer.setFrame(tr.transform(frame)); layer.setCrop(computeCrop(hw)); - layer.setPlaneAlpha(static_cast<uint8_t>(std::round(255.0f*getAlpha()))); + layer.setPlaneAlpha(static_cast<uint8_t>(std::round(255.0f * getAlpha()))); #endif /* @@ -660,12 +641,10 @@ void Layer::setGeometry( * the code below applies the primary display's inverse transform to the * buffer */ - uint32_t invTransform = - DisplayDevice::getPrimaryDisplayOrientationTransform(); + uint32_t invTransform = DisplayDevice::getPrimaryDisplayOrientationTransform(); // calculate the inverse transform if (invTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) { - invTransform ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | - NATIVE_WINDOW_TRANSFORM_FLIP_H; + invTransform ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | NATIVE_WINDOW_TRANSFORM_FLIP_H; } /* @@ -686,9 +665,11 @@ void Layer::setGeometry( } else { auto transform = static_cast<HWC2::Transform>(orientation); auto error = hwcLayer->setTransform(transform); - ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set transform %s: " - "%s (%d)", mName.string(), to_string(transform).c_str(), - to_string(error).c_str(), static_cast<int32_t>(error)); + ALOGE_IF(error != HWC2::Error::None, + "[%s] Failed to set transform %s: " + "%s (%d)", + mName.string(), to_string(transform).c_str(), to_string(error).c_str(), + static_cast<int32_t>(error)); } #else if (orientation & Transform::ROT_INVALID) { @@ -722,14 +703,14 @@ void Layer::setPerFrameData(const sp<const DisplayDevice>& displayDevice) { auto error = hwcLayer->setVisibleRegion(visible); if (error != HWC2::Error::None) { ALOGE("[%s] Failed to set visible region: %s (%d)", mName.string(), - to_string(error).c_str(), static_cast<int32_t>(error)); + to_string(error).c_str(), static_cast<int32_t>(error)); visible.dump(LOG_TAG); } error = hwcLayer->setSurfaceDamage(surfaceDamageRegion); if (error != HWC2::Error::None) { ALOGE("[%s] Failed to set surface damage: %s (%d)", mName.string(), - to_string(error).c_str(), static_cast<int32_t>(error)); + to_string(error).c_str(), static_cast<int32_t>(error)); surfaceDamageRegion.dump(LOG_TAG); } @@ -739,16 +720,15 @@ void Layer::setPerFrameData(const sp<const DisplayDevice>& displayDevice) { ALOGV("[%s] Requesting Sideband composition", mName.string()); error = hwcLayer->setSidebandStream(mSidebandStream->handle()); if (error != HWC2::Error::None) { - ALOGE("[%s] Failed to set sideband stream %p: %s (%d)", - mName.string(), mSidebandStream->handle(), - to_string(error).c_str(), static_cast<int32_t>(error)); + ALOGE("[%s] Failed to set sideband stream %p: %s (%d)", mName.string(), + mSidebandStream->handle(), to_string(error).c_str(), static_cast<int32_t>(error)); } return; } // Client layers if (hwcInfo.forceClientComposition || - (mActiveBuffer != nullptr && mActiveBuffer->handle == nullptr)) { + (mActiveBuffer != nullptr && mActiveBuffer->handle == nullptr)) { ALOGV("[%s] Requesting Client composition", mName.string()); setCompositionType(hwcId, HWC2::Composition::Client); return; @@ -759,13 +739,12 @@ void Layer::setPerFrameData(const sp<const DisplayDevice>& displayDevice) { setCompositionType(hwcId, HWC2::Composition::SolidColor); half4 color = getColor(); - error = hwcLayer->setColor({static_cast<uint8_t>(std::round(255.0f*color.r)), - static_cast<uint8_t>(std::round(255.0f * color.g)), - static_cast<uint8_t>(std::round(255.0f * color.b)), - 255}); + error = hwcLayer->setColor({static_cast<uint8_t>(std::round(255.0f * color.r)), + static_cast<uint8_t>(std::round(255.0f * color.g)), + static_cast<uint8_t>(std::round(255.0f * color.b)), 255}); if (error != HWC2::Error::None) { - ALOGE("[%s] Failed to set color: %s (%d)", mName.string(), - to_string(error).c_str(), static_cast<int32_t>(error)); + ALOGE("[%s] Failed to set color: %s (%d)", mName.string(), to_string(error).c_str(), + static_cast<int32_t>(error)); } // Clear out the transform, because it doesn't make sense absent a @@ -773,7 +752,7 @@ void Layer::setPerFrameData(const sp<const DisplayDevice>& displayDevice) { error = hwcLayer->setTransform(HWC2::Transform::None); if (error != HWC2::Error::None) { ALOGE("[%s] Failed to clear transform: %s (%d)", mName.string(), - to_string(error).c_str(), static_cast<int32_t>(error)); + to_string(error).c_str(), static_cast<int32_t>(error)); } return; @@ -791,28 +770,25 @@ void Layer::setPerFrameData(const sp<const DisplayDevice>& displayDevice) { ALOGV("setPerFrameData: dataspace = %d", mCurrentState.dataSpace); error = hwcLayer->setDataspace(mCurrentState.dataSpace); if (error != HWC2::Error::None) { - ALOGE("[%s] Failed to set dataspace %d: %s (%d)", mName.string(), - mCurrentState.dataSpace, to_string(error).c_str(), - static_cast<int32_t>(error)); + ALOGE("[%s] Failed to set dataspace %d: %s (%d)", mName.string(), mCurrentState.dataSpace, + to_string(error).c_str(), static_cast<int32_t>(error)); } uint32_t hwcSlot = 0; sp<GraphicBuffer> hwcBuffer; - hwcInfo.bufferCache.getHwcBuffer(mActiveBufferSlot, mActiveBuffer, - &hwcSlot, &hwcBuffer); + hwcInfo.bufferCache.getHwcBuffer(mActiveBufferSlot, mActiveBuffer, &hwcSlot, &hwcBuffer); auto acquireFence = mSurfaceFlingerConsumer->getCurrentFence(); error = hwcLayer->setBuffer(hwcSlot, hwcBuffer, acquireFence); if (error != HWC2::Error::None) { - ALOGE("[%s] Failed to set buffer %p: %s (%d)", mName.string(), - mActiveBuffer->handle, to_string(error).c_str(), - static_cast<int32_t>(error)); + ALOGE("[%s] Failed to set buffer %p: %s (%d)", mName.string(), mActiveBuffer->handle, + to_string(error).c_str(), static_cast<int32_t>(error)); } } #else void Layer::setPerFrameData(const sp<const DisplayDevice>& hw, - HWComposer::HWCLayerInterface& layer) { + HWComposer::HWCLayerInterface& layer) { // we have to set the visible region on every frame because // we currently free it during onLayerDisplayed(), which is called // after HWComposer::commit() -- every frame. @@ -837,8 +813,7 @@ void Layer::setPerFrameData(const sp<const DisplayDevice>& hw, #ifdef USE_HWC2 void Layer::updateCursorPosition(const sp<const DisplayDevice>& displayDevice) { auto hwcId = displayDevice->getHwcDisplayId(); - if (mHwcLayers.count(hwcId) == 0 || - getCompositionType(hwcId) != HWC2::Composition::Cursor) { + if (mHwcLayers.count(hwcId) == 0 || getCompositionType(hwcId) != HWC2::Composition::Cursor) { return; } @@ -861,22 +836,23 @@ void Layer::updateCursorPosition(const sp<const DisplayDevice>& displayDevice) { auto& displayTransform(displayDevice->getTransform()); auto position = displayTransform.transform(frame); - auto error = mHwcLayers[hwcId].layer->setCursorPosition(position.left, - position.top); - ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set cursor position " - "to (%d, %d): %s (%d)", mName.string(), position.left, - position.top, to_string(error).c_str(), - static_cast<int32_t>(error)); + auto error = mHwcLayers[hwcId].layer->setCursorPosition(position.left, position.top); + ALOGE_IF(error != HWC2::Error::None, + "[%s] Failed to set cursor position " + "to (%d, %d): %s (%d)", + mName.string(), position.left, position.top, to_string(error).c_str(), + static_cast<int32_t>(error)); } #else void Layer::setAcquireFence(const sp<const DisplayDevice>& /* hw */, - HWComposer::HWCLayerInterface& layer) { + HWComposer::HWCLayerInterface& layer) { int fenceFd = -1; // TODO: there is a possible optimization here: we only need to set the // acquire fence the first time a new buffer is acquired on EACH display. - if (layer.getCompositionType() == HWC_OVERLAY || layer.getCompositionType() == HWC_CURSOR_OVERLAY) { + if (layer.getCompositionType() == HWC_OVERLAY || + layer.getCompositionType() == HWC_CURSOR_OVERLAY) { sp<Fence> fence = mSurfaceFlingerConsumer->getCurrentFence(); if (fence->isValid()) { fenceFd = fence->dup(); @@ -888,9 +864,7 @@ void Layer::setAcquireFence(const sp<const DisplayDevice>& /* hw */, layer.setAcquireFenceFd(fenceFd); } -Rect Layer::getPosition( - const sp<const DisplayDevice>& hw) -{ +Rect Layer::getPosition(const sp<const DisplayDevice>& hw) { // this gives us only the "orientation" component of the transform const State& s(getCurrentState()); @@ -928,10 +902,8 @@ void Layer::draw(const RenderArea& renderArea) const { onDraw(renderArea, Region(renderArea.getBounds()), false); } -void Layer::clearWithOpenGL(const RenderArea& renderArea, - float red, float green, float blue, - float alpha) const -{ +void Layer::clearWithOpenGL(const RenderArea& renderArea, float red, float green, float blue, + float alpha) const { RenderEngine& engine(mFlinger->getRenderEngine()); computeGeometry(renderArea, mMesh, false); engine.setupFillWithColor(red, green, blue, alpha); @@ -939,29 +911,29 @@ void Layer::clearWithOpenGL(const RenderArea& renderArea, } void Layer::clearWithOpenGL(const RenderArea& renderArea) const { - clearWithOpenGL(renderArea, 0,0,0,0); + clearWithOpenGL(renderArea, 0, 0, 0, 0); } #ifdef USE_HWC2 -void Layer::setCompositionType(int32_t hwcId, HWC2::Composition type, - bool callIntoHwc) { +void Layer::setCompositionType(int32_t hwcId, HWC2::Composition type, bool callIntoHwc) { if (mHwcLayers.count(hwcId) == 0) { ALOGE("setCompositionType called without a valid HWC layer"); return; } auto& hwcInfo = mHwcLayers[hwcId]; auto& hwcLayer = hwcInfo.layer; - ALOGV("setCompositionType(%" PRIx64 ", %s, %d)", hwcLayer->getId(), - to_string(type).c_str(), static_cast<int>(callIntoHwc)); + ALOGV("setCompositionType(%" PRIx64 ", %s, %d)", hwcLayer->getId(), to_string(type).c_str(), + static_cast<int>(callIntoHwc)); if (hwcInfo.compositionType != type) { ALOGV(" actually setting"); hwcInfo.compositionType = type; if (callIntoHwc) { auto error = hwcLayer->setCompositionType(type); - ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set " - "composition type %s: %s (%d)", mName.string(), - to_string(type).c_str(), to_string(error).c_str(), - static_cast<int32_t>(error)); + ALOGE_IF(error != HWC2::Error::None, + "[%s] Failed to set " + "composition type %s: %s (%d)", + mName.string(), to_string(type).c_str(), to_string(error).c_str(), + static_cast<int32_t>(error)); } } } @@ -1067,13 +1039,12 @@ void Layer::computeGeometry(const RenderArea& renderArea, Mesh& mesh, position[1] = renderAreaTransform.transform(lb); position[2] = renderAreaTransform.transform(rb); position[3] = renderAreaTransform.transform(rt); - for (size_t i=0 ; i<4 ; i++) { + for (size_t i = 0; i < 4; i++) { position[i].y = height - position[i].y; } } -bool Layer::isSecure() const -{ +bool Layer::isSecure() const { const Layer::State& s(mDrawingState); return (s.flags & layer_state_t::eLayerSecure); } @@ -1088,8 +1059,7 @@ void Layer::setCoveredRegion(const Region& coveredRegion) { this->coveredRegion = coveredRegion; } -void Layer::setVisibleNonTransparentRegion(const Region& - setVisibleNonTransparentRegion) { +void Layer::setVisibleNonTransparentRegion(const Region& setVisibleNonTransparentRegion) { // always called from main thread this->visibleNonTransparentRegion = setVisibleNonTransparentRegion; } @@ -1114,8 +1084,7 @@ void Layer::pushPendingState() { // to be applied as per normal (no synchronization). mCurrentState.barrierLayer = nullptr; } else { - auto syncPoint = std::make_shared<SyncPoint>( - mCurrentState.frameNumber); + auto syncPoint = std::make_shared<SyncPoint>(mCurrentState.frameNumber); if (barrierLayer->addSyncPoint(syncPoint)) { mRemoteSyncPoints.push_back(std::move(syncPoint)); } else { @@ -1136,8 +1105,8 @@ void Layer::pushPendingState() { void Layer::popPendingState(State* stateToCommit) { auto oldFlags = stateToCommit->flags; *stateToCommit = mPendingStates[0]; - stateToCommit->flags = (oldFlags & ~stateToCommit->mask) | - (stateToCommit->flags & stateToCommit->mask); + stateToCommit->flags = + (oldFlags & ~stateToCommit->mask) | (stateToCommit->flags & stateToCommit->mask); mPendingStates.removeAt(0); ATRACE_INT(mTransactionName.string(), mPendingStates.size()); @@ -1157,10 +1126,8 @@ bool Layer::applyPendingStates(State* stateToCommit) { continue; } - if (mRemoteSyncPoints.front()->getFrameNumber() != - mPendingStates[0].frameNumber) { - ALOGE("[%s] Unexpected sync point frame number found", - mName.string()); + if (mRemoteSyncPoints.front()->getFrameNumber() != mPendingStates[0].frameNumber) { + ALOGE("[%s] Unexpected sync point frame number found", mName.string()); // Signal our end of the sync point and then dispose of it mRemoteSyncPoints.front()->setTransactionApplied(); @@ -1207,40 +1174,25 @@ uint32_t Layer::doTransaction(uint32_t flags) { const Layer::State& s(getDrawingState()); - const bool sizeChanged = (c.requested.w != s.requested.w) || - (c.requested.h != s.requested.h); + const bool sizeChanged = (c.requested.w != s.requested.w) || (c.requested.h != s.requested.h); if (mSurfaceFlingerConsumer && sizeChanged) { // the size changed, we need to ask our client to request a new buffer ALOGD_IF(DEBUG_RESIZE, - "doTransaction: geometry (layer=%p '%s'), tr=%02x, scalingMode=%d\n" - " current={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n" - " requested={ wh={%4u,%4u} }}\n" - " drawing={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n" - " requested={ wh={%4u,%4u} }}\n", - this, getName().string(), mCurrentTransform, - getEffectiveScalingMode(), - c.active.w, c.active.h, - c.crop.left, - c.crop.top, - c.crop.right, - c.crop.bottom, - c.crop.getWidth(), - c.crop.getHeight(), - c.requested.w, c.requested.h, - s.active.w, s.active.h, - s.crop.left, - s.crop.top, - s.crop.right, - s.crop.bottom, - s.crop.getWidth(), - s.crop.getHeight(), - s.requested.w, s.requested.h); + "doTransaction: geometry (layer=%p '%s'), tr=%02x, scalingMode=%d\n" + " current={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n" + " requested={ wh={%4u,%4u} }}\n" + " drawing={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n" + " requested={ wh={%4u,%4u} }}\n", + this, getName().string(), mCurrentTransform, getEffectiveScalingMode(), c.active.w, + c.active.h, c.crop.left, c.crop.top, c.crop.right, c.crop.bottom, + c.crop.getWidth(), c.crop.getHeight(), c.requested.w, c.requested.h, s.active.w, + s.active.h, s.crop.left, s.crop.top, s.crop.right, s.crop.bottom, + s.crop.getWidth(), s.crop.getHeight(), s.requested.w, s.requested.h); // record the new size, form this point on, when the client request // a buffer, it'll get the new size. - mSurfaceFlingerConsumer->setDefaultBufferSize( - c.requested.w, c.requested.h); + mSurfaceFlingerConsumer->setDefaultBufferSize(c.requested.w, c.requested.h); } // Don't let Layer::doTransaction update the drawing state @@ -1261,8 +1213,8 @@ uint32_t Layer::doTransaction(uint32_t flags) { // resizePending state is to avoid applying the state of the new buffer // to the old buffer. However in the state where we don't have an old buffer // there is no such concern but we may still be being used as a parent layer. - const bool resizePending = ((c.requested.w != c.active.w) || - (c.requested.h != c.active.h)) && (mActiveBuffer != nullptr); + const bool resizePending = ((c.requested.w != c.active.w) || (c.requested.h != c.active.h)) && + (mActiveBuffer != nullptr); if (!isFixedSize()) { if (resizePending && mSidebandStream == NULL) { flags |= eDontUpdateGeometryState; @@ -1311,8 +1263,7 @@ uint32_t Layer::doTransaction(uint32_t flags) { // we may use linear filtering, if the matrix scales us const uint8_t type = c.active.transform.getType(); - mNeedsFiltering = (!c.active.transform.preserveRects() || - (type >= Transform::SCALE)); + mNeedsFiltering = (!c.active.transform.preserveRects() || (type >= Transform::SCALE)); } // If the layer is hidden, signal and clear out all local sync points so @@ -1375,8 +1326,7 @@ bool Layer::setChildLayer(const sp<Layer>& childLayer, int32_t z) { } bool Layer::setLayer(int32_t z) { - if (mCurrentState.z == z) - return false; + if (mCurrentState.z == z) return false; mCurrentState.sequence++; mCurrentState.z = z; mCurrentState.modified = true; @@ -1434,8 +1384,7 @@ bool Layer::setRelativeLayer(const sp<IBinder>& relativeToHandle, int32_t z) { } bool Layer::setSize(uint32_t w, uint32_t h) { - if (mCurrentState.requested.w == w && mCurrentState.requested.h == h) - return false; + if (mCurrentState.requested.w == w && mCurrentState.requested.h == h) return false; mCurrentState.requested.w = w; mCurrentState.requested.h = h; mCurrentState.modified = true; @@ -1443,8 +1392,7 @@ bool Layer::setSize(uint32_t w, uint32_t h) { return true; } bool Layer::setAlpha(float alpha) { - if (mCurrentState.color.a == alpha) - return false; + if (mCurrentState.color.a == alpha) return false; mCurrentState.sequence++; mCurrentState.color.a = alpha; mCurrentState.modified = true; @@ -1453,8 +1401,8 @@ bool Layer::setAlpha(float alpha) { } bool Layer::setColor(const half3& color) { - if (color.r == mCurrentState.color.r && color.g == mCurrentState.color.g - && color.b == mCurrentState.color.b) + if (color.r == mCurrentState.color.r && color.g == mCurrentState.color.g && + color.b == mCurrentState.color.b) return false; mCurrentState.sequence++; @@ -1468,8 +1416,7 @@ bool Layer::setColor(const half3& color) { bool Layer::setMatrix(const layer_state_t::matrix22_t& matrix) { mCurrentState.sequence++; - mCurrentState.requested.transform.set( - matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy); + mCurrentState.requested.transform.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy); mCurrentState.modified = true; setTransactionFlags(eTransactionNeeded); return true; @@ -1482,8 +1429,7 @@ bool Layer::setTransparentRegionHint(const Region& transparent) { } bool Layer::setFlags(uint8_t flags, uint8_t mask) { const uint32_t newFlags = (mCurrentState.flags & ~mask) | (flags & mask); - if (mCurrentState.flags == newFlags) - return false; + if (mCurrentState.flags == newFlags) return false; mCurrentState.sequence++; mCurrentState.flags = newFlags; mCurrentState.mask = mask; @@ -1493,8 +1439,7 @@ bool Layer::setFlags(uint8_t flags, uint8_t mask) { } bool Layer::setCrop(const Rect& crop, bool immediate) { - if (mCurrentState.requestedCrop == crop) - return false; + if (mCurrentState.requestedCrop == crop) return false; mCurrentState.sequence++; mCurrentState.requestedCrop = crop; if (immediate && !mFreezeGeometryUpdates) { @@ -1508,8 +1453,7 @@ bool Layer::setCrop(const Rect& crop, bool immediate) { } bool Layer::setFinalCrop(const Rect& crop, bool immediate) { - if (mCurrentState.requestedFinalCrop == crop) - return false; + if (mCurrentState.requestedFinalCrop == crop) return false; mCurrentState.sequence++; mCurrentState.requestedFinalCrop = crop; if (immediate && !mFreezeGeometryUpdates) { @@ -1523,23 +1467,21 @@ bool Layer::setFinalCrop(const Rect& crop, bool immediate) { } bool Layer::setOverrideScalingMode(int32_t scalingMode) { - if (scalingMode == mOverrideScalingMode) - return false; + if (scalingMode == mOverrideScalingMode) return false; mOverrideScalingMode = scalingMode; setTransactionFlags(eTransactionNeeded); return true; } void Layer::setInfo(uint32_t type, uint32_t appId) { - mCurrentState.appId = appId; - mCurrentState.type = type; - mCurrentState.modified = true; - setTransactionFlags(eTransactionNeeded); + mCurrentState.appId = appId; + mCurrentState.type = type; + mCurrentState.modified = true; + setTransactionFlags(eTransactionNeeded); } bool Layer::setLayerStack(uint32_t layerStack) { - if (mCurrentState.layerStack == layerStack) - return false; + if (mCurrentState.layerStack == layerStack) return false; mCurrentState.sequence++; mCurrentState.layerStack = layerStack; mCurrentState.modified = true; @@ -1548,8 +1490,7 @@ bool Layer::setLayerStack(uint32_t layerStack) { } bool Layer::setDataSpace(android_dataspace dataSpace) { - if (mCurrentState.dataSpace == dataSpace) - return false; + if (mCurrentState.dataSpace == dataSpace) return false; mCurrentState.sequence++; mCurrentState.dataSpace = dataSpace; mCurrentState.modified = true; @@ -1569,8 +1510,7 @@ uint32_t Layer::getLayerStack() const { return p->getLayerStack(); } -void Layer::deferTransactionUntil(const sp<Layer>& barrierLayer, - uint64_t frameNumber) { +void Layer::deferTransactionUntil(const sp<Layer>& barrierLayer, uint64_t frameNumber) { mCurrentState.barrierLayer = barrierLayer; mCurrentState.frameNumber = frameNumber; // We don't set eTransactionNeeded, because just receiving a deferral @@ -1582,8 +1522,7 @@ void Layer::deferTransactionUntil(const sp<Layer>& barrierLayer, mCurrentState.modified = false; } -void Layer::deferTransactionUntil(const sp<IBinder>& barrierHandle, - uint64_t frameNumber) { +void Layer::deferTransactionUntil(const sp<IBinder>& barrierHandle, uint64_t frameNumber) { sp<Handle> handle = static_cast<Handle*>(barrierHandle.get()); deferTransactionUntil(handle->owner.promote(), frameNumber); } @@ -1614,40 +1553,38 @@ bool Layer::shouldPresentNow(const DispSync& dispSync) const { return false; } auto timestamp = mQueueItems[0].mTimestamp; - nsecs_t expectedPresent = - mSurfaceFlingerConsumer->computeExpectedPresent(dispSync); + nsecs_t expectedPresent = mSurfaceFlingerConsumer->computeExpectedPresent(dispSync); // Ignore timestamps more than a second in the future bool isPlausible = timestamp < (expectedPresent + s2ns(1)); - ALOGW_IF(!isPlausible, "[%s] Timestamp %" PRId64 " seems implausible " - "relative to expectedPresent %" PRId64, mName.string(), timestamp, - expectedPresent); + ALOGW_IF(!isPlausible, + "[%s] Timestamp %" PRId64 " seems implausible " + "relative to expectedPresent %" PRId64, + mName.string(), timestamp, expectedPresent); bool isDue = timestamp < expectedPresent; return isDue || !isPlausible; } bool Layer::onPostComposition(const std::shared_ptr<FenceTime>& glDoneFence, - const std::shared_ptr<FenceTime>& presentFence, - const CompositorTiming& compositorTiming) { + const std::shared_ptr<FenceTime>& presentFence, + const CompositorTiming& compositorTiming) { // mFrameLatencyNeeded is true when a new frame was latched for the // composition. - if (!mFrameLatencyNeeded) - return false; + if (!mFrameLatencyNeeded) return false; // Update mFrameEventHistory. { Mutex::Autolock lock(mFrameEventHistoryMutex); - mFrameEventHistory.addPostComposition(mCurrentFrameNumber, - glDoneFence, presentFence, compositorTiming); + mFrameEventHistory.addPostComposition(mCurrentFrameNumber, glDoneFence, presentFence, + compositorTiming); } // Update mFrameTracker. nsecs_t desiredPresentTime = mSurfaceFlingerConsumer->getTimestamp(); mFrameTracker.setDesiredPresentTime(desiredPresentTime); - std::shared_ptr<FenceTime> frameReadyFence = - mSurfaceFlingerConsumer->getCurrentFenceTime(); + std::shared_ptr<FenceTime> frameReadyFence = mSurfaceFlingerConsumer->getCurrentFenceTime(); if (frameReadyFence->isValid()) { mFrameTracker.setFrameReadyFence(std::move(frameReadyFence)); } else { @@ -1657,14 +1594,12 @@ bool Layer::onPostComposition(const std::shared_ptr<FenceTime>& glDoneFence, } if (presentFence->isValid()) { - mFrameTracker.setActualPresentFence( - std::shared_ptr<FenceTime>(presentFence)); + mFrameTracker.setActualPresentFence(std::shared_ptr<FenceTime>(presentFence)); } else { // The HWC doesn't support present fences, so use the refresh // timestamp instead. mFrameTracker.setActualPresentTime( - mFlinger->getHwComposer().getRefreshTimestamp( - HWC_DISPLAY_PRIMARY)); + mFlinger->getHwComposer().getRefreshTimestamp(HWC_DISPLAY_PRIMARY)); } mFrameTracker.advanceFrame(); @@ -1681,8 +1616,7 @@ bool Layer::isHiddenByPolicy() const { return s.flags & layer_state_t::eLayerHidden; } -uint32_t Layer::getEffectiveUsage(uint32_t usage) const -{ +uint32_t Layer::getEffectiveUsage(uint32_t usage) const { // TODO: should we do something special if mSecure is set? if (mProtectedByApp) { // need a hardware-protected path to external video sink @@ -1796,14 +1730,11 @@ void Layer::miniDump(String8& result, int32_t hwcId) const { const Layer::State& layerState(getDrawingState()); const HWCInfo& hwcInfo = mHwcLayers.at(hwcId); result.appendFormat(" %10d | ", layerState.z); - result.appendFormat("%10s | ", - to_string(getCompositionType(hwcId)).c_str()); + result.appendFormat("%10s | ", to_string(getCompositionType(hwcId)).c_str()); const Rect& frame = hwcInfo.displayFrame; - result.appendFormat("%4d %4d %4d %4d | ", frame.left, frame.top, - frame.right, frame.bottom); + result.appendFormat("%4d %4d %4d %4d | ", frame.left, frame.top, frame.right, frame.bottom); const FloatRect& crop = hwcInfo.sourceCrop; - result.appendFormat("%6.1f %6.1f %6.1f %6.1f\n", crop.left, crop.top, - crop.right, crop.bottom); + result.appendFormat("%6.1f %6.1f %6.1f %6.1f\n", crop.left, crop.top, crop.right, crop.bottom); result.append("- - - - - - - - - - - - - - - - - - - - "); result.append("- - - - - - - - - - - - - - - - - - - -\n"); @@ -1827,8 +1758,7 @@ void Layer::getFrameStats(FrameStats* outStats) const { } void Layer::dumpFrameEvents(String8& result) { - result.appendFormat("- Layer %s (%s, %p)\n", - getName().string(), getTypeId(), this); + result.appendFormat("- Layer %s (%s, %p)\n", getName().string(), getTypeId(), this); Mutex::Autolock lock(mFrameEventHistoryMutex); mFrameEventHistory.checkFencesForCompletion(); mFrameEventHistory.dump(result); @@ -1840,7 +1770,7 @@ void Layer::onDisconnect() { } void Layer::addAndGetFrameTimestamps(const NewFrameEventsEntry* newTimestamps, - FrameEventHistoryDelta *outDelta) { + FrameEventHistoryDelta* outDelta) { Mutex::Autolock lock(mFrameEventHistoryMutex); if (newTimestamps) { // If there are any unsignaled fences in the aquire timeline at this @@ -1858,18 +1788,14 @@ void Layer::addAndGetFrameTimestamps(const NewFrameEventsEntry* newTimestamps, } } -std::vector<OccupancyTracker::Segment> Layer::getOccupancyHistory( - bool forceFlush) { +std::vector<OccupancyTracker::Segment> Layer::getOccupancyHistory(bool forceFlush) { std::vector<OccupancyTracker::Segment> history; - if (!mSurfaceFlingerConsumer) - return {}; + if (!mSurfaceFlingerConsumer) return {}; - status_t result = mSurfaceFlingerConsumer->getOccupancyHistory(forceFlush, - &history); + status_t result = mSurfaceFlingerConsumer->getOccupancyHistory(forceFlush, &history); if (result != NO_ERROR) { - ALOGW("[%s] Failed to obtain occupancy history (%d)", mName.string(), - result); + ALOGW("[%s] Failed to obtain occupancy history (%d)", mName.string(), result); return {}; } return history; @@ -1990,8 +1916,8 @@ int32_t Layer::getZ() const { return mDrawingState.z; } -__attribute__((no_sanitize("unsigned-integer-overflow"))) -LayerVector Layer::makeTraversalList(LayerVector::StateSet stateSet) { +__attribute__((no_sanitize("unsigned-integer-overflow"))) LayerVector Layer::makeTraversalList( + LayerVector::StateSet stateSet) { LOG_ALWAYS_FATAL_IF(stateSet == LayerVector::StateSet::Invalid, "makeTraversalList received invalid stateSet"); const bool useDrawing = stateSet == LayerVector::StateSet::Drawing; @@ -2046,7 +1972,7 @@ void Layer::traverseInReverseZOrder(LayerVector::StateSet stateSet, LayerVector list = makeTraversalList(stateSet); int32_t i = 0; - for (i = list.size()-1; i>=0; i--) { + for (i = list.size() - 1; i >= 0; i--) { const auto& relative = list[i]; if (relative->getZ() < 0) { break; @@ -2054,7 +1980,7 @@ void Layer::traverseInReverseZOrder(LayerVector::StateSet stateSet, relative->traverseInReverseZOrder(stateSet, visitor); } visitor(this); - for (; i>=0; i--) { + for (; i >= 0; i--) { const auto& relative = list[i]; relative->traverseInReverseZOrder(stateSet, visitor); } @@ -2104,10 +2030,8 @@ Transform Layer::getTransform() const { bufferHeight = p->mActiveBuffer->getWidth(); bufferWidth = p->mActiveBuffer->getHeight(); } - float sx = p->getDrawingState().active.w / - static_cast<float>(bufferWidth); - float sy = p->getDrawingState().active.h / - static_cast<float>(bufferHeight); + float sx = p->getDrawingState().active.w / static_cast<float>(bufferWidth); + float sy = p->getDrawingState().active.h / static_cast<float>(bufferHeight); Transform extraParentScaling; extraParentScaling.set(sx, 0, 0, sy); t = t * extraParentScaling; diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h index ee3bb7ef3f..db94a31c5e 100644 --- a/services/surfaceflinger/Layer.h +++ b/services/surfaceflinger/Layer.h @@ -37,20 +37,20 @@ #include <list> -#include "FrameTracker.h" #include "Client.h" +#include "FrameTracker.h" #include "LayerVector.h" #include "MonitoredProducer.h" #include "SurfaceFlinger.h" #include "SurfaceFlingerConsumer.h" #include "Transform.h" +#include <layerproto/LayerProtoHeader.h> #include "DisplayHardware/HWComposer.h" #include "DisplayHardware/HWComposerBufferCache.h" +#include "RenderArea.h" #include "RenderEngine/Mesh.h" #include "RenderEngine/Texture.h" -#include <layerproto/LayerProtoHeader.h> -#include "RenderArea.h" #include <math/vec4.h> @@ -69,8 +69,7 @@ class LayerDebugInfo; // --------------------------------------------------------------------------- -class Layer : public virtual RefBase -{ +class Layer : public virtual RefBase { static int32_t sSequence; public: @@ -96,14 +95,11 @@ public: uint32_t h; Transform transform; - inline bool operator ==(const Geometry& rhs) const { - return (w == rhs.w && h == rhs.h) && - (transform.tx() == rhs.transform.tx()) && + inline bool operator==(const Geometry& rhs) const { + return (w == rhs.w && h == rhs.h) && (transform.tx() == rhs.transform.tx()) && (transform.ty() == rhs.transform.ty()); } - inline bool operator !=(const Geometry& rhs) const { - return !operator ==(rhs); - } + inline bool operator!=(const Geometry& rhs) const { return !operator==(rhs); } }; struct State { @@ -156,8 +152,8 @@ public: half4 color; }; - Layer(SurfaceFlinger* flinger, const sp<Client>& client, - const String8& name, uint32_t w, uint32_t h, uint32_t flags); + Layer(SurfaceFlinger* flinger, const sp<Client>& client, const String8& name, uint32_t w, + uint32_t h, uint32_t flags); virtual ~Layer(); void setPrimaryDisplayOnly() { mPrimaryDisplayOnly = true; } @@ -287,7 +283,8 @@ public: */ virtual bool isFixedSize() const = 0; - void writeToProto(LayerProto* layerInfo, LayerVector::StateSet stateSet = LayerVector::StateSet::Drawing); + void writeToProto(LayerProto* layerInfo, + LayerVector::StateSet stateSet = LayerVector::StateSet::Drawing); protected: /* @@ -310,8 +307,7 @@ public: bool getClearClientTarget(int32_t hwcId) const; void updateCursorPosition(const sp<const DisplayDevice>& hw); #else - void setGeometry(const sp<const DisplayDevice>& hw, - HWComposer::HWCLayerInterface& layer); + void setGeometry(const sp<const DisplayDevice>& hw, HWComposer::HWCLayerInterface& layer); void setPerFrameData(const sp<const DisplayDevice>& hw, HWComposer::HWCLayerInterface& layer); void setAcquireFence(const sp<const DisplayDevice>& hw, HWComposer::HWCLayerInterface& layer); @@ -324,8 +320,7 @@ public: #ifdef USE_HWC2 void onLayerDisplayed(const sp<Fence>& releaseFence); #else - void onLayerDisplayed(const sp<const DisplayDevice>& hw, - HWComposer::HWCLayerInterface* layer); + void onLayerDisplayed(const sp<const DisplayDevice>& hw, HWComposer::HWCLayerInterface* layer); #endif bool shouldPresentNow(const DispSync& dispSync) const; @@ -341,8 +336,8 @@ public: * returns true if the layer latched a new buffer this frame. */ bool onPostComposition(const std::shared_ptr<FenceTime>& glDoneFence, - const std::shared_ptr<FenceTime>& presentFence, - const CompositorTiming& compositorTiming); + const std::shared_ptr<FenceTime>& presentFence, + const CompositorTiming& compositorTiming); #ifdef USE_HWC2 // If a buffer was replaced this frame, release the former buffer @@ -380,8 +375,7 @@ public: * setVisibleNonTransparentRegion - called when the visible and * non-transparent region changes. */ - void setVisibleNonTransparentRegion(const Region& - visibleNonTransparentRegion); + void setVisibleNonTransparentRegion(const Region& visibleNonTransparentRegion); /* * latchBuffer - called each time the screen is redrawn and returns whether @@ -405,7 +399,6 @@ public: */ void onRemoved(); - // Updates the transform hint in our SurfaceFlingerConsumer to match // the current orientation of the display device. void updateTransformHint(const sp<const DisplayDevice>& hw) const; @@ -419,8 +412,9 @@ public: /* * Returns if a frame is queued. */ - bool hasQueuedFrame() const { return mQueuedFrames > 0 || - mSidebandStreamChanged || mAutoRefresh; } + bool hasQueuedFrame() const { + return mQueuedFrames > 0 || mSidebandStreamChanged || mAutoRefresh; + } int32_t getQueuedFrameCount() const { return mQueuedFrames; } @@ -431,9 +425,7 @@ public: void destroyHwcLayer(int32_t hwcId); void destroyAllHwcLayers(); - bool hasHwcLayer(int32_t hwcId) { - return mHwcLayers.count(hwcId) > 0; - } + bool hasHwcLayer(int32_t hwcId) { return mHwcLayers.count(hwcId) > 0; } HWC2::Layer* getHwcLayer(int32_t hwcId) { if (mHwcLayers.count(hwcId) == 0) { @@ -452,9 +444,9 @@ public: // only for debugging inline const sp<GraphicBuffer>& getActiveBuffer() const { return mActiveBuffer; } - inline const State& getDrawingState() const { return mDrawingState; } - inline const State& getCurrentState() const { return mCurrentState; } - inline State& getCurrentState() { return mCurrentState; } + inline const State& getDrawingState() const { return mDrawingState; } + inline const State& getCurrentState() const { return mCurrentState; } + inline State& getCurrentState() { return mCurrentState; } LayerDebugInfo getLayerDebugInfo() const; @@ -473,7 +465,7 @@ public: void onDisconnect(); void addAndGetFrameTimestamps(const NewFrameEventsEntry* newEntry, - FrameEventHistoryDelta* outDelta); + FrameEventHistoryDelta* outDelta); bool getTransformToDisplayInverse() const; @@ -506,6 +498,7 @@ public: // SurfaceFlinger to complete a transaction. void commitChildList(); int32_t getZ() const; + protected: // constant sp<SurfaceFlinger> mFlinger; @@ -516,23 +509,20 @@ protected: class LayerCleaner { sp<SurfaceFlinger> mFlinger; wp<Layer> mLayer; + protected: ~LayerCleaner() { // destroy client resources mFlinger->onLayerDestroyed(mLayer); } + public: - LayerCleaner(const sp<SurfaceFlinger>& flinger, - const sp<Layer>& layer) - : mFlinger(flinger), mLayer(layer) { - } + LayerCleaner(const sp<SurfaceFlinger>& flinger, const sp<Layer>& layer) + : mFlinger(flinger), mLayer(layer) {} }; - virtual void onFirstRef(); - - friend class SurfaceInterceptor; void commitTransaction(const State& stateToCommit); @@ -546,8 +536,8 @@ protected: Rect computeInitialCrop(const sp<const DisplayDevice>& hw) const; // drawing - void clearWithOpenGL(const RenderArea& renderArea, - float r, float g, float b, float alpha) const; + void clearWithOpenGL(const RenderArea& renderArea, float r, float g, float b, + float alpha) const; void setParent(const sp<Layer>& layer); @@ -556,31 +546,20 @@ protected: void removeZOrderRelative(const wp<Layer>& relative); protected: - class SyncPoint - { + class SyncPoint { public: - explicit SyncPoint(uint64_t frameNumber) : mFrameNumber(frameNumber), - mFrameIsAvailable(false), mTransactionIsApplied(false) {} + explicit SyncPoint(uint64_t frameNumber) + : mFrameNumber(frameNumber), mFrameIsAvailable(false), mTransactionIsApplied(false) {} - uint64_t getFrameNumber() const { - return mFrameNumber; - } + uint64_t getFrameNumber() const { return mFrameNumber; } - bool frameIsAvailable() const { - return mFrameIsAvailable; - } + bool frameIsAvailable() const { return mFrameIsAvailable; } - void setFrameAvailable() { - mFrameIsAvailable = true; - } + void setFrameAvailable() { mFrameIsAvailable = true; } - bool transactionIsApplied() const { - return mTransactionIsApplied; - } + bool transactionIsApplied() const { return mTransactionIsApplied; } - void setTransactionApplied() { - mTransactionIsApplied = true; - } + void setTransactionApplied() { mTransactionIsApplied = true; } private: const uint64_t mFrameNumber; @@ -611,6 +590,7 @@ protected: // Client) or mOverrideScalingMode mode (originating from // the Surface Controller) if set. virtual uint32_t getEffectiveScalingMode() const = 0; + public: /* * The layer handle is just a BBinder object passed to the client @@ -621,11 +601,11 @@ public: * this layer when the handle is destroyed. */ class Handle : public BBinder, public LayerCleaner { - public: - Handle(const sp<SurfaceFlinger>& flinger, const sp<Layer>& layer) - : LayerCleaner(flinger, layer), owner(layer) {} + public: + Handle(const sp<SurfaceFlinger>& flinger, const sp<Layer>& layer) + : LayerCleaner(flinger, layer), owner(layer) {} - wp<Layer> owner; + wp<Layer> owner; }; sp<IBinder> getHandle(); @@ -633,15 +613,15 @@ public: virtual void notifyAvailableFrames() = 0; virtual PixelFormat getPixelFormat() const = 0; bool getPremultipledAlpha() const; -protected: +protected: // ----------------------------------------------------------------------- // constants sp<SurfaceFlingerConsumer> mSurfaceFlingerConsumer; bool mPremultipliedAlpha; String8 mName; - String8 mTransactionName; // A cached version of "TX - " + mName for systraces + String8 mTransactionName; // A cached version of "TX - " + mName for systraces bool mPrimaryDisplayOnly = false; @@ -656,7 +636,7 @@ protected: // thread-safe volatile int32_t mQueuedFrames; - volatile int32_t mSidebandStreamChanged; // used like an atomic boolean + volatile int32_t mSidebandStreamChanged; // used like an atomic boolean // Timestamp history for UIAutomation. Thread safe. FrameTracker mFrameTracker; @@ -686,16 +666,15 @@ protected: // The mesh used to draw the layer in GLES composition mode mutable Mesh mMesh; - #ifdef USE_HWC2 // HWC items, accessed from the main thread struct HWCInfo { HWCInfo() - : hwc(nullptr), - layer(nullptr), - forceClientComposition(false), - compositionType(HWC2::Composition::Invalid), - clearClientTarget(false) {} + : hwc(nullptr), + layer(nullptr), + forceClientComposition(false), + compositionType(HWC2::Composition::Invalid), + clearClientTarget(false) {} HWComposer* hwc; HWC2::Layer* layer; |