2009-03-04 03:31:44 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2014-12-06 02:28:32 +00:00
|
|
|
//#define LOG_NDEBUG 0
|
2012-02-24 03:27:23 +00:00
|
|
|
#define ATRACE_TAG ATRACE_TAG_GRAPHICS
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
#include <stdint.h>
|
2012-07-24 06:11:29 +00:00
|
|
|
#include <sys/types.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <math.h>
|
2012-08-31 17:53:36 +00:00
|
|
|
#include <dlfcn.h>
|
2014-03-07 20:44:02 +00:00
|
|
|
#include <inttypes.h>
|
2014-07-13 19:47:02 +00:00
|
|
|
#include <stdatomic.h>
|
2012-07-24 06:11:29 +00:00
|
|
|
|
|
|
|
#include <EGL/egl.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
#include <cutils/log.h>
|
2015-09-20 11:20:21 +00:00
|
|
|
#include <cutils/iosched_policy.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
#include <cutils/properties.h>
|
|
|
|
|
2009-05-20 02:08:10 +00:00
|
|
|
#include <binder/IPCThreadState.h>
|
|
|
|
#include <binder/IServiceManager.h>
|
2009-07-03 01:11:53 +00:00
|
|
|
#include <binder/MemoryHeapBase.h>
|
2011-06-27 23:05:52 +00:00
|
|
|
#include <binder/PermissionCache.h>
|
2009-07-03 01:11:53 +00:00
|
|
|
|
2012-07-26 01:56:13 +00:00
|
|
|
#include <ui/DisplayInfo.h>
|
2014-09-11 21:58:45 +00:00
|
|
|
#include <ui/DisplayStatInfo.h>
|
2012-07-26 01:56:13 +00:00
|
|
|
|
2012-07-24 06:11:29 +00:00
|
|
|
#include <gui/BitTube.h>
|
2012-08-03 03:11:05 +00:00
|
|
|
#include <gui/BufferQueue.h>
|
2012-09-25 02:07:20 +00:00
|
|
|
#include <gui/GuiConfig.h>
|
2012-08-03 03:11:05 +00:00
|
|
|
#include <gui/IDisplayEventConnection.h>
|
2013-02-15 01:11:02 +00:00
|
|
|
#include <gui/Surface.h>
|
2012-11-30 07:26:29 +00:00
|
|
|
#include <gui/GraphicBufferAlloc.h>
|
2012-07-24 06:11:29 +00:00
|
|
|
|
|
|
|
#include <ui/GraphicBufferAllocator.h>
|
|
|
|
#include <ui/PixelFormat.h>
|
2012-09-25 02:07:20 +00:00
|
|
|
#include <ui/UiConfig.h>
|
2011-11-18 01:49:17 +00:00
|
|
|
|
2012-09-13 21:09:01 +00:00
|
|
|
#include <utils/misc.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
#include <utils/String8.h>
|
|
|
|
#include <utils/String16.h>
|
|
|
|
#include <utils/StopWatch.h>
|
2012-02-24 03:27:23 +00:00
|
|
|
#include <utils/Trace.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2012-07-24 06:11:29 +00:00
|
|
|
#include <private/android_filesystem_config.h>
|
2013-03-29 00:44:13 +00:00
|
|
|
#include <private/gui/SyncFeatures.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2013-04-22 15:52:16 +00:00
|
|
|
#include "Client.h"
|
2009-03-04 03:31:44 +00:00
|
|
|
#include "clz.h"
|
2013-04-22 15:52:16 +00:00
|
|
|
#include "Colorizer.h"
|
2012-02-26 02:48:35 +00:00
|
|
|
#include "DdmConnection.h"
|
2012-08-01 06:09:07 +00:00
|
|
|
#include "DisplayDevice.h"
|
2013-07-30 22:10:32 +00:00
|
|
|
#include "DispSync.h"
|
2013-10-14 19:22:52 +00:00
|
|
|
#include "EventControlThread.h"
|
2011-11-18 01:49:17 +00:00
|
|
|
#include "EventThread.h"
|
2009-03-04 03:31:44 +00:00
|
|
|
#include "Layer.h"
|
|
|
|
#include "LayerDim.h"
|
2014-12-06 02:28:32 +00:00
|
|
|
#include "LayerBlur.h"
|
2009-03-04 03:31:44 +00:00
|
|
|
#include "SurfaceFlinger.h"
|
|
|
|
|
2012-07-12 21:25:33 +00:00
|
|
|
#include "DisplayHardware/FramebufferSurface.h"
|
2010-08-11 00:14:02 +00:00
|
|
|
#include "DisplayHardware/HWComposer.h"
|
2013-03-14 21:29:29 +00:00
|
|
|
#include "DisplayHardware/VirtualDisplaySurface.h"
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2013-09-02 04:36:12 +00:00
|
|
|
#include "Effects/Daltonizer.h"
|
|
|
|
|
2013-06-07 22:35:48 +00:00
|
|
|
#include "RenderEngine/RenderEngine.h"
|
2013-09-02 04:36:12 +00:00
|
|
|
#include <cutils/compiler.h>
|
2015-06-23 19:55:15 +00:00
|
|
|
#include "DisplayUtils.h"
|
2013-06-07 22:35:48 +00:00
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
#define DISPLAY_COUNT 1
|
|
|
|
|
2013-07-03 19:34:01 +00:00
|
|
|
/*
|
|
|
|
* DEBUG_SCREENSHOTS: set to true to check that screenshots are not all
|
|
|
|
* black pixels.
|
|
|
|
*/
|
|
|
|
#define DEBUG_SCREENSHOTS false
|
|
|
|
|
2013-03-29 00:44:13 +00:00
|
|
|
EGLAPI const char* eglQueryStringImplementationANDROID(EGLDisplay dpy, EGLint name);
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
namespace android {
|
2013-07-30 22:10:32 +00:00
|
|
|
|
|
|
|
// This is the phase offset in nanoseconds of the software vsync event
|
|
|
|
// relative to the vsync event reported by HWComposer. The software vsync
|
|
|
|
// event is when SurfaceFlinger and Choreographer-based applications run each
|
|
|
|
// frame.
|
|
|
|
//
|
|
|
|
// This phase offset allows adjustment of the minimum latency from application
|
|
|
|
// wake-up (by Choregographer) time to the time at which the resulting window
|
|
|
|
// image is displayed. This value may be either positive (after the HW vsync)
|
|
|
|
// or negative (before the HW vsync). Setting it to 0 will result in a
|
|
|
|
// minimum latency of two vsync periods because the app and SurfaceFlinger
|
|
|
|
// will run just after the HW vsync. Setting it to a positive number will
|
|
|
|
// result in the minimum latency being:
|
|
|
|
//
|
|
|
|
// (2 * VSYNC_PERIOD - (vsyncPhaseOffsetNs % VSYNC_PERIOD))
|
|
|
|
//
|
|
|
|
// Note that reducing this latency makes it more likely for the applications
|
|
|
|
// to not have their window content image ready in time. When this happens
|
|
|
|
// the latency will end up being an additional vsync period, and animations
|
|
|
|
// will hiccup. Therefore, this latency should be tuned somewhat
|
|
|
|
// conservatively (or at least with awareness of the trade-off being made).
|
|
|
|
static const int64_t vsyncPhaseOffsetNs = VSYNC_EVENT_PHASE_OFFSET_NS;
|
|
|
|
|
2013-10-15 03:52:46 +00:00
|
|
|
// This is the phase offset at which SurfaceFlinger's composition runs.
|
|
|
|
static const int64_t sfVsyncPhaseOffsetNs = SF_VSYNC_EVENT_PHASE_OFFSET_NS;
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2011-06-27 23:05:52 +00:00
|
|
|
const String16 sHardwareTest("android.permission.HARDWARE_TEST");
|
|
|
|
const String16 sAccessSurfaceFlinger("android.permission.ACCESS_SURFACE_FLINGER");
|
|
|
|
const String16 sReadFramebuffer("android.permission.READ_FRAME_BUFFER");
|
|
|
|
const String16 sDump("android.permission.DUMP");
|
|
|
|
|
2014-07-17 18:36:08 +00:00
|
|
|
static sp<Layer> lastSurfaceViewLayer;
|
|
|
|
|
2011-06-27 23:05:52 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
SurfaceFlinger::SurfaceFlinger()
|
2013-08-20 00:26:18 +00:00
|
|
|
: BnSurfaceComposer(),
|
2009-03-04 03:31:44 +00:00
|
|
|
mTransactionFlags(0),
|
2012-10-16 01:24:43 +00:00
|
|
|
mTransactionPending(false),
|
|
|
|
mAnimTransactionPending(false),
|
2009-04-10 21:24:30 +00:00
|
|
|
mLayersRemoved(false),
|
2012-08-01 02:01:53 +00:00
|
|
|
mRepaintEverything(0),
|
2013-06-07 22:35:48 +00:00
|
|
|
mRenderEngine(NULL),
|
2009-03-04 03:31:44 +00:00
|
|
|
mBootTime(systemTime()),
|
|
|
|
mVisibleRegionsDirty(false),
|
2010-08-11 00:14:02 +00:00
|
|
|
mHwWorkListDirty(false),
|
2013-02-05 21:30:24 +00:00
|
|
|
mAnimCompositionPending(false),
|
2009-03-04 03:31:44 +00:00
|
|
|
mDebugRegion(0),
|
2011-08-16 03:44:40 +00:00
|
|
|
mDebugDDMS(0),
|
2010-09-23 01:58:01 +00:00
|
|
|
mDebugDisableHWC(0),
|
2011-08-24 01:03:18 +00:00
|
|
|
mDebugDisableTransformHint(0),
|
2009-08-26 23:36:26 +00:00
|
|
|
mDebugInSwapBuffers(0),
|
|
|
|
mLastSwapBufferTime(0),
|
|
|
|
mDebugInTransaction(0),
|
|
|
|
mLastTransactionTime(0),
|
2013-09-02 04:36:12 +00:00
|
|
|
mBootFinished(false),
|
2015-03-23 22:50:23 +00:00
|
|
|
mForceFullDamage(false),
|
2013-07-30 22:10:32 +00:00
|
|
|
mPrimaryHWVsyncEnabled(false),
|
2013-10-14 19:56:09 +00:00
|
|
|
mHWVsyncAvailable(false),
|
2013-09-13 03:04:35 +00:00
|
|
|
mDaltonize(false),
|
2015-03-05 19:05:59 +00:00
|
|
|
mHasColorMatrix(false),
|
|
|
|
mHasPoweredOff(false),
|
|
|
|
mFrameBuckets(),
|
|
|
|
mTotalTime(0),
|
2014-12-06 02:28:32 +00:00
|
|
|
mLastSwapTime(0),
|
|
|
|
mActiveFrameSequence(0)
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2012-01-04 20:05:49 +00:00
|
|
|
ALOGI("SurfaceFlinger is starting");
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
// debugging stuff...
|
|
|
|
char value[PROPERTY_VALUE_MAX];
|
2011-08-16 03:44:40 +00:00
|
|
|
|
2013-03-21 01:36:41 +00:00
|
|
|
property_get("ro.bq.gpu_to_cpu_unsupported", value, "0");
|
2013-03-22 04:13:21 +00:00
|
|
|
mGpuToCpuSupported = !atoi(value);
|
2013-03-21 01:36:41 +00:00
|
|
|
|
2015-07-09 19:43:33 +00:00
|
|
|
property_get("debug.sf.drop_missed_frames", value, "0");
|
|
|
|
mDropMissedFrames = atoi(value);
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
property_get("debug.sf.showupdates", value, "0");
|
|
|
|
mDebugRegion = atoi(value);
|
2011-08-16 03:44:40 +00:00
|
|
|
|
|
|
|
property_get("debug.sf.ddms", value, "0");
|
|
|
|
mDebugDDMS = atoi(value);
|
|
|
|
if (mDebugDDMS) {
|
2012-08-31 17:53:36 +00:00
|
|
|
if (!startDdmConnection()) {
|
|
|
|
// start failed, and DDMS debugging not enabled
|
|
|
|
mDebugDDMS = 0;
|
|
|
|
}
|
2011-08-16 03:44:40 +00:00
|
|
|
}
|
2012-08-05 03:09:03 +00:00
|
|
|
ALOGI_IF(mDebugRegion, "showupdates enabled");
|
|
|
|
ALOGI_IF(mDebugDDMS, "DDMS debugging enabled");
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2012-02-01 02:24:27 +00:00
|
|
|
void SurfaceFlinger::onFirstRef()
|
|
|
|
{
|
|
|
|
mEventQueue.init(this);
|
|
|
|
}
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
SurfaceFlinger::~SurfaceFlinger()
|
|
|
|
{
|
2012-07-12 21:25:33 +00:00
|
|
|
EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
|
|
|
eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
|
|
|
eglTerminate(display);
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2014-02-14 23:03:43 +00:00
|
|
|
void SurfaceFlinger::binderDied(const wp<IBinder>& /* who */)
|
2012-02-01 02:24:27 +00:00
|
|
|
{
|
|
|
|
// the window manager died on us. prepare its eulogy.
|
|
|
|
|
2012-08-24 17:16:42 +00:00
|
|
|
// restore initial conditions (default device unblank, etc)
|
|
|
|
initializeDisplays();
|
2012-02-01 02:24:27 +00:00
|
|
|
|
|
|
|
// restart the boot-animation
|
2012-06-20 00:26:12 +00:00
|
|
|
startBootAnim();
|
2012-02-01 02:24:27 +00:00
|
|
|
}
|
|
|
|
|
2010-05-28 21:22:23 +00:00
|
|
|
sp<ISurfaceComposerClient> SurfaceFlinger::createConnection()
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2010-06-03 06:28:45 +00:00
|
|
|
sp<ISurfaceComposerClient> bclient;
|
|
|
|
sp<Client> client(new Client(this));
|
|
|
|
status_t err = client->initCheck();
|
|
|
|
if (err == NO_ERROR) {
|
|
|
|
bclient = client;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
return bclient;
|
|
|
|
}
|
|
|
|
|
2012-10-20 01:19:11 +00:00
|
|
|
sp<IBinder> SurfaceFlinger::createDisplay(const String8& displayName,
|
|
|
|
bool secure)
|
2012-08-09 23:29:12 +00:00
|
|
|
{
|
|
|
|
class DisplayToken : public BBinder {
|
|
|
|
sp<SurfaceFlinger> flinger;
|
|
|
|
virtual ~DisplayToken() {
|
|
|
|
// no more references, this display must be terminated
|
|
|
|
Mutex::Autolock _l(flinger->mStateLock);
|
|
|
|
flinger->mCurrentState.displays.removeItem(this);
|
|
|
|
flinger->setTransactionFlags(eDisplayTransactionNeeded);
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
DisplayToken(const sp<SurfaceFlinger>& flinger)
|
|
|
|
: flinger(flinger) {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
sp<BBinder> token = new DisplayToken(this);
|
|
|
|
|
|
|
|
Mutex::Autolock _l(mStateLock);
|
2012-08-27 23:28:24 +00:00
|
|
|
DisplayDeviceState info(DisplayDevice::DISPLAY_VIRTUAL);
|
2012-09-18 01:27:17 +00:00
|
|
|
info.displayName = displayName;
|
2012-10-20 01:19:11 +00:00
|
|
|
info.isSecure = secure;
|
2012-08-09 23:29:12 +00:00
|
|
|
mCurrentState.displays.add(token, info);
|
|
|
|
|
|
|
|
return token;
|
|
|
|
}
|
|
|
|
|
2013-08-08 19:15:49 +00:00
|
|
|
void SurfaceFlinger::destroyDisplay(const sp<IBinder>& display) {
|
|
|
|
Mutex::Autolock _l(mStateLock);
|
|
|
|
|
|
|
|
ssize_t idx = mCurrentState.displays.indexOfKey(display);
|
|
|
|
if (idx < 0) {
|
|
|
|
ALOGW("destroyDisplay: invalid display token");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const DisplayDeviceState& info(mCurrentState.displays.valueAt(idx));
|
|
|
|
if (!info.isVirtualDisplay()) {
|
|
|
|
ALOGE("destroyDisplay called for non-virtual display");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mCurrentState.displays.removeItemsAt(idx);
|
|
|
|
setTransactionFlags(eDisplayTransactionNeeded);
|
|
|
|
}
|
|
|
|
|
2012-11-08 23:41:56 +00:00
|
|
|
void SurfaceFlinger::createBuiltinDisplayLocked(DisplayDevice::DisplayType type) {
|
|
|
|
ALOGW_IF(mBuiltinDisplays[type],
|
|
|
|
"Overwriting display token for display type %d", type);
|
|
|
|
mBuiltinDisplays[type] = new BBinder();
|
|
|
|
DisplayDeviceState info(type);
|
|
|
|
// All non-virtual displays are currently considered secure.
|
|
|
|
info.isSecure = true;
|
|
|
|
mCurrentState.displays.add(mBuiltinDisplays[type], info);
|
|
|
|
}
|
|
|
|
|
2012-08-09 23:29:12 +00:00
|
|
|
sp<IBinder> SurfaceFlinger::getBuiltInDisplay(int32_t id) {
|
2013-08-16 21:28:37 +00:00
|
|
|
if (uint32_t(id) >= DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES) {
|
2012-08-09 23:29:12 +00:00
|
|
|
ALOGE("getDefaultDisplay: id=%d is not a valid default display id", id);
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-11-08 23:41:56 +00:00
|
|
|
return mBuiltinDisplays[id];
|
2012-08-09 23:29:12 +00:00
|
|
|
}
|
|
|
|
|
2011-01-13 02:30:40 +00:00
|
|
|
sp<IGraphicBufferAlloc> SurfaceFlinger::createGraphicBufferAlloc()
|
|
|
|
{
|
|
|
|
sp<GraphicBufferAlloc> gba(new GraphicBufferAlloc());
|
|
|
|
return gba;
|
|
|
|
}
|
2010-06-01 22:12:58 +00:00
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
void SurfaceFlinger::bootFinished()
|
|
|
|
{
|
|
|
|
const nsecs_t now = systemTime();
|
|
|
|
const nsecs_t duration = now - mBootTime;
|
2012-01-04 20:05:49 +00:00
|
|
|
ALOGI("Boot is finished (%ld ms)", long(ns2ms(duration)) );
|
2009-10-06 00:07:12 +00:00
|
|
|
mBootFinished = true;
|
2011-07-02 00:08:43 +00:00
|
|
|
|
|
|
|
// wait patiently for the window manager death
|
|
|
|
const String16 name("window");
|
|
|
|
sp<IBinder> window(defaultServiceManager()->getService(name));
|
|
|
|
if (window != 0) {
|
2012-07-24 06:11:29 +00:00
|
|
|
window->linkToDeath(static_cast<IBinder::DeathRecipient*>(this));
|
2011-07-02 00:08:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// stop boot animation
|
2012-06-20 00:26:12 +00:00
|
|
|
// formerly we would just kill the process, but we now ask it to exit so it
|
|
|
|
// can choose where to stop the animation.
|
|
|
|
property_set("service.bootanim.exit", "1");
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2013-08-08 04:24:32 +00:00
|
|
|
void SurfaceFlinger::deleteTextureAsync(uint32_t texture) {
|
2012-07-24 06:11:29 +00:00
|
|
|
class MessageDestroyGLTexture : public MessageBase {
|
2013-08-08 04:24:32 +00:00
|
|
|
RenderEngine& engine;
|
|
|
|
uint32_t texture;
|
2012-07-24 06:11:29 +00:00
|
|
|
public:
|
2013-08-08 04:24:32 +00:00
|
|
|
MessageDestroyGLTexture(RenderEngine& engine, uint32_t texture)
|
|
|
|
: engine(engine), texture(texture) {
|
2012-07-24 06:11:29 +00:00
|
|
|
}
|
|
|
|
virtual bool handler() {
|
2013-08-08 04:24:32 +00:00
|
|
|
engine.deleteTextures(1, &texture);
|
2012-07-24 06:11:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2013-08-08 04:24:32 +00:00
|
|
|
postMessageAsync(new MessageDestroyGLTexture(getRenderEngine(), texture));
|
2012-07-24 06:11:29 +00:00
|
|
|
}
|
|
|
|
|
2013-07-30 22:10:32 +00:00
|
|
|
class DispSyncSource : public VSyncSource, private DispSync::Callback {
|
|
|
|
public:
|
2014-05-22 20:08:43 +00:00
|
|
|
DispSyncSource(DispSync* dispSync, nsecs_t phaseOffset, bool traceVsync,
|
|
|
|
const char* label) :
|
2013-10-15 03:52:46 +00:00
|
|
|
mValue(0),
|
|
|
|
mTraceVsync(traceVsync),
|
2014-05-22 20:08:43 +00:00
|
|
|
mVsyncOnLabel(String8::format("VsyncOn-%s", label)),
|
|
|
|
mVsyncEventLabel(String8::format("VSYNC-%s", label)),
|
2015-04-14 18:34:01 +00:00
|
|
|
mDispSync(dispSync),
|
|
|
|
mCallbackMutex(),
|
|
|
|
mCallback(),
|
|
|
|
mVsyncMutex(),
|
|
|
|
mPhaseOffset(phaseOffset),
|
|
|
|
mEnabled(false) {}
|
2013-07-30 22:10:32 +00:00
|
|
|
|
|
|
|
virtual ~DispSyncSource() {}
|
|
|
|
|
|
|
|
virtual void setVSyncEnabled(bool enable) {
|
2015-04-14 18:34:01 +00:00
|
|
|
Mutex::Autolock lock(mVsyncMutex);
|
2013-07-30 22:10:32 +00:00
|
|
|
if (enable) {
|
2013-10-15 03:52:46 +00:00
|
|
|
status_t err = mDispSync->addEventListener(mPhaseOffset,
|
2013-07-30 22:10:32 +00:00
|
|
|
static_cast<DispSync::Callback*>(this));
|
|
|
|
if (err != NO_ERROR) {
|
|
|
|
ALOGE("error registering vsync callback: %s (%d)",
|
|
|
|
strerror(-err), err);
|
|
|
|
}
|
2014-05-22 20:08:43 +00:00
|
|
|
//ATRACE_INT(mVsyncOnLabel.string(), 1);
|
2013-07-30 22:10:32 +00:00
|
|
|
} else {
|
|
|
|
status_t err = mDispSync->removeEventListener(
|
|
|
|
static_cast<DispSync::Callback*>(this));
|
|
|
|
if (err != NO_ERROR) {
|
|
|
|
ALOGE("error unregistering vsync callback: %s (%d)",
|
|
|
|
strerror(-err), err);
|
|
|
|
}
|
2014-05-22 20:08:43 +00:00
|
|
|
//ATRACE_INT(mVsyncOnLabel.string(), 0);
|
2013-07-30 22:10:32 +00:00
|
|
|
}
|
2015-04-14 18:34:01 +00:00
|
|
|
mEnabled = enable;
|
2013-07-30 22:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void setCallback(const sp<VSyncSource::Callback>& callback) {
|
2015-04-14 18:34:01 +00:00
|
|
|
Mutex::Autolock lock(mCallbackMutex);
|
2013-07-30 22:10:32 +00:00
|
|
|
mCallback = callback;
|
|
|
|
}
|
|
|
|
|
2015-04-14 18:34:01 +00:00
|
|
|
virtual void setPhaseOffset(nsecs_t phaseOffset) {
|
|
|
|
Mutex::Autolock lock(mVsyncMutex);
|
|
|
|
|
|
|
|
// Normalize phaseOffset to [0, period)
|
|
|
|
auto period = mDispSync->getPeriod();
|
|
|
|
phaseOffset %= period;
|
|
|
|
if (phaseOffset < 0) {
|
|
|
|
// If we're here, then phaseOffset is in (-period, 0). After this
|
|
|
|
// operation, it will be in (0, period)
|
|
|
|
phaseOffset += period;
|
|
|
|
}
|
|
|
|
mPhaseOffset = phaseOffset;
|
|
|
|
|
|
|
|
// If we're not enabled, we don't need to mess with the listeners
|
|
|
|
if (!mEnabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the listener with the old offset
|
|
|
|
status_t err = mDispSync->removeEventListener(
|
|
|
|
static_cast<DispSync::Callback*>(this));
|
|
|
|
if (err != NO_ERROR) {
|
|
|
|
ALOGE("error unregistering vsync callback: %s (%d)",
|
|
|
|
strerror(-err), err);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add a listener with the new offset
|
|
|
|
err = mDispSync->addEventListener(mPhaseOffset,
|
|
|
|
static_cast<DispSync::Callback*>(this));
|
|
|
|
if (err != NO_ERROR) {
|
|
|
|
ALOGE("error registering vsync callback: %s (%d)",
|
|
|
|
strerror(-err), err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-30 22:10:32 +00:00
|
|
|
private:
|
|
|
|
virtual void onDispSyncEvent(nsecs_t when) {
|
|
|
|
sp<VSyncSource::Callback> callback;
|
|
|
|
{
|
2015-04-14 18:34:01 +00:00
|
|
|
Mutex::Autolock lock(mCallbackMutex);
|
2013-07-30 22:10:32 +00:00
|
|
|
callback = mCallback;
|
2012-07-12 21:25:33 +00:00
|
|
|
|
2013-10-15 03:52:46 +00:00
|
|
|
if (mTraceVsync) {
|
|
|
|
mValue = (mValue + 1) % 2;
|
2014-05-22 20:08:43 +00:00
|
|
|
ATRACE_INT(mVsyncEventLabel.string(), mValue);
|
2013-10-15 03:52:46 +00:00
|
|
|
}
|
2013-07-30 22:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (callback != NULL) {
|
|
|
|
callback->onVSyncEvent(when);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int mValue;
|
|
|
|
|
2013-10-15 03:52:46 +00:00
|
|
|
const bool mTraceVsync;
|
2014-05-22 20:08:43 +00:00
|
|
|
const String8 mVsyncOnLabel;
|
|
|
|
const String8 mVsyncEventLabel;
|
2013-10-15 03:52:46 +00:00
|
|
|
|
2013-07-30 22:10:32 +00:00
|
|
|
DispSync* mDispSync;
|
2015-04-14 18:34:01 +00:00
|
|
|
|
|
|
|
Mutex mCallbackMutex; // Protects the following
|
2013-07-30 22:10:32 +00:00
|
|
|
sp<VSyncSource::Callback> mCallback;
|
2015-04-14 18:34:01 +00:00
|
|
|
|
|
|
|
Mutex mVsyncMutex; // Protects the following
|
|
|
|
nsecs_t mPhaseOffset;
|
|
|
|
bool mEnabled;
|
2013-07-30 22:10:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void SurfaceFlinger::init() {
|
2012-07-12 21:25:33 +00:00
|
|
|
ALOGI( "SurfaceFlinger's main thread ready to run. "
|
|
|
|
"Initializing graphics H/W...");
|
|
|
|
|
2012-11-08 23:41:56 +00:00
|
|
|
Mutex::Autolock _l(mStateLock);
|
|
|
|
|
2012-09-10 21:08:09 +00:00
|
|
|
// initialize EGL for the default display
|
2012-07-30 05:35:34 +00:00
|
|
|
mEGLDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
|
|
|
eglInitialize(mEGLDisplay, NULL, NULL);
|
2012-07-12 21:25:33 +00:00
|
|
|
|
2015-06-16 00:55:51 +00:00
|
|
|
// start the EventThread
|
|
|
|
sp<VSyncSource> vsyncSrc = new DispSyncSource(&mPrimaryDispSync,
|
|
|
|
vsyncPhaseOffsetNs, true, "app");
|
|
|
|
mEventThread = new EventThread(vsyncSrc);
|
|
|
|
sp<VSyncSource> sfVsyncSrc = new DispSyncSource(&mPrimaryDispSync,
|
|
|
|
sfVsyncPhaseOffsetNs, true, "sf");
|
|
|
|
mSFEventThread = new EventThread(sfVsyncSrc);
|
|
|
|
mEventQueue.setEventThread(mSFEventThread);
|
|
|
|
|
2012-09-10 21:08:09 +00:00
|
|
|
// Initialize the H/W composer object. There may or may not be an
|
|
|
|
// actual hardware composer underneath.
|
2015-06-23 19:55:15 +00:00
|
|
|
mHwc = DisplayUtils::getInstance()->getHWCInstance(this,
|
2012-09-10 21:08:09 +00:00
|
|
|
*static_cast<HWComposer::EventHandler *>(this));
|
|
|
|
|
2013-06-07 22:35:48 +00:00
|
|
|
// get a RenderEngine for the given display / config (can't fail)
|
2013-12-24 04:44:38 +00:00
|
|
|
mRenderEngine = RenderEngine::create(mEGLDisplay, mHwc->getVisualID());
|
2013-06-07 22:35:48 +00:00
|
|
|
|
|
|
|
// retrieve the EGL context that was selected/created
|
|
|
|
mEGLContext = mRenderEngine->getEGLContext();
|
2012-07-12 21:25:33 +00:00
|
|
|
|
2012-09-14 01:17:13 +00:00
|
|
|
LOG_ALWAYS_FATAL_IF(mEGLContext == EGL_NO_CONTEXT,
|
|
|
|
"couldn't create EGLContext");
|
|
|
|
|
2012-09-13 21:09:01 +00:00
|
|
|
// initialize our non-virtual displays
|
2013-08-16 21:28:37 +00:00
|
|
|
for (size_t i=0 ; i<DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES ; i++) {
|
2012-09-20 01:16:22 +00:00
|
|
|
DisplayDevice::DisplayType type((DisplayDevice::DisplayType)i);
|
|
|
|
// set-up the displays that are already connected
|
2012-09-22 01:26:16 +00:00
|
|
|
if (mHwc->isConnected(i) || type==DisplayDevice::DISPLAY_PRIMARY) {
|
2012-10-20 01:19:11 +00:00
|
|
|
// All non-virtual displays are currently considered secure.
|
|
|
|
bool isSecure = true;
|
2012-11-08 23:41:56 +00:00
|
|
|
createBuiltinDisplayLocked(type);
|
|
|
|
wp<IBinder> token = mBuiltinDisplays[i];
|
|
|
|
|
2014-03-13 18:55:57 +00:00
|
|
|
sp<IGraphicBufferProducer> producer;
|
|
|
|
sp<IGraphicBufferConsumer> consumer;
|
|
|
|
BufferQueue::createBufferQueue(&producer, &consumer,
|
|
|
|
new GraphicBufferAlloc());
|
|
|
|
|
|
|
|
sp<FramebufferSurface> fbs = new FramebufferSurface(*mHwc, i,
|
|
|
|
consumer);
|
2013-12-24 05:02:15 +00:00
|
|
|
int32_t hwcId = allocateHwcDisplayId(type);
|
2012-09-20 01:16:22 +00:00
|
|
|
sp<DisplayDevice> hw = new DisplayDevice(this,
|
2013-12-24 05:02:15 +00:00
|
|
|
type, hwcId, mHwc->getFormat(hwcId), isSecure, token,
|
2014-03-13 18:55:57 +00:00
|
|
|
fbs, producer,
|
2013-12-24 04:44:38 +00:00
|
|
|
mRenderEngine->getEGLConfig());
|
2012-09-20 01:16:22 +00:00
|
|
|
if (i > DisplayDevice::DISPLAY_PRIMARY) {
|
2012-09-27 23:02:06 +00:00
|
|
|
// FIXME: currently we don't get blank/unblank requests
|
2012-09-20 01:16:22 +00:00
|
|
|
// for displays other than the main display, so we always
|
|
|
|
// assume a connected display is unblanked.
|
2014-03-07 20:44:02 +00:00
|
|
|
ALOGD("marking display %zu as acquired/unblanked", i);
|
2014-05-25 08:36:31 +00:00
|
|
|
hw->setPowerMode(HWC_POWER_MODE_NORMAL);
|
2012-09-20 01:16:22 +00:00
|
|
|
}
|
2014-09-22 23:57:24 +00:00
|
|
|
// When a non-virtual display device is added at boot time,
|
|
|
|
// update the active config by querying HWC otherwise the
|
|
|
|
// default config (config 0) will be used.
|
|
|
|
int activeConfig = mHwc->getActiveConfig(hwcId);
|
|
|
|
if (activeConfig >= 0) {
|
|
|
|
hw->setActiveConfig(activeConfig);
|
|
|
|
}
|
2012-09-20 01:16:22 +00:00
|
|
|
mDisplays.add(token, hw);
|
|
|
|
}
|
2012-08-09 23:29:12 +00:00
|
|
|
}
|
2012-09-13 21:09:01 +00:00
|
|
|
|
2013-08-08 03:10:20 +00:00
|
|
|
// make the GLContext current so that we can create textures when creating Layers
|
|
|
|
// (which may happens before we render something)
|
|
|
|
getDefaultDisplayDevice()->makeCurrent(mEGLDisplay, mEGLContext);
|
|
|
|
|
2013-10-14 19:22:52 +00:00
|
|
|
mEventControlThread = new EventControlThread(this);
|
|
|
|
mEventControlThread->run("EventControl", PRIORITY_URGENT_DISPLAY);
|
2015-09-20 11:20:21 +00:00
|
|
|
android_set_rt_ioprio(mEventControlThread->getTid(), 1);
|
2013-10-14 19:22:52 +00:00
|
|
|
|
2013-07-30 22:10:32 +00:00
|
|
|
// set a fake vsync period if there is no HWComposer
|
|
|
|
if (mHwc->initCheck() != NO_ERROR) {
|
|
|
|
mPrimaryDispSync.setPeriod(16666667);
|
|
|
|
}
|
|
|
|
|
2012-08-03 01:32:23 +00:00
|
|
|
// initialize our drawing state
|
|
|
|
mDrawingState = mCurrentState;
|
2012-07-25 05:46:10 +00:00
|
|
|
|
2012-08-24 17:16:42 +00:00
|
|
|
// set initial conditions (e.g. unblank default device)
|
|
|
|
initializeDisplays();
|
|
|
|
|
2009-05-22 02:21:59 +00:00
|
|
|
// start boot animation
|
2012-06-20 00:26:12 +00:00
|
|
|
startBootAnim();
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2012-08-27 23:28:24 +00:00
|
|
|
int32_t SurfaceFlinger::allocateHwcDisplayId(DisplayDevice::DisplayType type) {
|
2013-08-16 21:28:37 +00:00
|
|
|
return (uint32_t(type) < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES) ?
|
2012-08-27 23:28:24 +00:00
|
|
|
type : mHwc->allocateDisplayId();
|
|
|
|
}
|
|
|
|
|
2012-06-20 00:26:12 +00:00
|
|
|
void SurfaceFlinger::startBootAnim() {
|
|
|
|
// start boot animation
|
|
|
|
property_set("service.bootanim.exit", "0");
|
|
|
|
property_set("ctl.start", "bootanim");
|
|
|
|
}
|
|
|
|
|
2013-06-07 22:35:48 +00:00
|
|
|
size_t SurfaceFlinger::getMaxTextureSize() const {
|
|
|
|
return mRenderEngine->getMaxTextureSize();
|
2012-07-12 21:25:33 +00:00
|
|
|
}
|
|
|
|
|
2013-06-07 22:35:48 +00:00
|
|
|
size_t SurfaceFlinger::getMaxViewportDims() const {
|
|
|
|
return mRenderEngine->getMaxViewportDims();
|
2012-07-12 21:25:33 +00:00
|
|
|
}
|
|
|
|
|
2011-11-18 01:49:17 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2011-08-18 01:19:00 +00:00
|
|
|
bool SurfaceFlinger::authenticateSurfaceTexture(
|
2012-12-18 17:49:45 +00:00
|
|
|
const sp<IGraphicBufferProducer>& bufferProducer) const {
|
2011-03-08 20:18:54 +00:00
|
|
|
Mutex::Autolock _l(mStateLock);
|
2014-11-14 16:01:01 +00:00
|
|
|
sp<IBinder> surfaceTextureBinder(IInterface::asBinder(bufferProducer));
|
2013-03-15 02:18:13 +00:00
|
|
|
return mGraphicBufferProducerList.indexOf(surfaceTextureBinder) >= 0;
|
2011-03-08 20:18:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-02 22:26:25 +00:00
|
|
|
status_t SurfaceFlinger::getDisplayConfigs(const sp<IBinder>& display,
|
|
|
|
Vector<DisplayInfo>* configs) {
|
2014-10-29 23:47:19 +00:00
|
|
|
if ((configs == NULL) || (display.get() == NULL)) {
|
2014-05-02 22:26:25 +00:00
|
|
|
return BAD_VALUE;
|
|
|
|
}
|
|
|
|
|
2014-11-03 19:49:23 +00:00
|
|
|
if (!display.get())
|
|
|
|
return NAME_NOT_FOUND;
|
|
|
|
|
2012-11-08 23:41:56 +00:00
|
|
|
int32_t type = NAME_NOT_FOUND;
|
2013-08-16 21:28:37 +00:00
|
|
|
for (int i=0 ; i<DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES ; i++) {
|
2012-11-08 23:41:56 +00:00
|
|
|
if (display == mBuiltinDisplays[i]) {
|
2012-09-19 04:54:42 +00:00
|
|
|
type = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type < 0) {
|
|
|
|
return type;
|
2012-07-26 01:56:13 +00:00
|
|
|
}
|
2012-08-14 00:54:26 +00:00
|
|
|
|
|
|
|
// TODO: Not sure if display density should handled by SF any longer
|
|
|
|
class Density {
|
|
|
|
static int getDensityFromProperty(char const* propName) {
|
|
|
|
char property[PROPERTY_VALUE_MAX];
|
|
|
|
int density = 0;
|
|
|
|
if (property_get(propName, property, NULL) > 0) {
|
|
|
|
density = atoi(property);
|
|
|
|
}
|
|
|
|
return density;
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
static int getEmuDensity() {
|
|
|
|
return getDensityFromProperty("qemu.sf.lcd_density"); }
|
|
|
|
static int getBuildDensity() {
|
|
|
|
return getDensityFromProperty("ro.sf.lcd_density"); }
|
|
|
|
};
|
2012-09-19 04:54:42 +00:00
|
|
|
|
2014-05-02 22:26:25 +00:00
|
|
|
configs->clear();
|
|
|
|
|
|
|
|
const Vector<HWComposer::DisplayConfig>& hwConfigs =
|
|
|
|
getHwComposer().getConfigs(type);
|
|
|
|
for (size_t c = 0; c < hwConfigs.size(); ++c) {
|
|
|
|
const HWComposer::DisplayConfig& hwConfig = hwConfigs[c];
|
|
|
|
DisplayInfo info = DisplayInfo();
|
|
|
|
|
|
|
|
float xdpi = hwConfig.xdpi;
|
|
|
|
float ydpi = hwConfig.ydpi;
|
|
|
|
|
|
|
|
if (type == DisplayDevice::DISPLAY_PRIMARY) {
|
|
|
|
// The density of the device is provided by a build property
|
|
|
|
float density = Density::getBuildDensity() / 160.0f;
|
|
|
|
if (density == 0) {
|
|
|
|
// the build doesn't provide a density -- this is wrong!
|
|
|
|
// use xdpi instead
|
|
|
|
ALOGE("ro.sf.lcd_density must be defined as a build property");
|
|
|
|
density = xdpi / 160.0f;
|
|
|
|
}
|
|
|
|
if (Density::getEmuDensity()) {
|
|
|
|
// if "qemu.sf.lcd_density" is specified, it overrides everything
|
|
|
|
xdpi = ydpi = density = Density::getEmuDensity();
|
|
|
|
density /= 160.0f;
|
|
|
|
}
|
|
|
|
info.density = density;
|
|
|
|
|
|
|
|
// TODO: this needs to go away (currently needed only by webkit)
|
|
|
|
sp<const DisplayDevice> hw(getDefaultDisplayDevice());
|
|
|
|
info.orientation = hw->getOrientation();
|
|
|
|
} else {
|
|
|
|
// TODO: where should this value come from?
|
|
|
|
static const int TV_DENSITY = 213;
|
|
|
|
info.density = TV_DENSITY / 160.0f;
|
|
|
|
info.orientation = 0;
|
2012-09-19 04:54:42 +00:00
|
|
|
}
|
2014-05-02 22:26:25 +00:00
|
|
|
|
2015-11-10 22:58:38 +00:00
|
|
|
char value[PROPERTY_VALUE_MAX];
|
|
|
|
property_get("ro.sf.hwrotation", value, "0");
|
|
|
|
int additionalRot = atoi(value) / 90;
|
2012-12-11 00:33:53 +00:00
|
|
|
if ((type == DisplayDevice::DISPLAY_PRIMARY) && (additionalRot & DisplayState::eOrientationSwapMask)) {
|
|
|
|
info.h = hwConfig.width;
|
|
|
|
info.w = hwConfig.height;
|
|
|
|
info.xdpi = ydpi;
|
|
|
|
info.ydpi = xdpi;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
info.w = hwConfig.width;
|
|
|
|
info.h = hwConfig.height;
|
|
|
|
info.xdpi = xdpi;
|
|
|
|
info.ydpi = ydpi;
|
|
|
|
}
|
2014-05-02 22:26:25 +00:00
|
|
|
info.fps = float(1e9 / hwConfig.refresh);
|
2014-06-13 21:04:23 +00:00
|
|
|
info.appVsyncOffset = VSYNC_EVENT_PHASE_OFFSET_NS;
|
2015-08-31 19:06:48 +00:00
|
|
|
info.colorTransform = hwConfig.colorTransform;
|
2014-06-13 21:04:23 +00:00
|
|
|
|
|
|
|
// This is how far in advance a buffer must be queued for
|
|
|
|
// presentation at a given time. If you want a buffer to appear
|
|
|
|
// on the screen at time N, you must submit the buffer before
|
|
|
|
// (N - presentationDeadline).
|
|
|
|
//
|
|
|
|
// Normally it's one full refresh period (to give SF a chance to
|
|
|
|
// latch the buffer), but this can be reduced by configuring a
|
|
|
|
// DispSync offset. Any additional delays introduced by the hardware
|
|
|
|
// composer or panel must be accounted for here.
|
|
|
|
//
|
|
|
|
// We add an additional 1ms to allow for processing time and
|
|
|
|
// differences between the ideal and actual refresh rate.
|
|
|
|
info.presentationDeadline =
|
|
|
|
hwConfig.refresh - SF_VSYNC_EVENT_PHASE_OFFSET_NS + 1000000;
|
2014-05-02 22:26:25 +00:00
|
|
|
|
|
|
|
// All non-virtual displays are currently considered secure.
|
|
|
|
info.secure = true;
|
|
|
|
|
|
|
|
configs->push_back(info);
|
2012-08-14 00:54:26 +00:00
|
|
|
}
|
|
|
|
|
2014-05-02 22:26:25 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
}
|
2012-10-20 01:19:11 +00:00
|
|
|
|
2014-11-13 22:18:56 +00:00
|
|
|
status_t SurfaceFlinger::getDisplayStats(const sp<IBinder>& /* display */,
|
2014-09-11 21:58:45 +00:00
|
|
|
DisplayStatInfo* stats) {
|
|
|
|
if (stats == NULL) {
|
|
|
|
return BAD_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME for now we always return stats for the primary display
|
|
|
|
memset(stats, 0, sizeof(*stats));
|
|
|
|
stats->vsyncTime = mPrimaryDispSync.computeNextRefresh(0);
|
|
|
|
stats->vsyncPeriod = mPrimaryDispSync.getPeriod();
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2014-07-14 20:48:55 +00:00
|
|
|
int SurfaceFlinger::getActiveConfig(const sp<IBinder>& display) {
|
2015-03-09 17:04:11 +00:00
|
|
|
sp<DisplayDevice> device(getDisplayDevice(display));
|
|
|
|
if (device != NULL) {
|
|
|
|
return device->getActiveConfig();
|
|
|
|
}
|
|
|
|
return BAD_VALUE;
|
2014-05-02 22:26:25 +00:00
|
|
|
}
|
2012-10-20 01:19:11 +00:00
|
|
|
|
2014-07-14 20:48:55 +00:00
|
|
|
void SurfaceFlinger::setActiveConfigInternal(const sp<DisplayDevice>& hw, int mode) {
|
|
|
|
ALOGD("Set active config mode=%d, type=%d flinger=%p", mode, hw->getDisplayType(),
|
|
|
|
this);
|
|
|
|
int32_t type = hw->getDisplayType();
|
|
|
|
int currentMode = hw->getActiveConfig();
|
|
|
|
|
|
|
|
if (mode == currentMode) {
|
|
|
|
ALOGD("Screen type=%d is already mode=%d", hw->getDisplayType(), mode);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type >= DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES) {
|
|
|
|
ALOGW("Trying to set config for virtual display");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-22 23:57:24 +00:00
|
|
|
status_t status = getHwComposer().setActiveConfig(type, mode);
|
|
|
|
if (status == NO_ERROR) {
|
|
|
|
hw->setActiveConfig(mode);
|
|
|
|
}
|
2014-07-14 20:48:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
status_t SurfaceFlinger::setActiveConfig(const sp<IBinder>& display, int mode) {
|
|
|
|
class MessageSetActiveConfig: public MessageBase {
|
|
|
|
SurfaceFlinger& mFlinger;
|
|
|
|
sp<IBinder> mDisplay;
|
|
|
|
int mMode;
|
|
|
|
public:
|
|
|
|
MessageSetActiveConfig(SurfaceFlinger& flinger, const sp<IBinder>& disp,
|
|
|
|
int mode) :
|
|
|
|
mFlinger(flinger), mDisplay(disp) { mMode = mode; }
|
|
|
|
virtual bool handler() {
|
2014-07-30 20:00:37 +00:00
|
|
|
Vector<DisplayInfo> configs;
|
|
|
|
mFlinger.getDisplayConfigs(mDisplay, &configs);
|
2014-08-08 05:43:06 +00:00
|
|
|
if (mMode < 0 || mMode >= static_cast<int>(configs.size())) {
|
2014-07-30 23:42:12 +00:00
|
|
|
ALOGE("Attempt to set active config = %d for display with %zu configs",
|
2014-07-30 20:00:37 +00:00
|
|
|
mMode, configs.size());
|
|
|
|
}
|
2014-07-14 20:48:55 +00:00
|
|
|
sp<DisplayDevice> hw(mFlinger.getDisplayDevice(mDisplay));
|
|
|
|
if (hw == NULL) {
|
|
|
|
ALOGE("Attempt to set active config = %d for null display %p",
|
2014-07-30 20:00:37 +00:00
|
|
|
mMode, mDisplay.get());
|
2014-07-14 20:48:55 +00:00
|
|
|
} else if (hw->getDisplayType() >= DisplayDevice::DISPLAY_VIRTUAL) {
|
|
|
|
ALOGW("Attempt to set active config = %d for virtual display",
|
|
|
|
mMode);
|
|
|
|
} else {
|
|
|
|
mFlinger.setActiveConfigInternal(hw, mMode);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
sp<MessageBase> msg = new MessageSetActiveConfig(*this, display, mode);
|
|
|
|
postMessageSync(msg);
|
2012-08-05 04:10:38 +00:00
|
|
|
return NO_ERROR;
|
2012-07-26 01:56:13 +00:00
|
|
|
}
|
|
|
|
|
2014-03-20 17:28:31 +00:00
|
|
|
status_t SurfaceFlinger::clearAnimationFrameStats() {
|
|
|
|
Mutex::Autolock _l(mStateLock);
|
|
|
|
mAnimFrameTracker.clearStats();
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t SurfaceFlinger::getAnimationFrameStats(FrameStats* outStats) const {
|
|
|
|
Mutex::Autolock _l(mStateLock);
|
|
|
|
mAnimFrameTracker.getStats(outStats);
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2011-11-18 01:49:17 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
sp<IDisplayEventConnection> SurfaceFlinger::createDisplayEventConnection() {
|
2012-01-25 00:39:14 +00:00
|
|
|
return mEventThread->createEventConnection();
|
2010-05-19 00:06:55 +00:00
|
|
|
}
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2012-02-01 02:24:27 +00:00
|
|
|
|
|
|
|
void SurfaceFlinger::waitForEvent() {
|
|
|
|
mEventQueue.waitMessage();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SurfaceFlinger::signalTransaction() {
|
|
|
|
mEventQueue.invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SurfaceFlinger::signalLayerUpdate() {
|
|
|
|
mEventQueue.invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SurfaceFlinger::signalRefresh() {
|
|
|
|
mEventQueue.refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t SurfaceFlinger::postMessageAsync(const sp<MessageBase>& msg,
|
2014-02-14 23:03:43 +00:00
|
|
|
nsecs_t reltime, uint32_t /* flags */) {
|
2012-02-01 02:24:27 +00:00
|
|
|
return mEventQueue.postMessage(msg, reltime);
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t SurfaceFlinger::postMessageSync(const sp<MessageBase>& msg,
|
2014-02-14 23:03:43 +00:00
|
|
|
nsecs_t reltime, uint32_t /* flags */) {
|
2012-02-01 02:24:27 +00:00
|
|
|
status_t res = mEventQueue.postMessage(msg, reltime);
|
|
|
|
if (res == NO_ERROR) {
|
|
|
|
msg->wait();
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2013-08-20 00:26:18 +00:00
|
|
|
void SurfaceFlinger::run() {
|
|
|
|
do {
|
|
|
|
waitForEvent();
|
|
|
|
} while (true);
|
2012-02-01 02:24:27 +00:00
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2013-07-30 22:10:32 +00:00
|
|
|
void SurfaceFlinger::enableHardwareVsync() {
|
|
|
|
Mutex::Autolock _l(mHWVsyncLock);
|
2013-10-14 19:56:09 +00:00
|
|
|
if (!mPrimaryHWVsyncEnabled && mHWVsyncAvailable) {
|
2013-07-30 22:10:32 +00:00
|
|
|
mPrimaryDispSync.beginResync();
|
2013-10-14 19:22:52 +00:00
|
|
|
//eventControl(HWC_DISPLAY_PRIMARY, SurfaceFlinger::EVENT_VSYNC, true);
|
|
|
|
mEventControlThread->setVsyncEnabled(true);
|
2013-07-30 22:10:32 +00:00
|
|
|
mPrimaryHWVsyncEnabled = true;
|
2012-09-11 22:15:13 +00:00
|
|
|
}
|
2013-07-30 22:10:32 +00:00
|
|
|
}
|
|
|
|
|
2013-10-14 19:56:09 +00:00
|
|
|
void SurfaceFlinger::resyncToHardwareVsync(bool makeAvailable) {
|
2013-07-30 22:10:32 +00:00
|
|
|
Mutex::Autolock _l(mHWVsyncLock);
|
|
|
|
|
2013-10-14 19:56:09 +00:00
|
|
|
if (makeAvailable) {
|
|
|
|
mHWVsyncAvailable = true;
|
|
|
|
} else if (!mHWVsyncAvailable) {
|
|
|
|
ALOGE("resyncToHardwareVsync called when HW vsync unavailable");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-30 22:10:32 +00:00
|
|
|
const nsecs_t period =
|
|
|
|
getHwComposer().getRefreshPeriod(HWC_DISPLAY_PRIMARY);
|
|
|
|
|
|
|
|
mPrimaryDispSync.reset();
|
|
|
|
mPrimaryDispSync.setPeriod(period);
|
|
|
|
|
|
|
|
if (!mPrimaryHWVsyncEnabled) {
|
|
|
|
mPrimaryDispSync.beginResync();
|
2013-10-14 19:22:52 +00:00
|
|
|
//eventControl(HWC_DISPLAY_PRIMARY, SurfaceFlinger::EVENT_VSYNC, true);
|
|
|
|
mEventControlThread->setVsyncEnabled(true);
|
2013-07-30 22:10:32 +00:00
|
|
|
mPrimaryHWVsyncEnabled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-14 19:56:09 +00:00
|
|
|
void SurfaceFlinger::disableHardwareVsync(bool makeUnavailable) {
|
2013-07-30 22:10:32 +00:00
|
|
|
Mutex::Autolock _l(mHWVsyncLock);
|
|
|
|
if (mPrimaryHWVsyncEnabled) {
|
2013-10-14 19:22:52 +00:00
|
|
|
//eventControl(HWC_DISPLAY_PRIMARY, SurfaceFlinger::EVENT_VSYNC, false);
|
|
|
|
mEventControlThread->setVsyncEnabled(false);
|
2013-07-30 22:10:32 +00:00
|
|
|
mPrimaryDispSync.endResync();
|
|
|
|
mPrimaryHWVsyncEnabled = false;
|
|
|
|
}
|
2013-10-14 19:56:09 +00:00
|
|
|
if (makeUnavailable) {
|
|
|
|
mHWVsyncAvailable = false;
|
|
|
|
}
|
2013-07-30 22:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SurfaceFlinger::onVSyncReceived(int type, nsecs_t timestamp) {
|
2013-10-14 19:22:52 +00:00
|
|
|
bool needsHwVsync = false;
|
2013-07-30 22:10:32 +00:00
|
|
|
|
2013-10-14 19:22:52 +00:00
|
|
|
{ // Scope for the lock
|
|
|
|
Mutex::Autolock _l(mHWVsyncLock);
|
|
|
|
if (type == 0 && mPrimaryHWVsyncEnabled) {
|
|
|
|
needsHwVsync = mPrimaryDispSync.addResyncSample(timestamp);
|
2013-07-30 22:10:32 +00:00
|
|
|
}
|
2012-09-20 00:31:36 +00:00
|
|
|
}
|
2013-10-14 19:22:52 +00:00
|
|
|
|
|
|
|
if (needsHwVsync) {
|
|
|
|
enableHardwareVsync();
|
|
|
|
} else {
|
|
|
|
disableHardwareVsync(false);
|
|
|
|
}
|
2012-09-20 00:31:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SurfaceFlinger::onHotplugReceived(int type, bool connected) {
|
|
|
|
if (mEventThread == NULL) {
|
|
|
|
// This is a temporary workaround for b/7145521. A non-null pointer
|
|
|
|
// does not mean EventThread has finished initializing, so this
|
|
|
|
// is not a correct fix.
|
|
|
|
ALOGW("WARNING: EventThread not started, ignoring hotplug");
|
|
|
|
return;
|
|
|
|
}
|
2012-09-22 01:26:16 +00:00
|
|
|
|
2013-08-16 21:28:37 +00:00
|
|
|
if (uint32_t(type) < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES) {
|
2012-09-22 01:26:16 +00:00
|
|
|
Mutex::Autolock _l(mStateLock);
|
2012-11-08 23:41:56 +00:00
|
|
|
if (connected) {
|
|
|
|
createBuiltinDisplayLocked((DisplayDevice::DisplayType)type);
|
2012-09-22 01:26:16 +00:00
|
|
|
} else {
|
2012-11-08 23:41:56 +00:00
|
|
|
mCurrentState.displays.removeItem(mBuiltinDisplays[type]);
|
|
|
|
mBuiltinDisplays[type].clear();
|
2015-06-23 19:55:15 +00:00
|
|
|
updateVisibleRegionsDirty();
|
2012-09-22 01:26:16 +00:00
|
|
|
}
|
|
|
|
setTransactionFlags(eDisplayTransactionNeeded);
|
|
|
|
|
2012-10-11 01:17:51 +00:00
|
|
|
// Defer EventThread notification until SF has updated mDisplays.
|
2012-08-27 23:28:24 +00:00
|
|
|
}
|
2012-07-25 05:46:10 +00:00
|
|
|
}
|
|
|
|
|
2012-10-04 09:34:38 +00:00
|
|
|
void SurfaceFlinger::eventControl(int disp, int event, int enabled) {
|
2013-07-30 22:10:32 +00:00
|
|
|
ATRACE_CALL();
|
2012-10-04 09:34:38 +00:00
|
|
|
getHwComposer().eventControl(disp, event, enabled);
|
2012-07-25 05:46:10 +00:00
|
|
|
}
|
|
|
|
|
2012-06-29 21:12:52 +00:00
|
|
|
void SurfaceFlinger::onMessageReceived(int32_t what) {
|
2012-02-24 03:27:23 +00:00
|
|
|
ATRACE_CALL();
|
2012-02-01 02:24:27 +00:00
|
|
|
switch (what) {
|
2014-11-08 00:00:59 +00:00
|
|
|
case MessageQueue::TRANSACTION: {
|
|
|
|
handleMessageTransaction();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageQueue::INVALIDATE: {
|
|
|
|
bool refreshNeeded = handleMessageTransaction();
|
|
|
|
refreshNeeded |= handleMessageInvalidate();
|
2014-12-03 00:58:17 +00:00
|
|
|
refreshNeeded |= mRepaintEverything;
|
2014-11-08 00:00:59 +00:00
|
|
|
if (refreshNeeded) {
|
2014-12-03 00:58:17 +00:00
|
|
|
// Signal a refresh if a transaction modified the window state,
|
|
|
|
// a new buffer was latched, or if HWC has requested a full
|
|
|
|
// repaint
|
2014-11-08 00:00:59 +00:00
|
|
|
signalRefresh();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageQueue::REFRESH: {
|
|
|
|
handleMessageRefresh();
|
|
|
|
break;
|
|
|
|
}
|
2012-06-29 21:12:52 +00:00
|
|
|
}
|
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2014-11-08 00:00:59 +00:00
|
|
|
bool SurfaceFlinger::handleMessageTransaction() {
|
2012-08-09 23:29:12 +00:00
|
|
|
uint32_t transactionFlags = peekTransactionFlags(eTransactionMask);
|
2012-06-29 21:12:52 +00:00
|
|
|
if (transactionFlags) {
|
2012-07-31 19:38:26 +00:00
|
|
|
handleTransaction(transactionFlags);
|
2014-11-08 00:00:59 +00:00
|
|
|
return true;
|
2012-06-29 21:12:52 +00:00
|
|
|
}
|
2014-11-08 00:00:59 +00:00
|
|
|
return false;
|
2012-06-29 21:12:52 +00:00
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2014-11-08 00:00:59 +00:00
|
|
|
bool SurfaceFlinger::handleMessageInvalidate() {
|
2012-08-16 23:28:27 +00:00
|
|
|
ATRACE_CALL();
|
2014-11-08 00:00:59 +00:00
|
|
|
return handlePageFlip();
|
2012-06-29 21:12:52 +00:00
|
|
|
}
|
2011-10-19 00:36:28 +00:00
|
|
|
|
2012-06-29 21:12:52 +00:00
|
|
|
void SurfaceFlinger::handleMessageRefresh() {
|
2012-08-16 23:28:27 +00:00
|
|
|
ATRACE_CALL();
|
2015-07-09 19:43:33 +00:00
|
|
|
|
|
|
|
static nsecs_t previousExpectedPresent = 0;
|
|
|
|
nsecs_t expectedPresent = mPrimaryDispSync.computeNextRefresh(0);
|
|
|
|
static bool previousFrameMissed = false;
|
|
|
|
bool frameMissed = (expectedPresent == previousExpectedPresent);
|
|
|
|
if (frameMissed != previousFrameMissed) {
|
|
|
|
ATRACE_INT("FrameMissed", static_cast<int>(frameMissed));
|
|
|
|
}
|
|
|
|
previousFrameMissed = frameMissed;
|
|
|
|
|
|
|
|
if (CC_UNLIKELY(mDropMissedFrames && frameMissed)) {
|
|
|
|
// Latch buffers, but don't send anything to HWC, then signal another
|
|
|
|
// wakeup for the next vsync
|
|
|
|
preComposition();
|
|
|
|
repaintEverything();
|
|
|
|
} else {
|
|
|
|
preComposition();
|
|
|
|
rebuildLayerStacks();
|
|
|
|
setUpHWComposer();
|
|
|
|
doDebugFlashRegions();
|
|
|
|
doComposition();
|
|
|
|
postComposition();
|
|
|
|
}
|
|
|
|
|
|
|
|
previousExpectedPresent = mPrimaryDispSync.computeNextRefresh(0);
|
2012-08-16 23:28:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SurfaceFlinger::doDebugFlashRegions()
|
|
|
|
{
|
|
|
|
// is debugging enabled
|
|
|
|
if (CC_LIKELY(!mDebugRegion))
|
|
|
|
return;
|
|
|
|
|
|
|
|
const bool repaintEverything = mRepaintEverything;
|
|
|
|
for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
|
|
|
|
const sp<DisplayDevice>& hw(mDisplays[dpy]);
|
2014-05-25 08:36:31 +00:00
|
|
|
if (hw->isDisplayOn()) {
|
2012-08-16 23:28:27 +00:00
|
|
|
// transform the dirty region into this screen's coordinate space
|
|
|
|
const Region dirtyRegion(hw->getDirtyRegion(repaintEverything));
|
|
|
|
if (!dirtyRegion.isEmpty()) {
|
|
|
|
// redraw the whole screen
|
|
|
|
doComposeSurfaces(hw, Region(hw->bounds()));
|
|
|
|
|
|
|
|
// and draw the dirty region
|
|
|
|
const int32_t height = hw->getHeight();
|
2013-08-08 04:24:32 +00:00
|
|
|
RenderEngine& engine(getRenderEngine());
|
|
|
|
engine.fillRegionWithColor(dirtyRegion, height, 1, 0, 1, 1);
|
|
|
|
|
2012-08-16 23:28:27 +00:00
|
|
|
hw->compositionComplete();
|
2012-09-14 01:17:13 +00:00
|
|
|
hw->swapBuffers(getHwComposer());
|
2012-08-16 23:28:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
postFramebuffer();
|
|
|
|
|
|
|
|
if (mDebugRegion > 1) {
|
|
|
|
usleep(mDebugRegion * 1000);
|
|
|
|
}
|
2012-09-25 04:27:29 +00:00
|
|
|
|
|
|
|
HWComposer& hwc(getHwComposer());
|
|
|
|
if (hwc.initCheck() == NO_ERROR) {
|
|
|
|
status_t err = hwc.prepare();
|
|
|
|
ALOGE_IF(err, "HWComposer::prepare failed (%s)", strerror(-err));
|
|
|
|
}
|
2012-08-16 23:28:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SurfaceFlinger::preComposition()
|
|
|
|
{
|
|
|
|
bool needExtraInvalidate = false;
|
2013-06-05 23:59:15 +00:00
|
|
|
const LayerVector& layers(mDrawingState.layersSortedByZ);
|
|
|
|
const size_t count = layers.size();
|
2012-08-16 23:28:27 +00:00
|
|
|
for (size_t i=0 ; i<count ; i++) {
|
2013-06-05 23:59:15 +00:00
|
|
|
if (layers[i]->onPreComposition()) {
|
2012-08-16 23:28:27 +00:00
|
|
|
needExtraInvalidate = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (needExtraInvalidate) {
|
|
|
|
signalLayerUpdate();
|
|
|
|
}
|
|
|
|
}
|
2010-08-11 00:14:02 +00:00
|
|
|
|
2012-08-16 23:28:27 +00:00
|
|
|
void SurfaceFlinger::postComposition()
|
|
|
|
{
|
2013-06-05 23:59:15 +00:00
|
|
|
const LayerVector& layers(mDrawingState.layersSortedByZ);
|
|
|
|
const size_t count = layers.size();
|
2012-08-16 23:28:27 +00:00
|
|
|
for (size_t i=0 ; i<count ; i++) {
|
2013-06-05 23:59:15 +00:00
|
|
|
layers[i]->onPostComposition();
|
2012-08-16 23:28:27 +00:00
|
|
|
}
|
2013-02-05 21:30:24 +00:00
|
|
|
|
2013-07-30 22:10:32 +00:00
|
|
|
const HWComposer& hwc = getHwComposer();
|
|
|
|
sp<Fence> presentFence = hwc.getDisplayFence(HWC_DISPLAY_PRIMARY);
|
|
|
|
|
|
|
|
if (presentFence->isValid()) {
|
|
|
|
if (mPrimaryDispSync.addPresentFence(presentFence)) {
|
|
|
|
enableHardwareVsync();
|
|
|
|
} else {
|
2013-10-14 19:56:09 +00:00
|
|
|
disableHardwareVsync(false);
|
2013-07-30 22:10:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-05 19:05:59 +00:00
|
|
|
const sp<const DisplayDevice> hw(getDefaultDisplayDevice());
|
2014-05-22 20:08:43 +00:00
|
|
|
if (kIgnorePresentFences) {
|
2014-05-25 08:36:31 +00:00
|
|
|
if (hw->isDisplayOn()) {
|
2013-07-30 22:10:32 +00:00
|
|
|
enableHardwareVsync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-05 21:30:24 +00:00
|
|
|
if (mAnimCompositionPending) {
|
|
|
|
mAnimCompositionPending = false;
|
|
|
|
|
2013-02-28 00:39:25 +00:00
|
|
|
if (presentFence->isValid()) {
|
2013-02-05 21:30:24 +00:00
|
|
|
mAnimFrameTracker.setActualPresentFence(presentFence);
|
|
|
|
} else {
|
|
|
|
// The HWC doesn't support present fences, so use the refresh
|
|
|
|
// timestamp instead.
|
|
|
|
nsecs_t presentTime = hwc.getRefreshTimestamp(HWC_DISPLAY_PRIMARY);
|
|
|
|
mAnimFrameTracker.setActualPresentTime(presentTime);
|
|
|
|
}
|
|
|
|
mAnimFrameTracker.advanceFrame();
|
|
|
|
}
|
2015-03-05 19:05:59 +00:00
|
|
|
|
|
|
|
if (hw->getPowerMode() == HWC_POWER_MODE_OFF) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsecs_t currentTime = systemTime();
|
|
|
|
if (mHasPoweredOff) {
|
|
|
|
mHasPoweredOff = false;
|
|
|
|
} else {
|
|
|
|
nsecs_t period = mPrimaryDispSync.getPeriod();
|
|
|
|
nsecs_t elapsedTime = currentTime - mLastSwapTime;
|
|
|
|
size_t numPeriods = static_cast<size_t>(elapsedTime / period);
|
|
|
|
if (numPeriods < NUM_BUCKETS - 1) {
|
|
|
|
mFrameBuckets[numPeriods] += elapsedTime;
|
|
|
|
} else {
|
|
|
|
mFrameBuckets[NUM_BUCKETS - 1] += elapsedTime;
|
|
|
|
}
|
|
|
|
mTotalTime += elapsedTime;
|
|
|
|
}
|
|
|
|
mLastSwapTime = currentTime;
|
2012-08-16 23:28:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SurfaceFlinger::rebuildLayerStacks() {
|
2015-06-23 19:55:15 +00:00
|
|
|
updateExtendedMode();
|
2012-08-16 23:28:27 +00:00
|
|
|
// rebuild the visible layer list per screen
|
2012-08-01 02:01:53 +00:00
|
|
|
if (CC_UNLIKELY(mVisibleRegionsDirty)) {
|
2012-08-16 23:28:27 +00:00
|
|
|
ATRACE_CALL();
|
2012-07-31 19:38:26 +00:00
|
|
|
mVisibleRegionsDirty = false;
|
|
|
|
invalidateHwcGeometry();
|
2012-09-12 22:34:57 +00:00
|
|
|
|
2013-06-05 23:59:15 +00:00
|
|
|
const LayerVector& layers(mDrawingState.layersSortedByZ);
|
2012-08-03 01:32:23 +00:00
|
|
|
for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
|
2012-09-12 22:34:57 +00:00
|
|
|
Region opaqueRegion;
|
|
|
|
Region dirtyRegion;
|
2013-03-06 01:47:11 +00:00
|
|
|
Vector< sp<Layer> > layersSortedByZ;
|
2012-08-05 07:40:46 +00:00
|
|
|
const sp<DisplayDevice>& hw(mDisplays[dpy]);
|
2012-08-28 21:20:00 +00:00
|
|
|
const Transform& tr(hw->getTransform());
|
|
|
|
const Rect bounds(hw->getBounds());
|
2014-05-25 08:36:31 +00:00
|
|
|
if (hw->isDisplayOn()) {
|
2015-06-23 19:55:15 +00:00
|
|
|
computeVisibleRegions(hw->getHwcDisplayId(), layers,
|
2012-09-12 22:34:57 +00:00
|
|
|
hw->getLayerStack(), dirtyRegion, opaqueRegion);
|
2012-08-28 21:20:00 +00:00
|
|
|
|
2013-06-05 23:59:15 +00:00
|
|
|
const size_t count = layers.size();
|
2012-09-12 22:34:57 +00:00
|
|
|
for (size_t i=0 ; i<count ; i++) {
|
2013-06-05 23:59:15 +00:00
|
|
|
const sp<Layer>& layer(layers[i]);
|
2015-06-23 19:55:15 +00:00
|
|
|
{
|
2012-09-25 20:25:04 +00:00
|
|
|
Region drawRegion(tr.transform(
|
|
|
|
layer->visibleNonTransparentRegion));
|
|
|
|
drawRegion.andSelf(bounds);
|
|
|
|
if (!drawRegion.isEmpty()) {
|
2012-09-12 22:34:57 +00:00
|
|
|
layersSortedByZ.add(layer);
|
|
|
|
}
|
2012-07-31 19:38:26 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-11 20:48:17 +00:00
|
|
|
}
|
2012-08-05 07:40:46 +00:00
|
|
|
hw->setVisibleLayersSortedByZ(layersSortedByZ);
|
2012-08-28 21:20:00 +00:00
|
|
|
hw->undefinedRegion.set(bounds);
|
|
|
|
hw->undefinedRegion.subtractSelf(tr.transform(opaqueRegion));
|
|
|
|
hw->dirtyRegion.orSelf(dirtyRegion);
|
2012-07-11 20:48:17 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-16 23:28:27 +00:00
|
|
|
}
|
2012-07-11 20:48:17 +00:00
|
|
|
|
2012-08-16 23:28:27 +00:00
|
|
|
void SurfaceFlinger::setUpHWComposer() {
|
2013-08-20 23:35:32 +00:00
|
|
|
for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
|
2014-08-14 22:45:06 +00:00
|
|
|
bool dirty = !mDisplays[dpy]->getDirtyRegion(false).isEmpty();
|
|
|
|
bool empty = mDisplays[dpy]->getVisibleLayersSortedByZ().size() == 0;
|
|
|
|
bool wasEmpty = !mDisplays[dpy]->lastCompositionHadVisibleLayers;
|
|
|
|
|
|
|
|
// If nothing has changed (!dirty), don't recompose.
|
|
|
|
// If something changed, but we don't currently have any visible layers,
|
|
|
|
// and didn't when we last did a composition, then skip it this time.
|
|
|
|
// The second rule does two things:
|
|
|
|
// - When all layers are removed from a display, we'll emit one black
|
|
|
|
// frame, then nothing more until we get new layers.
|
|
|
|
// - When a display is created with a private layer stack, we won't
|
|
|
|
// emit any black frames until a layer is added to the layer stack.
|
|
|
|
bool mustRecompose = dirty && !(empty && wasEmpty);
|
|
|
|
|
|
|
|
ALOGV_IF(mDisplays[dpy]->getDisplayType() == DisplayDevice::DISPLAY_VIRTUAL,
|
|
|
|
"dpy[%zu]: %s composition (%sdirty %sempty %swasEmpty)", dpy,
|
|
|
|
mustRecompose ? "doing" : "skipping",
|
|
|
|
dirty ? "+" : "-",
|
|
|
|
empty ? "+" : "-",
|
|
|
|
wasEmpty ? "+" : "-");
|
|
|
|
|
2014-02-05 00:22:36 +00:00
|
|
|
mDisplays[dpy]->beginFrame(mustRecompose);
|
2014-08-14 22:45:06 +00:00
|
|
|
|
|
|
|
if (mustRecompose) {
|
|
|
|
mDisplays[dpy]->lastCompositionHadVisibleLayers = !empty;
|
|
|
|
}
|
2013-08-20 23:35:32 +00:00
|
|
|
}
|
|
|
|
|
2012-08-01 02:01:53 +00:00
|
|
|
HWComposer& hwc(getHwComposer());
|
|
|
|
if (hwc.initCheck() == NO_ERROR) {
|
|
|
|
// build the h/w work list
|
2012-09-26 03:26:00 +00:00
|
|
|
if (CC_UNLIKELY(mHwWorkListDirty)) {
|
|
|
|
mHwWorkListDirty = false;
|
|
|
|
for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
|
|
|
|
sp<const DisplayDevice> hw(mDisplays[dpy]);
|
|
|
|
const int32_t id = hw->getHwcDisplayId();
|
|
|
|
if (id >= 0) {
|
2013-03-06 01:47:11 +00:00
|
|
|
const Vector< sp<Layer> >& currentLayers(
|
2012-09-26 03:26:00 +00:00
|
|
|
hw->getVisibleLayersSortedByZ());
|
|
|
|
const size_t count = currentLayers.size();
|
|
|
|
if (hwc.createWorkList(id, count) == NO_ERROR) {
|
|
|
|
HWComposer::LayerListIterator cur = hwc.begin(id);
|
|
|
|
const HWComposer::LayerListIterator end = hwc.end(id);
|
|
|
|
for (size_t i=0 ; cur!=end && i<count ; ++i, ++cur) {
|
2013-03-06 01:47:11 +00:00
|
|
|
const sp<Layer>& layer(currentLayers[i]);
|
2012-09-26 03:26:00 +00:00
|
|
|
layer->setGeometry(hw, *cur);
|
2013-09-13 03:04:35 +00:00
|
|
|
if (mDebugDisableHWC || mDebugRegion || mDaltonize || mHasColorMatrix) {
|
2012-09-26 03:26:00 +00:00
|
|
|
cur->setSkip(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the per-frame data
|
2012-08-03 01:32:23 +00:00
|
|
|
for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
|
2012-08-05 07:40:46 +00:00
|
|
|
sp<const DisplayDevice> hw(mDisplays[dpy]);
|
2012-08-22 06:34:09 +00:00
|
|
|
const int32_t id = hw->getHwcDisplayId();
|
|
|
|
if (id >= 0) {
|
2015-06-23 19:55:15 +00:00
|
|
|
bool freezeSurfacePresent = false;
|
|
|
|
isfreezeSurfacePresent(freezeSurfacePresent, hw, id);
|
2013-03-06 01:47:11 +00:00
|
|
|
const Vector< sp<Layer> >& currentLayers(
|
2012-08-16 23:28:27 +00:00
|
|
|
hw->getVisibleLayersSortedByZ());
|
2012-08-22 06:34:09 +00:00
|
|
|
const size_t count = currentLayers.size();
|
2012-09-26 03:26:00 +00:00
|
|
|
HWComposer::LayerListIterator cur = hwc.begin(id);
|
|
|
|
const HWComposer::LayerListIterator end = hwc.end(id);
|
|
|
|
for (size_t i=0 ; cur!=end && i<count ; ++i, ++cur) {
|
|
|
|
/*
|
|
|
|
* update the per-frame h/w composer data for each layer
|
|
|
|
* and build the transparent region of the FB
|
|
|
|
*/
|
2013-03-06 01:47:11 +00:00
|
|
|
const sp<Layer>& layer(currentLayers[i]);
|
2012-09-26 03:26:00 +00:00
|
|
|
layer->setPerFrameData(hw, *cur);
|
2015-06-23 19:55:15 +00:00
|
|
|
setOrientationEventControl(freezeSurfacePresent,id);
|
2014-07-17 18:36:08 +00:00
|
|
|
if(!strncmp(layer->getName(), "SurfaceView",
|
|
|
|
11)) {
|
|
|
|
lastSurfaceViewLayer = layer;
|
|
|
|
}
|
2012-08-09 01:35:12 +00:00
|
|
|
}
|
2012-08-01 02:01:53 +00:00
|
|
|
}
|
2012-07-31 19:38:26 +00:00
|
|
|
}
|
2012-09-26 03:26:00 +00:00
|
|
|
|
2014-07-01 21:22:59 +00:00
|
|
|
// If possible, attempt to use the cursor overlay on each display.
|
|
|
|
for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
|
|
|
|
sp<const DisplayDevice> hw(mDisplays[dpy]);
|
|
|
|
const int32_t id = hw->getHwcDisplayId();
|
|
|
|
if (id >= 0) {
|
|
|
|
const Vector< sp<Layer> >& currentLayers(
|
|
|
|
hw->getVisibleLayersSortedByZ());
|
|
|
|
const size_t count = currentLayers.size();
|
|
|
|
HWComposer::LayerListIterator cur = hwc.begin(id);
|
|
|
|
const HWComposer::LayerListIterator end = hwc.end(id);
|
|
|
|
for (size_t i=0 ; cur!=end && i<count ; ++i, ++cur) {
|
|
|
|
const sp<Layer>& layer(currentLayers[i]);
|
|
|
|
if (layer->isPotentialCursor()) {
|
|
|
|
cur->setIsCursorLayerHint();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-01 02:01:53 +00:00
|
|
|
status_t err = hwc.prepare();
|
|
|
|
ALOGE_IF(err, "HWComposer::prepare failed (%s)", strerror(-err));
|
2013-04-07 06:12:29 +00:00
|
|
|
|
|
|
|
for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
|
|
|
|
sp<const DisplayDevice> hw(mDisplays[dpy]);
|
|
|
|
hw->prepareFrame(hwc);
|
|
|
|
}
|
2012-08-01 02:01:53 +00:00
|
|
|
}
|
2012-08-16 23:28:27 +00:00
|
|
|
}
|
2012-08-01 02:01:53 +00:00
|
|
|
|
2012-08-16 23:28:27 +00:00
|
|
|
void SurfaceFlinger::doComposition() {
|
|
|
|
ATRACE_CALL();
|
2012-08-01 02:01:53 +00:00
|
|
|
const bool repaintEverything = android_atomic_and(0, &mRepaintEverything);
|
2012-08-03 01:32:23 +00:00
|
|
|
for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
|
2012-08-05 07:40:46 +00:00
|
|
|
const sp<DisplayDevice>& hw(mDisplays[dpy]);
|
2014-05-25 08:36:31 +00:00
|
|
|
if (hw->isDisplayOn()) {
|
2012-08-16 23:28:27 +00:00
|
|
|
// transform the dirty region into this screen's coordinate space
|
|
|
|
const Region dirtyRegion(hw->getDirtyRegion(repaintEverything));
|
2012-11-06 01:50:57 +00:00
|
|
|
|
|
|
|
// repaint the framebuffer (if needed)
|
|
|
|
doDisplayComposition(hw, dirtyRegion);
|
|
|
|
|
2014-12-06 02:28:32 +00:00
|
|
|
++mActiveFrameSequence;
|
|
|
|
|
2012-08-16 23:28:27 +00:00
|
|
|
hw->dirtyRegion.clear();
|
|
|
|
hw->flip(hw->swapRegion);
|
|
|
|
hw->swapRegion.clear();
|
2012-07-31 19:38:26 +00:00
|
|
|
}
|
2012-08-01 02:01:53 +00:00
|
|
|
// inform the h/w that we're done compositing
|
2012-08-05 07:40:46 +00:00
|
|
|
hw->compositionComplete();
|
2012-06-29 21:12:52 +00:00
|
|
|
}
|
2012-08-01 02:01:53 +00:00
|
|
|
postFramebuffer();
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SurfaceFlinger::postFramebuffer()
|
|
|
|
{
|
2012-03-01 23:44:37 +00:00
|
|
|
ATRACE_CALL();
|
2012-02-04 23:44:04 +00:00
|
|
|
|
2011-10-17 01:46:35 +00:00
|
|
|
const nsecs_t now = systemTime();
|
|
|
|
mDebugInSwapBuffers = now;
|
2012-07-02 23:49:28 +00:00
|
|
|
|
2012-08-01 02:01:53 +00:00
|
|
|
HWComposer& hwc(getHwComposer());
|
2012-06-14 21:45:17 +00:00
|
|
|
if (hwc.initCheck() == NO_ERROR) {
|
2012-09-25 01:12:35 +00:00
|
|
|
if (!hwc.supportsFramebufferTarget()) {
|
|
|
|
// EGL spec says:
|
|
|
|
// "surface must be bound to the calling thread's current context,
|
|
|
|
// for the current rendering API."
|
2013-06-07 22:35:48 +00:00
|
|
|
getDefaultDisplayDevice()->makeCurrent(mEGLDisplay, mEGLContext);
|
2012-09-25 01:12:35 +00:00
|
|
|
}
|
2012-08-22 06:34:09 +00:00
|
|
|
hwc.commit();
|
2012-08-01 02:01:53 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 03:40:07 +00:00
|
|
|
// make the default display current because the VirtualDisplayDevice code cannot
|
|
|
|
// deal with dequeueBuffer() being called outside of the composition loop; however
|
|
|
|
// the code below can call glFlush() which is allowed (and does in some case) call
|
|
|
|
// dequeueBuffer().
|
|
|
|
getDefaultDisplayDevice()->makeCurrent(mEGLDisplay, mEGLContext);
|
|
|
|
|
2012-08-03 01:32:23 +00:00
|
|
|
for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
|
2012-08-05 07:40:46 +00:00
|
|
|
sp<const DisplayDevice> hw(mDisplays[dpy]);
|
2013-03-06 01:47:11 +00:00
|
|
|
const Vector< sp<Layer> >& currentLayers(hw->getVisibleLayersSortedByZ());
|
2012-09-14 01:17:13 +00:00
|
|
|
hw->onSwapBuffersCompleted(hwc);
|
2012-08-01 02:01:53 +00:00
|
|
|
const size_t count = currentLayers.size();
|
2012-08-22 06:34:09 +00:00
|
|
|
int32_t id = hw->getHwcDisplayId();
|
|
|
|
if (id >=0 && hwc.initCheck() == NO_ERROR) {
|
2012-08-09 01:35:12 +00:00
|
|
|
HWComposer::LayerListIterator cur = hwc.begin(id);
|
|
|
|
const HWComposer::LayerListIterator end = hwc.end(id);
|
2012-08-01 02:01:53 +00:00
|
|
|
for (size_t i = 0; cur != end && i < count; ++i, ++cur) {
|
2012-08-02 21:01:42 +00:00
|
|
|
currentLayers[i]->onLayerDisplayed(hw, &*cur);
|
2012-08-01 02:01:53 +00:00
|
|
|
}
|
2012-08-16 23:28:27 +00:00
|
|
|
} else {
|
2012-08-01 02:01:53 +00:00
|
|
|
for (size_t i = 0; i < count; i++) {
|
2012-08-02 21:01:42 +00:00
|
|
|
currentLayers[i]->onLayerDisplayed(hw, NULL);
|
2012-08-01 02:01:53 +00:00
|
|
|
}
|
2012-06-14 21:45:17 +00:00
|
|
|
}
|
2012-01-16 02:54:57 +00:00
|
|
|
}
|
|
|
|
|
2011-10-17 01:46:35 +00:00
|
|
|
mLastSwapBufferTime = systemTime() - now;
|
|
|
|
mDebugInSwapBuffers = 0;
|
2013-07-17 03:12:42 +00:00
|
|
|
|
|
|
|
uint32_t flipCount = getDefaultDisplayDevice()->getPageFlipCount();
|
|
|
|
if (flipCount % LOG_FRAME_STATS_PERIOD == 0) {
|
|
|
|
logFrameStats();
|
|
|
|
}
|
2014-12-06 02:28:32 +00:00
|
|
|
ALOGV_IF(mFrameRateHelper.update(), "FPS: %d", mFrameRateHelper.get());
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2012-07-31 19:38:26 +00:00
|
|
|
void SurfaceFlinger::handleTransaction(uint32_t transactionFlags)
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2012-03-01 23:44:37 +00:00
|
|
|
ATRACE_CALL();
|
|
|
|
|
2013-06-05 21:30:54 +00:00
|
|
|
// here we keep a copy of the drawing state (that is the state that's
|
|
|
|
// going to be overwritten by handleTransactionLocked()) outside of
|
|
|
|
// mStateLock so that the side-effects of the State assignment
|
|
|
|
// don't happen with mStateLock held (which can cause deadlocks).
|
|
|
|
State drawingState(mDrawingState);
|
|
|
|
|
2011-05-19 22:38:14 +00:00
|
|
|
Mutex::Autolock _l(mStateLock);
|
|
|
|
const nsecs_t now = systemTime();
|
|
|
|
mDebugInTransaction = now;
|
|
|
|
|
|
|
|
// Here we're guaranteed that some transaction flags are set
|
|
|
|
// so we can call handleTransactionLocked() unconditionally.
|
|
|
|
// We call getTransactionFlags(), which will also clear the flags,
|
|
|
|
// with mStateLock held to guarantee that mCurrentState won't change
|
|
|
|
// until the transaction is committed.
|
|
|
|
|
2012-08-09 23:29:12 +00:00
|
|
|
transactionFlags = getTransactionFlags(eTransactionMask);
|
2012-07-31 19:38:26 +00:00
|
|
|
handleTransactionLocked(transactionFlags);
|
2011-05-19 22:38:14 +00:00
|
|
|
|
|
|
|
mLastTransactionTime = systemTime() - now;
|
|
|
|
mDebugInTransaction = 0;
|
|
|
|
invalidateHwcGeometry();
|
|
|
|
// here the transaction has been committed
|
2009-06-05 01:46:21 +00:00
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2012-07-31 19:38:26 +00:00
|
|
|
void SurfaceFlinger::handleTransactionLocked(uint32_t transactionFlags)
|
2009-06-05 01:46:21 +00:00
|
|
|
{
|
|
|
|
const LayerVector& currentLayers(mCurrentState.layersSortedByZ);
|
2009-03-04 03:31:44 +00:00
|
|
|
const size_t count = currentLayers.size();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Traversal of the children
|
|
|
|
* (perform the transaction for each of them if needed)
|
|
|
|
*/
|
|
|
|
|
2012-08-15 20:46:03 +00:00
|
|
|
if (transactionFlags & eTraversalNeeded) {
|
2009-03-04 03:31:44 +00:00
|
|
|
for (size_t i=0 ; i<count ; i++) {
|
2013-03-06 01:47:11 +00:00
|
|
|
const sp<Layer>& layer(currentLayers[i]);
|
2009-03-04 03:31:44 +00:00
|
|
|
uint32_t trFlags = layer->getTransactionFlags(eTransactionNeeded);
|
|
|
|
if (!trFlags) continue;
|
|
|
|
|
|
|
|
const uint32_t flags = layer->doTransaction(0);
|
|
|
|
if (flags & Layer::eVisibleRegion)
|
|
|
|
mVisibleRegionsDirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-08-15 20:46:03 +00:00
|
|
|
* Perform display own transactions if needed
|
2009-03-04 03:31:44 +00:00
|
|
|
*/
|
|
|
|
|
2012-08-09 23:29:12 +00:00
|
|
|
if (transactionFlags & eDisplayTransactionNeeded) {
|
2012-08-03 01:32:23 +00:00
|
|
|
// here we take advantage of Vector's copy-on-write semantics to
|
|
|
|
// improve performance by skipping the transaction entirely when
|
|
|
|
// know that the lists are identical
|
2012-08-09 23:29:12 +00:00
|
|
|
const KeyedVector< wp<IBinder>, DisplayDeviceState>& curr(mCurrentState.displays);
|
|
|
|
const KeyedVector< wp<IBinder>, DisplayDeviceState>& draw(mDrawingState.displays);
|
2012-08-03 01:32:23 +00:00
|
|
|
if (!curr.isIdenticalTo(draw)) {
|
2009-03-04 03:31:44 +00:00
|
|
|
mVisibleRegionsDirty = true;
|
2012-08-03 01:32:23 +00:00
|
|
|
const size_t cc = curr.size();
|
2012-08-30 00:30:36 +00:00
|
|
|
size_t dc = draw.size();
|
2012-08-03 01:32:23 +00:00
|
|
|
|
|
|
|
// find the displays that were removed
|
|
|
|
// (ie: in drawing state but not in current state)
|
|
|
|
// also handle displays that changed
|
|
|
|
// (ie: displays that are in both lists)
|
|
|
|
for (size_t i=0 ; i<dc ; i++) {
|
2012-08-09 23:29:12 +00:00
|
|
|
const ssize_t j = curr.indexOfKey(draw.keyAt(i));
|
|
|
|
if (j < 0) {
|
2012-08-03 01:32:23 +00:00
|
|
|
// in drawing state but not in current state
|
2012-08-27 23:28:24 +00:00
|
|
|
if (!draw[i].isMainDisplay()) {
|
2012-10-03 02:04:45 +00:00
|
|
|
// Call makeCurrent() on the primary display so we can
|
|
|
|
// be sure that nothing associated with this display
|
|
|
|
// is current.
|
2013-03-25 21:43:23 +00:00
|
|
|
const sp<const DisplayDevice> defaultDisplay(getDefaultDisplayDevice());
|
2013-06-07 22:35:48 +00:00
|
|
|
defaultDisplay->makeCurrent(mEGLDisplay, mEGLContext);
|
2013-03-25 21:43:23 +00:00
|
|
|
sp<DisplayDevice> hw(getDisplayDevice(draw.keyAt(i)));
|
|
|
|
if (hw != NULL)
|
|
|
|
hw->disconnect(getHwComposer());
|
2013-08-16 21:28:37 +00:00
|
|
|
if (draw[i].type < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES)
|
2013-03-07 00:13:49 +00:00
|
|
|
mEventThread->onHotplugReceived(draw[i].type, false);
|
2013-03-25 21:43:23 +00:00
|
|
|
mDisplays.removeItem(draw.keyAt(i));
|
2012-08-03 01:32:23 +00:00
|
|
|
} else {
|
|
|
|
ALOGW("trying to remove the main display");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// this display is in both lists. see if something changed.
|
2012-08-09 23:29:12 +00:00
|
|
|
const DisplayDeviceState& state(curr[j]);
|
2012-08-27 23:28:24 +00:00
|
|
|
const wp<IBinder>& display(curr.keyAt(j));
|
2014-11-14 16:01:01 +00:00
|
|
|
const sp<IBinder> state_binder = IInterface::asBinder(state.surface);
|
|
|
|
const sp<IBinder> draw_binder = IInterface::asBinder(draw[i].surface);
|
2014-09-09 01:59:09 +00:00
|
|
|
if (state_binder != draw_binder) {
|
2012-08-09 23:29:12 +00:00
|
|
|
// changing the surface is like destroying and
|
2012-08-30 00:30:36 +00:00
|
|
|
// recreating the DisplayDevice, so we just remove it
|
|
|
|
// from the drawing state, so that it get re-added
|
|
|
|
// below.
|
2013-03-25 21:43:23 +00:00
|
|
|
sp<DisplayDevice> hw(getDisplayDevice(display));
|
|
|
|
if (hw != NULL)
|
|
|
|
hw->disconnect(getHwComposer());
|
2012-08-30 00:30:36 +00:00
|
|
|
mDisplays.removeItem(display);
|
|
|
|
mDrawingState.displays.removeItemsAt(i);
|
|
|
|
dc--; i--;
|
|
|
|
// at this point we must loop to the next item
|
|
|
|
continue;
|
2012-08-03 01:32:23 +00:00
|
|
|
}
|
2012-08-30 00:30:36 +00:00
|
|
|
|
2012-10-15 23:51:41 +00:00
|
|
|
const sp<DisplayDevice> disp(getDisplayDevice(display));
|
2012-08-30 00:30:36 +00:00
|
|
|
if (disp != NULL) {
|
|
|
|
if (state.layerStack != draw[i].layerStack) {
|
|
|
|
disp->setLayerStack(state.layerStack);
|
|
|
|
}
|
2012-09-05 02:30:46 +00:00
|
|
|
if ((state.orientation != draw[i].orientation)
|
|
|
|
|| (state.viewport != draw[i].viewport)
|
|
|
|
|| (state.frame != draw[i].frame))
|
|
|
|
{
|
|
|
|
disp->setProjection(state.orientation,
|
2012-09-07 19:55:10 +00:00
|
|
|
state.viewport, state.frame);
|
2012-08-30 00:30:36 +00:00
|
|
|
}
|
2014-07-18 22:34:25 +00:00
|
|
|
if (state.width != draw[i].width || state.height != draw[i].height) {
|
|
|
|
disp->setDisplaySize(state.width, state.height);
|
|
|
|
}
|
2012-08-03 01:32:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// find displays that were added
|
|
|
|
// (ie: in current state but not in drawing state)
|
|
|
|
for (size_t i=0 ; i<cc ; i++) {
|
2012-08-09 23:29:12 +00:00
|
|
|
if (draw.indexOfKey(curr.keyAt(i)) < 0) {
|
|
|
|
const DisplayDeviceState& state(curr[i]);
|
2012-09-13 21:09:01 +00:00
|
|
|
|
2013-03-14 21:29:29 +00:00
|
|
|
sp<DisplaySurface> dispSurface;
|
2013-08-02 08:40:18 +00:00
|
|
|
sp<IGraphicBufferProducer> producer;
|
2014-03-13 18:55:57 +00:00
|
|
|
sp<IGraphicBufferProducer> bqProducer;
|
|
|
|
sp<IGraphicBufferConsumer> bqConsumer;
|
|
|
|
BufferQueue::createBufferQueue(&bqProducer, &bqConsumer,
|
|
|
|
new GraphicBufferAlloc());
|
2013-08-02 08:40:18 +00:00
|
|
|
|
2013-03-25 21:43:23 +00:00
|
|
|
int32_t hwcDisplayId = -1;
|
2013-03-14 21:29:29 +00:00
|
|
|
if (state.isVirtualDisplay()) {
|
2013-03-25 21:43:23 +00:00
|
|
|
// Virtual displays without a surface are dormant:
|
|
|
|
// they have external state (layer stack, projection,
|
|
|
|
// etc.) but no internal state (i.e. a DisplayDevice).
|
2013-03-14 21:29:29 +00:00
|
|
|
if (state.surface != NULL) {
|
2013-08-02 08:40:18 +00:00
|
|
|
|
2014-10-15 23:34:55 +00:00
|
|
|
int width = 0;
|
2015-10-02 21:53:50 +00:00
|
|
|
DisplayUtils* displayUtils = DisplayUtils::getInstance();
|
2014-10-15 23:34:55 +00:00
|
|
|
int status = state.surface->query(
|
|
|
|
NATIVE_WINDOW_WIDTH, &width);
|
|
|
|
ALOGE_IF(status != NO_ERROR,
|
|
|
|
"Unable to query width (%d)", status);
|
|
|
|
int height = 0;
|
|
|
|
status = state.surface->query(
|
|
|
|
NATIVE_WINDOW_HEIGHT, &height);
|
|
|
|
ALOGE_IF(status != NO_ERROR,
|
|
|
|
"Unable to query height (%d)", status);
|
|
|
|
if (MAX_VIRTUAL_DISPLAY_DIMENSION == 0 ||
|
|
|
|
(width <= MAX_VIRTUAL_DISPLAY_DIMENSION &&
|
|
|
|
height <= MAX_VIRTUAL_DISPLAY_DIMENSION)) {
|
2015-10-02 21:53:50 +00:00
|
|
|
int usage = 0;
|
|
|
|
status = state.surface->query(
|
|
|
|
NATIVE_WINDOW_CONSUMER_USAGE_BITS, &usage);
|
|
|
|
ALOGW_IF(status != NO_ERROR,
|
|
|
|
"Unable to query usage (%d)", status);
|
|
|
|
if ( (status == NO_ERROR) &&
|
|
|
|
displayUtils->canAllocateHwcDisplayIdForVDS(usage)) {
|
|
|
|
hwcDisplayId = allocateHwcDisplayId(state.type);
|
|
|
|
}
|
2014-10-15 23:34:55 +00:00
|
|
|
}
|
|
|
|
|
2015-10-02 21:53:50 +00:00
|
|
|
displayUtils->initVDSInstance(mHwc, hwcDisplayId, state.surface,
|
|
|
|
dispSurface, producer, bqProducer, bqConsumer,
|
2015-08-12 10:55:05 +00:00
|
|
|
state.displayName, state.isSecure, state.type);
|
2013-08-02 08:40:18 +00:00
|
|
|
|
2013-03-14 21:29:29 +00:00
|
|
|
}
|
|
|
|
} else {
|
2012-09-13 21:09:01 +00:00
|
|
|
ALOGE_IF(state.surface!=NULL,
|
|
|
|
"adding a supported display, but rendering "
|
|
|
|
"surface is provided (%p), ignoring it",
|
|
|
|
state.surface.get());
|
2013-03-25 21:43:23 +00:00
|
|
|
hwcDisplayId = allocateHwcDisplayId(state.type);
|
2012-09-13 21:09:01 +00:00
|
|
|
// for supported (by hwc) displays we provide our
|
|
|
|
// own rendering surface
|
2014-03-13 18:55:57 +00:00
|
|
|
dispSurface = new FramebufferSurface(*mHwc, state.type,
|
|
|
|
bqConsumer);
|
|
|
|
producer = bqProducer;
|
2012-09-13 21:09:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const wp<IBinder>& display(curr.keyAt(i));
|
2015-08-12 10:55:05 +00:00
|
|
|
if (dispSurface != NULL && producer != NULL) {
|
2012-09-13 21:09:01 +00:00
|
|
|
sp<DisplayDevice> hw = new DisplayDevice(this,
|
2013-12-24 05:02:15 +00:00
|
|
|
state.type, hwcDisplayId,
|
|
|
|
mHwc->getFormat(hwcDisplayId), state.isSecure,
|
2013-12-24 04:44:38 +00:00
|
|
|
display, dispSurface, producer,
|
|
|
|
mRenderEngine->getEGLConfig());
|
2012-09-13 21:09:01 +00:00
|
|
|
hw->setLayerStack(state.layerStack);
|
|
|
|
hw->setProjection(state.orientation,
|
2012-09-07 19:55:10 +00:00
|
|
|
state.viewport, state.frame);
|
2012-09-18 01:27:17 +00:00
|
|
|
hw->setDisplayName(state.displayName);
|
2014-09-22 23:57:24 +00:00
|
|
|
// When a new display device is added update the active
|
|
|
|
// config by querying HWC otherwise the default config
|
|
|
|
// (config 0) will be used.
|
|
|
|
if (hwcDisplayId >= DisplayDevice::DISPLAY_PRIMARY &&
|
|
|
|
hwcDisplayId < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES) {
|
|
|
|
int activeConfig = mHwc->getActiveConfig(hwcDisplayId);
|
|
|
|
if (activeConfig >= 0) {
|
|
|
|
hw->setActiveConfig(activeConfig);
|
|
|
|
}
|
|
|
|
}
|
2012-09-13 21:09:01 +00:00
|
|
|
mDisplays.add(display, hw);
|
2013-04-05 20:44:52 +00:00
|
|
|
if (state.isVirtualDisplay()) {
|
|
|
|
if (hwcDisplayId >= 0) {
|
|
|
|
mHwc->setVirtualDisplayProperties(hwcDisplayId,
|
|
|
|
hw->getWidth(), hw->getHeight(),
|
|
|
|
hw->getFormat());
|
|
|
|
}
|
|
|
|
} else {
|
2013-03-07 00:13:49 +00:00
|
|
|
mEventThread->onHotplugReceived(state.type, true);
|
2013-04-05 20:44:52 +00:00
|
|
|
}
|
2012-08-30 00:30:36 +00:00
|
|
|
}
|
2012-08-03 01:32:23 +00:00
|
|
|
}
|
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
2012-08-15 20:46:03 +00:00
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2012-11-22 00:02:13 +00:00
|
|
|
if (transactionFlags & (eTraversalNeeded|eDisplayTransactionNeeded)) {
|
|
|
|
// The transform hint might have changed for some layers
|
|
|
|
// (either because a display has changed, or because a layer
|
|
|
|
// as changed).
|
|
|
|
//
|
|
|
|
// Walk through all the layers in currentLayers,
|
|
|
|
// and update their transform hint.
|
|
|
|
//
|
|
|
|
// If a layer is visible only on a single display, then that
|
|
|
|
// display is used to calculate the hint, otherwise we use the
|
|
|
|
// default display.
|
|
|
|
//
|
|
|
|
// NOTE: we do this here, rather than in rebuildLayerStacks() so that
|
|
|
|
// the hint is set before we acquire a buffer from the surface texture.
|
|
|
|
//
|
|
|
|
// NOTE: layer transactions have taken place already, so we use their
|
|
|
|
// drawing state. However, SurfaceFlinger's own transaction has not
|
|
|
|
// happened yet, so we must use the current state layer list
|
|
|
|
// (soon to become the drawing state list).
|
|
|
|
//
|
|
|
|
sp<const DisplayDevice> disp;
|
|
|
|
uint32_t currentlayerStack = 0;
|
|
|
|
for (size_t i=0; i<count; i++) {
|
|
|
|
// NOTE: we rely on the fact that layers are sorted by
|
|
|
|
// layerStack first (so we don't have to traverse the list
|
|
|
|
// of displays for every layer).
|
2013-03-06 01:47:11 +00:00
|
|
|
const sp<Layer>& layer(currentLayers[i]);
|
2013-06-05 23:59:15 +00:00
|
|
|
uint32_t layerStack = layer->getDrawingState().layerStack;
|
2012-11-22 00:02:13 +00:00
|
|
|
if (i==0 || currentlayerStack != layerStack) {
|
|
|
|
currentlayerStack = layerStack;
|
|
|
|
// figure out if this layerstack is mirrored
|
|
|
|
// (more than one display) if so, pick the default display,
|
|
|
|
// if not, pick the only display it's on.
|
|
|
|
disp.clear();
|
|
|
|
for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
|
|
|
|
sp<const DisplayDevice> hw(mDisplays[dpy]);
|
|
|
|
if (hw->getLayerStack() == currentlayerStack) {
|
|
|
|
if (disp == NULL) {
|
|
|
|
disp = hw;
|
|
|
|
} else {
|
2013-04-11 22:24:55 +00:00
|
|
|
disp = NULL;
|
2012-11-22 00:02:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-11 22:24:55 +00:00
|
|
|
if (disp == NULL) {
|
|
|
|
// NOTE: TEMPORARY FIX ONLY. Real fix should cause layers to
|
|
|
|
// redraw after transform hint changes. See bug 8508397.
|
|
|
|
|
|
|
|
// could be null when this layer is using a layerStack
|
|
|
|
// that is not visible on any display. Also can occur at
|
|
|
|
// screen off/on times.
|
|
|
|
disp = getDefaultDisplayDevice();
|
2012-11-22 00:02:13 +00:00
|
|
|
}
|
2013-04-11 22:24:55 +00:00
|
|
|
layer->updateTransformHint(disp);
|
2012-11-22 00:02:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-15 20:46:03 +00:00
|
|
|
/*
|
|
|
|
* Perform our own transaction if needed
|
|
|
|
*/
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2013-06-05 23:59:15 +00:00
|
|
|
const LayerVector& layers(mDrawingState.layersSortedByZ);
|
|
|
|
if (currentLayers.size() > layers.size()) {
|
2012-08-15 20:46:03 +00:00
|
|
|
// layers have been added
|
|
|
|
mVisibleRegionsDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// some layers might have been removed, so
|
|
|
|
// we need to update the regions they're exposing.
|
|
|
|
if (mLayersRemoved) {
|
|
|
|
mLayersRemoved = false;
|
|
|
|
mVisibleRegionsDirty = true;
|
2013-06-05 23:59:15 +00:00
|
|
|
const size_t count = layers.size();
|
2012-08-15 20:46:03 +00:00
|
|
|
for (size_t i=0 ; i<count ; i++) {
|
2013-06-05 23:59:15 +00:00
|
|
|
const sp<Layer>& layer(layers[i]);
|
2012-08-15 20:46:03 +00:00
|
|
|
if (currentLayers.indexOf(layer) < 0) {
|
|
|
|
// this layer is not visible anymore
|
|
|
|
// TODO: we could traverse the tree from front to back and
|
|
|
|
// compute the actual visible region
|
|
|
|
// TODO: we could cache the transformed region
|
2013-06-05 23:59:15 +00:00
|
|
|
const Layer::State& s(layer->getDrawingState());
|
2012-09-05 04:04:09 +00:00
|
|
|
Region visibleReg = s.transform.transform(
|
|
|
|
Region(Rect(s.active.w, s.active.h)));
|
|
|
|
invalidateLayerStack(s.layerStack, visibleReg);
|
2009-04-22 22:23:34 +00:00
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
commitTransaction();
|
2014-07-01 21:22:59 +00:00
|
|
|
|
|
|
|
updateCursorAsync();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SurfaceFlinger::updateCursorAsync()
|
|
|
|
{
|
|
|
|
HWComposer& hwc(getHwComposer());
|
|
|
|
for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
|
|
|
|
sp<const DisplayDevice> hw(mDisplays[dpy]);
|
|
|
|
const int32_t id = hw->getHwcDisplayId();
|
|
|
|
if (id < 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const Vector< sp<Layer> >& currentLayers(
|
|
|
|
hw->getVisibleLayersSortedByZ());
|
|
|
|
const size_t count = currentLayers.size();
|
|
|
|
HWComposer::LayerListIterator cur = hwc.begin(id);
|
|
|
|
const HWComposer::LayerListIterator end = hwc.end(id);
|
|
|
|
for (size_t i=0 ; cur!=end && i<count ; ++i, ++cur) {
|
|
|
|
if (cur->getCompositionType() != HWC_CURSOR_OVERLAY) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const sp<Layer>& layer(currentLayers[i]);
|
|
|
|
Rect cursorPos = layer->getPosition(hw);
|
|
|
|
hwc.setCursorPositionAsync(id, cursorPos);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-06-29 21:12:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SurfaceFlinger::commitTransaction()
|
|
|
|
{
|
|
|
|
if (!mLayersPendingRemoval.isEmpty()) {
|
|
|
|
// Notify removed layers now that they can't be drawn from
|
|
|
|
for (size_t i = 0; i < mLayersPendingRemoval.size(); i++) {
|
|
|
|
mLayersPendingRemoval[i]->onRemoved();
|
|
|
|
}
|
|
|
|
mLayersPendingRemoval.clear();
|
|
|
|
}
|
|
|
|
|
2013-02-05 21:30:24 +00:00
|
|
|
// If this transaction is part of a window animation then the next frame
|
|
|
|
// we composite should be considered an animation as well.
|
|
|
|
mAnimCompositionPending = mAnimTransactionPending;
|
|
|
|
|
2012-06-29 21:12:52 +00:00
|
|
|
mDrawingState = mCurrentState;
|
2012-10-16 01:24:43 +00:00
|
|
|
mTransactionPending = false;
|
|
|
|
mAnimTransactionPending = false;
|
2012-06-29 21:12:52 +00:00
|
|
|
mTransactionCV.broadcast();
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2015-06-23 19:55:15 +00:00
|
|
|
void SurfaceFlinger::computeVisibleRegions(size_t dpy,
|
2012-07-31 19:38:26 +00:00
|
|
|
const LayerVector& currentLayers, uint32_t layerStack,
|
|
|
|
Region& outDirtyRegion, Region& outOpaqueRegion)
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2012-03-01 23:44:37 +00:00
|
|
|
ATRACE_CALL();
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
Region aboveOpaqueLayers;
|
|
|
|
Region aboveCoveredLayers;
|
|
|
|
Region dirty;
|
|
|
|
|
2012-07-31 19:38:26 +00:00
|
|
|
outDirtyRegion.clear();
|
2015-06-23 19:55:15 +00:00
|
|
|
bool bIgnoreLayers = false;
|
|
|
|
int indexLOI = -1;
|
|
|
|
getIndexLOI(dpy, currentLayers, bIgnoreLayers, indexLOI);
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
size_t i = currentLayers.size();
|
|
|
|
while (i--) {
|
2013-03-06 01:47:11 +00:00
|
|
|
const sp<Layer>& layer = currentLayers[i];
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
// start with the whole surface at its current location
|
2013-06-05 23:59:15 +00:00
|
|
|
const Layer::State& s(layer->getDrawingState());
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2015-06-23 19:55:15 +00:00
|
|
|
if(updateLayerVisibleNonTransparentRegion(dpy, layer,
|
|
|
|
bIgnoreLayers, indexLOI,
|
|
|
|
layerStack, i))
|
2012-07-31 19:38:26 +00:00
|
|
|
continue;
|
|
|
|
|
2010-03-16 23:41:46 +00:00
|
|
|
/*
|
|
|
|
* opaqueRegion: area of a surface that is fully opaque.
|
|
|
|
*/
|
2009-03-04 03:31:44 +00:00
|
|
|
Region opaqueRegion;
|
2010-03-16 23:41:46 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* visibleRegion: area of a surface that is visible on screen
|
|
|
|
* and not fully transparent. This is essentially the layer's
|
|
|
|
* footprint minus the opaque regions above it.
|
|
|
|
* Areas covered by a translucent surface are considered visible.
|
|
|
|
*/
|
2009-03-04 03:31:44 +00:00
|
|
|
Region visibleRegion;
|
2010-03-16 23:41:46 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* coveredRegion: area of a surface that is covered by all
|
|
|
|
* visible regions above it (which includes the translucent areas).
|
|
|
|
*/
|
2009-03-04 03:31:44 +00:00
|
|
|
Region coveredRegion;
|
2010-03-16 23:41:46 +00:00
|
|
|
|
2012-09-25 20:25:04 +00:00
|
|
|
/*
|
|
|
|
* transparentRegion: area of a surface that is hinted to be completely
|
|
|
|
* transparent. This is only used to tell when the layer has no visible
|
|
|
|
* non-transparent regions and can be removed from the layer list. It
|
|
|
|
* does not affect the visibleRegion of this layer or any layers
|
|
|
|
* beneath it. The hint may not be correct if apps don't respect the
|
|
|
|
* SurfaceView restrictions (which, sadly, some don't).
|
|
|
|
*/
|
|
|
|
Region transparentRegion;
|
|
|
|
|
2010-03-16 23:41:46 +00:00
|
|
|
|
|
|
|
// handle hidden surfaces by setting the visible region to empty
|
2012-09-14 01:17:13 +00:00
|
|
|
if (CC_LIKELY(layer->isVisible())) {
|
2014-01-30 01:17:11 +00:00
|
|
|
const bool translucent = !layer->isOpaque(s);
|
2013-02-27 00:37:53 +00:00
|
|
|
Rect bounds(s.transform.transform(layer->computeBounds()));
|
2009-03-04 03:31:44 +00:00
|
|
|
visibleRegion.set(bounds);
|
2010-03-16 23:41:46 +00:00
|
|
|
if (!visibleRegion.isEmpty()) {
|
|
|
|
// Remove the transparent area from the visible region
|
|
|
|
if (translucent) {
|
2012-06-29 21:12:52 +00:00
|
|
|
const Transform tr(s.transform);
|
|
|
|
if (tr.transformed()) {
|
|
|
|
if (tr.preserveRects()) {
|
|
|
|
// transform the transparent region
|
2013-04-03 01:30:32 +00:00
|
|
|
transparentRegion = tr.transform(s.activeTransparentRegion);
|
2012-06-29 21:12:52 +00:00
|
|
|
} else {
|
|
|
|
// transformation too complex, can't do the
|
|
|
|
// transparent region optimization.
|
2012-09-25 20:25:04 +00:00
|
|
|
transparentRegion.clear();
|
2012-06-29 21:12:52 +00:00
|
|
|
}
|
|
|
|
} else {
|
2013-04-03 01:30:32 +00:00
|
|
|
transparentRegion = s.activeTransparentRegion;
|
2012-06-29 21:12:52 +00:00
|
|
|
}
|
2010-03-16 23:41:46 +00:00
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2010-03-16 23:41:46 +00:00
|
|
|
// compute the opaque region
|
2012-06-29 21:12:52 +00:00
|
|
|
const int32_t layerOrientation = s.transform.getOrientation();
|
2010-03-16 23:41:46 +00:00
|
|
|
if (s.alpha==255 && !translucent &&
|
|
|
|
((layerOrientation & Transform::ROT_INVALID) == false)) {
|
|
|
|
// the opaque region is the layer's footprint
|
|
|
|
opaqueRegion = visibleRegion;
|
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-16 23:41:46 +00:00
|
|
|
// Clip the covered region to the visible region
|
|
|
|
coveredRegion = aboveCoveredLayers.intersect(visibleRegion);
|
|
|
|
|
|
|
|
// Update aboveCoveredLayers for next (lower) layer
|
|
|
|
aboveCoveredLayers.orSelf(visibleRegion);
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
// subtract the opaque region covered by the layers above us
|
|
|
|
visibleRegion.subtractSelf(aboveOpaqueLayers);
|
|
|
|
|
|
|
|
// compute this layer's dirty region
|
|
|
|
if (layer->contentDirty) {
|
|
|
|
// we need to invalidate the whole region
|
|
|
|
dirty = visibleRegion;
|
|
|
|
// as well, as the old visible region
|
2012-06-29 21:12:52 +00:00
|
|
|
dirty.orSelf(layer->visibleRegion);
|
2009-03-04 03:31:44 +00:00
|
|
|
layer->contentDirty = false;
|
|
|
|
} else {
|
2009-06-28 09:54:16 +00:00
|
|
|
/* compute the exposed region:
|
2010-03-16 23:41:46 +00:00
|
|
|
* the exposed region consists of two components:
|
|
|
|
* 1) what's VISIBLE now and was COVERED before
|
|
|
|
* 2) what's EXPOSED now less what was EXPOSED before
|
|
|
|
*
|
|
|
|
* note that (1) is conservative, we start with the whole
|
|
|
|
* visible region but only keep what used to be covered by
|
|
|
|
* something -- which mean it may have been exposed.
|
|
|
|
*
|
|
|
|
* (2) handles areas that were not covered by anything but got
|
|
|
|
* exposed because of a resize.
|
2009-06-28 09:54:16 +00:00
|
|
|
*/
|
2010-03-16 23:41:46 +00:00
|
|
|
const Region newExposed = visibleRegion - coveredRegion;
|
2012-06-29 21:12:52 +00:00
|
|
|
const Region oldVisibleRegion = layer->visibleRegion;
|
|
|
|
const Region oldCoveredRegion = layer->coveredRegion;
|
2010-03-16 23:41:46 +00:00
|
|
|
const Region oldExposed = oldVisibleRegion - oldCoveredRegion;
|
|
|
|
dirty = (visibleRegion&oldCoveredRegion) | (newExposed-oldExposed);
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
dirty.subtractSelf(aboveOpaqueLayers);
|
|
|
|
|
|
|
|
// accumulate to the screen dirty region
|
2012-07-31 19:38:26 +00:00
|
|
|
outDirtyRegion.orSelf(dirty);
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2010-03-16 23:41:46 +00:00
|
|
|
// Update aboveOpaqueLayers for next (lower) layer
|
2009-03-04 03:31:44 +00:00
|
|
|
aboveOpaqueLayers.orSelf(opaqueRegion);
|
2010-08-16 15:49:37 +00:00
|
|
|
|
2012-09-25 20:25:04 +00:00
|
|
|
// Store the visible region in screen space
|
2009-03-04 03:31:44 +00:00
|
|
|
layer->setVisibleRegion(visibleRegion);
|
|
|
|
layer->setCoveredRegion(coveredRegion);
|
2012-09-25 20:25:04 +00:00
|
|
|
layer->setVisibleNonTransparentRegion(
|
|
|
|
visibleRegion.subtract(transparentRegion));
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2012-07-31 19:38:26 +00:00
|
|
|
outOpaqueRegion = aboveOpaqueLayers;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2012-07-31 19:38:26 +00:00
|
|
|
void SurfaceFlinger::invalidateLayerStack(uint32_t layerStack,
|
|
|
|
const Region& dirty) {
|
2012-08-03 01:32:23 +00:00
|
|
|
for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
|
2012-08-05 07:40:46 +00:00
|
|
|
const sp<DisplayDevice>& hw(mDisplays[dpy]);
|
|
|
|
if (hw->getLayerStack() == layerStack) {
|
|
|
|
hw->dirtyRegion.orSelf(dirty);
|
2012-08-03 01:32:23 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-31 19:38:26 +00:00
|
|
|
}
|
|
|
|
|
2014-11-08 00:00:59 +00:00
|
|
|
bool SurfaceFlinger::handlePageFlip()
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2012-06-29 21:12:52 +00:00
|
|
|
Region dirtyRegion;
|
2012-02-01 02:24:27 +00:00
|
|
|
|
2012-06-29 21:12:52 +00:00
|
|
|
bool visibleRegions = false;
|
2013-06-05 23:59:15 +00:00
|
|
|
const LayerVector& layers(mDrawingState.layersSortedByZ);
|
2014-11-08 00:00:59 +00:00
|
|
|
bool frameQueued = false;
|
2014-07-29 02:51:58 +00:00
|
|
|
|
|
|
|
// Store the set of layers that need updates. This set must not change as
|
|
|
|
// buffers are being latched, as this could result in a deadlock.
|
|
|
|
// Example: Two producers share the same command stream and:
|
|
|
|
// 1.) Layer 0 is latched
|
|
|
|
// 2.) Layer 0 gets a new frame
|
|
|
|
// 2.) Layer 1 gets a new frame
|
|
|
|
// 3.) Layer 1 is latched.
|
|
|
|
// Display is now waiting on Layer 1's frame, which is behind layer 0's
|
|
|
|
// second frame. But layer 0's second frame could be waiting on display.
|
|
|
|
Vector<Layer*> layersWithQueuedFrames;
|
|
|
|
for (size_t i = 0, count = layers.size(); i<count ; i++) {
|
2013-06-05 23:59:15 +00:00
|
|
|
const sp<Layer>& layer(layers[i]);
|
2014-11-08 00:00:59 +00:00
|
|
|
if (layer->hasQueuedFrame()) {
|
|
|
|
frameQueued = true;
|
|
|
|
if (layer->shouldPresentNow(mPrimaryDispSync)) {
|
|
|
|
layersWithQueuedFrames.push_back(layer.get());
|
2015-03-23 22:50:23 +00:00
|
|
|
} else {
|
|
|
|
layer->useEmptyDamage();
|
2014-11-08 00:00:59 +00:00
|
|
|
}
|
2015-03-23 22:50:23 +00:00
|
|
|
} else {
|
|
|
|
layer->useEmptyDamage();
|
2014-11-08 00:00:59 +00:00
|
|
|
}
|
2014-07-29 02:51:58 +00:00
|
|
|
}
|
|
|
|
for (size_t i = 0, count = layersWithQueuedFrames.size() ; i<count ; i++) {
|
|
|
|
Layer* layer = layersWithQueuedFrames[i];
|
2012-07-31 19:38:26 +00:00
|
|
|
const Region dirty(layer->latchBuffer(visibleRegions));
|
2015-03-23 22:50:23 +00:00
|
|
|
layer->useSurfaceDamage();
|
2013-06-05 23:59:15 +00:00
|
|
|
const Layer::State& s(layer->getDrawingState());
|
2012-07-31 19:38:26 +00:00
|
|
|
invalidateLayerStack(s.layerStack, dirty);
|
2012-06-29 21:12:52 +00:00
|
|
|
}
|
2010-08-11 00:19:56 +00:00
|
|
|
|
2012-07-11 20:48:17 +00:00
|
|
|
mVisibleRegionsDirty |= visibleRegions;
|
2014-11-08 00:00:59 +00:00
|
|
|
|
|
|
|
// If we will need to wake up at some time in the future to deal with a
|
|
|
|
// queued frame that shouldn't be displayed during this vsync period, wake
|
|
|
|
// up during the next vsync period to check again.
|
|
|
|
if (frameQueued && layersWithQueuedFrames.empty()) {
|
|
|
|
signalLayerUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only continue with the refresh if there is actually new work to do
|
|
|
|
return !layersWithQueuedFrames.empty();
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2011-01-14 01:53:01 +00:00
|
|
|
void SurfaceFlinger::invalidateHwcGeometry()
|
|
|
|
{
|
|
|
|
mHwWorkListDirty = true;
|
|
|
|
}
|
|
|
|
|
2012-02-01 02:24:27 +00:00
|
|
|
|
2012-08-16 23:28:27 +00:00
|
|
|
void SurfaceFlinger::doDisplayComposition(const sp<const DisplayDevice>& hw,
|
2012-07-31 19:38:26 +00:00
|
|
|
const Region& inDirtyRegion)
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2014-02-05 00:22:36 +00:00
|
|
|
// We only need to actually compose the display if:
|
|
|
|
// 1) It is being handled by hardware composer, which may need this to
|
|
|
|
// keep its virtual display state machine in sync, or
|
|
|
|
// 2) There is work to be done (the dirty region isn't empty)
|
|
|
|
bool isHwcDisplay = hw->getHwcDisplayId() >= 0;
|
|
|
|
if (!isHwcDisplay && inDirtyRegion.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-31 19:38:26 +00:00
|
|
|
Region dirtyRegion(inDirtyRegion);
|
|
|
|
|
2009-06-27 02:06:36 +00:00
|
|
|
// compute the invalid region
|
2012-08-05 07:40:46 +00:00
|
|
|
hw->swapRegion.orSelf(dirtyRegion);
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2012-08-05 07:40:46 +00:00
|
|
|
uint32_t flags = hw->getFlags();
|
2012-08-01 06:09:07 +00:00
|
|
|
if (flags & DisplayDevice::SWAP_RECTANGLE) {
|
2009-06-30 01:49:56 +00:00
|
|
|
// we can redraw only what's dirty, but since SWAP_RECTANGLE only
|
|
|
|
// takes a rectangle, we must make sure to update that whole
|
|
|
|
// rectangle in that case
|
2012-08-05 07:40:46 +00:00
|
|
|
dirtyRegion.set(hw->swapRegion.bounds());
|
2009-03-04 03:31:44 +00:00
|
|
|
} else {
|
2012-08-01 06:09:07 +00:00
|
|
|
if (flags & DisplayDevice::PARTIAL_UPDATES) {
|
2009-06-30 01:49:56 +00:00
|
|
|
// We need to redraw the rectangle that will be updated
|
2009-05-05 02:29:25 +00:00
|
|
|
// (pushed to the framebuffer).
|
2009-09-24 21:57:26 +00:00
|
|
|
// This is needed because PARTIAL_UPDATES only takes one
|
2012-08-01 06:09:07 +00:00
|
|
|
// rectangle instead of a region (see DisplayDevice::flip())
|
2012-08-05 07:40:46 +00:00
|
|
|
dirtyRegion.set(hw->swapRegion.bounds());
|
2009-03-04 03:31:44 +00:00
|
|
|
} else {
|
2009-06-30 01:49:56 +00:00
|
|
|
// we need to redraw everything (the whole screen)
|
2012-08-05 07:40:46 +00:00
|
|
|
dirtyRegion.set(hw->bounds());
|
|
|
|
hw->swapRegion = dirtyRegion;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-13 03:04:35 +00:00
|
|
|
if (CC_LIKELY(!mDaltonize && !mHasColorMatrix)) {
|
2014-10-01 18:17:28 +00:00
|
|
|
if (!doComposeSurfaces(hw, dirtyRegion)) return;
|
2013-09-02 04:36:12 +00:00
|
|
|
} else {
|
|
|
|
RenderEngine& engine(getRenderEngine());
|
2013-09-13 03:04:35 +00:00
|
|
|
mat4 colorMatrix = mColorMatrix;
|
|
|
|
if (mDaltonize) {
|
|
|
|
colorMatrix = colorMatrix * mDaltonizer();
|
|
|
|
}
|
2014-10-20 22:46:09 +00:00
|
|
|
mat4 oldMatrix = engine.setupColorTransform(colorMatrix);
|
2013-09-02 04:36:12 +00:00
|
|
|
doComposeSurfaces(hw, dirtyRegion);
|
2014-10-20 22:46:09 +00:00
|
|
|
engine.setupColorTransform(oldMatrix);
|
2013-09-02 04:36:12 +00:00
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2011-09-21 00:21:56 +00:00
|
|
|
// update the swap region and clear the dirty region
|
2012-08-05 07:40:46 +00:00
|
|
|
hw->swapRegion.orSelf(dirtyRegion);
|
2012-09-14 01:17:13 +00:00
|
|
|
|
|
|
|
// swap buffers (presentation)
|
|
|
|
hw->swapBuffers(getHwComposer());
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2014-10-01 18:17:28 +00:00
|
|
|
bool SurfaceFlinger::doComposeSurfaces(const sp<const DisplayDevice>& hw, const Region& dirty)
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2013-08-08 04:24:32 +00:00
|
|
|
RenderEngine& engine(getRenderEngine());
|
2012-08-29 23:59:24 +00:00
|
|
|
const int32_t id = hw->getHwcDisplayId();
|
2012-07-25 05:46:10 +00:00
|
|
|
HWComposer& hwc(getHwComposer());
|
2012-08-09 01:35:12 +00:00
|
|
|
HWComposer::LayerListIterator cur = hwc.begin(id);
|
|
|
|
const HWComposer::LayerListIterator end = hwc.end(id);
|
2010-08-11 00:14:02 +00:00
|
|
|
|
2013-09-30 23:49:30 +00:00
|
|
|
bool hasGlesComposition = hwc.hasGlesComposition(id);
|
2012-08-29 23:59:24 +00:00
|
|
|
if (hasGlesComposition) {
|
2013-06-07 22:35:48 +00:00
|
|
|
if (!hw->makeCurrent(mEGLDisplay, mEGLContext)) {
|
2013-03-04 23:15:46 +00:00
|
|
|
ALOGW("DisplayDevice::makeCurrent failed. Aborting surface composition for display %s",
|
|
|
|
hw->getDisplayName().string());
|
2014-10-01 18:17:28 +00:00
|
|
|
eglMakeCurrent(mEGLDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
|
|
|
if(!getDefaultDisplayDevice()->makeCurrent(mEGLDisplay, mEGLContext)) {
|
|
|
|
ALOGE("DisplayDevice::makeCurrent on default display failed. Aborting.");
|
|
|
|
}
|
|
|
|
return false;
|
2013-03-04 23:15:46 +00:00
|
|
|
}
|
2010-08-11 00:14:02 +00:00
|
|
|
|
2012-04-16 06:34:59 +00:00
|
|
|
// Never touch the framebuffer if we don't have any framebuffer layers
|
2012-08-29 23:59:24 +00:00
|
|
|
const bool hasHwcComposition = hwc.hasHwcComposition(id);
|
2012-08-22 06:34:09 +00:00
|
|
|
if (hasHwcComposition) {
|
2012-04-18 09:28:45 +00:00
|
|
|
// when using overlays, we assume a fully transparent framebuffer
|
|
|
|
// NOTE: we could reduce how much we need to clear, for instance
|
|
|
|
// remove where there are opaque FB layers. however, on some
|
2013-08-08 04:24:32 +00:00
|
|
|
// GPUs doing a "clean slate" clear might be more efficient.
|
2012-04-18 09:28:45 +00:00
|
|
|
// We'll revisit later if needed.
|
2013-08-08 04:24:32 +00:00
|
|
|
engine.clearWithColor(0, 0, 0, 0);
|
2012-04-18 09:28:45 +00:00
|
|
|
} else {
|
2012-10-31 01:08:06 +00:00
|
|
|
// we start with the whole screen area
|
|
|
|
const Region bounds(hw->getBounds());
|
|
|
|
|
|
|
|
// we remove the scissor part
|
|
|
|
// we're left with the letterbox region
|
|
|
|
// (common case is that letterbox ends-up being empty)
|
|
|
|
const Region letterbox(bounds.subtract(hw->getScissor()));
|
|
|
|
|
|
|
|
// compute the area to clear
|
|
|
|
Region region(hw->undefinedRegion.merge(letterbox));
|
|
|
|
|
|
|
|
// but limit it to the dirty region
|
|
|
|
region.andSelf(dirty);
|
|
|
|
|
2012-04-18 09:28:45 +00:00
|
|
|
// screen is already cleared here
|
2012-07-31 19:38:26 +00:00
|
|
|
if (!region.isEmpty()) {
|
2012-04-18 09:28:45 +00:00
|
|
|
// can happen with SurfaceView
|
2015-07-17 04:34:43 +00:00
|
|
|
drawWormHoleIfRequired(cur, end, hw, region);
|
2012-04-18 09:28:45 +00:00
|
|
|
}
|
2012-04-16 06:34:59 +00:00
|
|
|
}
|
2012-10-24 23:29:17 +00:00
|
|
|
|
2012-10-31 01:08:06 +00:00
|
|
|
if (hw->getDisplayType() != DisplayDevice::DISPLAY_PRIMARY) {
|
|
|
|
// just to be on the safe side, we don't set the
|
2012-10-24 23:29:17 +00:00
|
|
|
// scissor on the main display. It should never be needed
|
|
|
|
// anyways (though in theory it could since the API allows it).
|
|
|
|
const Rect& bounds(hw->getBounds());
|
2012-10-31 01:08:06 +00:00
|
|
|
const Rect& scissor(hw->getScissor());
|
2012-10-24 23:29:17 +00:00
|
|
|
if (scissor != bounds) {
|
|
|
|
// scissor doesn't match the screen's dimensions, so we
|
|
|
|
// need to clear everything outside of it and enable
|
|
|
|
// the GL scissor so we don't draw anything where we shouldn't
|
2013-08-08 04:24:32 +00:00
|
|
|
|
2012-10-24 23:29:17 +00:00
|
|
|
// enable scissor for this frame
|
2013-08-08 04:24:32 +00:00
|
|
|
const uint32_t height = hw->getHeight();
|
|
|
|
engine.setScissor(scissor.left, height - scissor.bottom,
|
|
|
|
scissor.getWidth(), scissor.getHeight());
|
2012-10-24 23:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-29 23:59:24 +00:00
|
|
|
}
|
2012-03-29 19:23:51 +00:00
|
|
|
|
2012-08-29 23:59:24 +00:00
|
|
|
/*
|
|
|
|
* and then, render the layers targeted at the framebuffer
|
|
|
|
*/
|
2012-03-29 19:23:51 +00:00
|
|
|
|
2013-03-06 01:47:11 +00:00
|
|
|
const Vector< sp<Layer> >& layers(hw->getVisibleLayersSortedByZ());
|
2012-08-29 23:59:24 +00:00
|
|
|
const size_t count = layers.size();
|
|
|
|
const Transform& tr = hw->getTransform();
|
|
|
|
if (cur != end) {
|
|
|
|
// we're using h/w composer
|
|
|
|
for (size_t i=0 ; i<count && cur!=end ; ++i, ++cur) {
|
2013-03-06 01:47:11 +00:00
|
|
|
const sp<Layer>& layer(layers[i]);
|
2012-06-29 21:12:52 +00:00
|
|
|
const Region clip(dirty.intersect(tr.transform(layer->visibleRegion)));
|
2012-08-29 23:59:24 +00:00
|
|
|
if (!clip.isEmpty()) {
|
|
|
|
switch (cur->getCompositionType()) {
|
2014-07-01 21:22:59 +00:00
|
|
|
case HWC_CURSOR_OVERLAY:
|
2012-08-29 23:59:24 +00:00
|
|
|
case HWC_OVERLAY: {
|
2013-10-01 22:36:52 +00:00
|
|
|
const Layer::State& state(layer->getDrawingState());
|
2012-08-29 23:59:24 +00:00
|
|
|
if ((cur->getHints() & HWC_HINT_CLEAR_FB)
|
|
|
|
&& i
|
2014-01-30 01:17:11 +00:00
|
|
|
&& layer->isOpaque(state) && (state.alpha == 0xFF)
|
2012-08-29 23:59:24 +00:00
|
|
|
&& hasGlesComposition) {
|
2012-08-16 23:28:27 +00:00
|
|
|
// never clear the very first layer since we're
|
|
|
|
// guaranteed the FB is already cleared
|
|
|
|
layer->clearWithOpenGL(hw, clip);
|
|
|
|
}
|
2012-08-29 23:59:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case HWC_FRAMEBUFFER: {
|
2012-08-16 23:28:27 +00:00
|
|
|
layer->draw(hw, clip);
|
2012-08-29 23:59:24 +00:00
|
|
|
break;
|
2012-04-16 06:34:59 +00:00
|
|
|
}
|
2012-09-14 01:17:13 +00:00
|
|
|
case HWC_FRAMEBUFFER_TARGET: {
|
|
|
|
// this should not happen as the iterator shouldn't
|
|
|
|
// let us get there.
|
2014-03-07 20:44:02 +00:00
|
|
|
ALOGW("HWC_FRAMEBUFFER_TARGET found in hwc list (index=%zu)", i);
|
2012-09-14 01:17:13 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-08-16 23:28:27 +00:00
|
|
|
}
|
2012-07-19 23:44:38 +00:00
|
|
|
}
|
2012-08-29 23:59:24 +00:00
|
|
|
layer->setAcquireFence(hw, *cur);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// we're not using h/w composer
|
|
|
|
for (size_t i=0 ; i<count ; ++i) {
|
2013-03-06 01:47:11 +00:00
|
|
|
const sp<Layer>& layer(layers[i]);
|
2012-08-29 23:59:24 +00:00
|
|
|
const Region clip(dirty.intersect(
|
|
|
|
tr.transform(layer->visibleRegion)));
|
|
|
|
if (!clip.isEmpty()) {
|
|
|
|
layer->draw(hw, clip);
|
|
|
|
}
|
2012-03-29 19:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
2012-10-24 23:29:17 +00:00
|
|
|
|
|
|
|
// disable scissor at the end of the frame
|
2013-08-08 04:24:32 +00:00
|
|
|
engine.disableScissor();
|
2014-10-01 18:17:28 +00:00
|
|
|
return true;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2013-08-08 04:24:32 +00:00
|
|
|
void SurfaceFlinger::drawWormhole(const sp<const DisplayDevice>& hw, const Region& region) const {
|
2012-08-28 01:54:24 +00:00
|
|
|
const int32_t height = hw->getHeight();
|
2013-08-08 04:24:32 +00:00
|
|
|
RenderEngine& engine(getRenderEngine());
|
|
|
|
engine.fillRegionWithColor(region, height, 0, 0, 0, 0);
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2015-04-30 20:29:25 +00:00
|
|
|
status_t SurfaceFlinger::addClientLayer(const sp<Client>& client,
|
2013-02-12 00:40:36 +00:00
|
|
|
const sp<IBinder>& handle,
|
2013-03-15 02:18:13 +00:00
|
|
|
const sp<IGraphicBufferProducer>& gbc,
|
2013-03-06 01:47:11 +00:00
|
|
|
const sp<Layer>& lbc)
|
2010-04-21 00:55:49 +00:00
|
|
|
{
|
2015-04-30 20:29:25 +00:00
|
|
|
// add this layer to the current state list
|
|
|
|
{
|
|
|
|
Mutex::Autolock _l(mStateLock);
|
|
|
|
if (mCurrentState.layersSortedByZ.size() >= MAX_LAYERS) {
|
|
|
|
return NO_MEMORY;
|
|
|
|
}
|
|
|
|
mCurrentState.layersSortedByZ.add(lbc);
|
|
|
|
mGraphicBufferProducerList.add(IInterface::asBinder(gbc));
|
|
|
|
}
|
|
|
|
|
2010-06-03 06:28:45 +00:00
|
|
|
// attach this layer to the client
|
2013-02-12 00:40:36 +00:00
|
|
|
client->attachLayer(handle, lbc);
|
2011-05-03 23:21:41 +00:00
|
|
|
|
2015-04-30 20:29:25 +00:00
|
|
|
return NO_ERROR;
|
2010-06-03 06:28:45 +00:00
|
|
|
}
|
|
|
|
|
2013-08-08 04:24:32 +00:00
|
|
|
status_t SurfaceFlinger::removeLayer(const sp<Layer>& layer) {
|
2010-06-03 06:28:45 +00:00
|
|
|
Mutex::Autolock _l(mStateLock);
|
2013-03-06 01:47:11 +00:00
|
|
|
ssize_t index = mCurrentState.layersSortedByZ.remove(layer);
|
2009-03-04 03:31:44 +00:00
|
|
|
if (index >= 0) {
|
2013-03-15 02:18:13 +00:00
|
|
|
mLayersPendingRemoval.push(layer);
|
2009-04-10 21:24:30 +00:00
|
|
|
mLayersRemoved = true;
|
2013-03-15 02:18:13 +00:00
|
|
|
setTransactionFlags(eTransactionNeeded);
|
2009-03-04 03:31:44 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
}
|
2009-06-05 01:46:21 +00:00
|
|
|
return status_t(index);
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2014-02-14 23:03:43 +00:00
|
|
|
uint32_t SurfaceFlinger::peekTransactionFlags(uint32_t /* flags */) {
|
2011-05-04 00:04:02 +00:00
|
|
|
return android_atomic_release_load(&mTransactionFlags);
|
|
|
|
}
|
|
|
|
|
2013-08-08 04:24:32 +00:00
|
|
|
uint32_t SurfaceFlinger::getTransactionFlags(uint32_t flags) {
|
2009-03-04 03:31:44 +00:00
|
|
|
return android_atomic_and(~flags, &mTransactionFlags) & flags;
|
|
|
|
}
|
|
|
|
|
2013-08-08 04:24:32 +00:00
|
|
|
uint32_t SurfaceFlinger::setTransactionFlags(uint32_t flags) {
|
2009-03-04 03:31:44 +00:00
|
|
|
uint32_t old = android_atomic_or(flags, &mTransactionFlags);
|
|
|
|
if ((old & flags)==0) { // wake the server up
|
2012-02-01 02:24:27 +00:00
|
|
|
signalTransaction();
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
return old;
|
|
|
|
}
|
|
|
|
|
2012-07-25 03:43:54 +00:00
|
|
|
void SurfaceFlinger::setTransactionState(
|
|
|
|
const Vector<ComposerState>& state,
|
|
|
|
const Vector<DisplayState>& displays,
|
|
|
|
uint32_t flags)
|
|
|
|
{
|
2012-10-17 16:29:47 +00:00
|
|
|
ATRACE_CALL();
|
2015-06-23 19:55:15 +00:00
|
|
|
|
|
|
|
delayDPTransactionIfNeeded(displays);
|
2011-06-29 02:09:31 +00:00
|
|
|
Mutex::Autolock _l(mStateLock);
|
2011-10-13 00:39:00 +00:00
|
|
|
uint32_t transactionFlags = 0;
|
2012-08-09 23:29:12 +00:00
|
|
|
|
2012-10-16 01:24:43 +00:00
|
|
|
if (flags & eAnimation) {
|
|
|
|
// For window updates that are part of an animation we must wait for
|
|
|
|
// previous animation "frames" to be handled.
|
|
|
|
while (mAnimTransactionPending) {
|
2012-10-17 16:29:47 +00:00
|
|
|
status_t err = mTransactionCV.waitRelative(mStateLock, s2ns(5));
|
2012-10-16 01:24:43 +00:00
|
|
|
if (CC_UNLIKELY(err != NO_ERROR)) {
|
|
|
|
// just in case something goes wrong in SF, return to the
|
2012-10-17 16:29:47 +00:00
|
|
|
// caller after a few seconds.
|
|
|
|
ALOGW_IF(err == TIMED_OUT, "setTransactionState timed out "
|
|
|
|
"waiting for previous animation frame");
|
2012-10-16 01:24:43 +00:00
|
|
|
mAnimTransactionPending = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-09 23:29:12 +00:00
|
|
|
size_t count = displays.size();
|
|
|
|
for (size_t i=0 ; i<count ; i++) {
|
|
|
|
const DisplayState& s(displays[i]);
|
|
|
|
transactionFlags |= setDisplayStateLocked(s);
|
2011-10-10 22:48:06 +00:00
|
|
|
}
|
|
|
|
|
2012-08-09 23:29:12 +00:00
|
|
|
count = state.size();
|
2011-06-29 02:09:31 +00:00
|
|
|
for (size_t i=0 ; i<count ; i++) {
|
|
|
|
const ComposerState& s(state[i]);
|
2012-10-22 21:27:45 +00:00
|
|
|
// Here we need to check that the interface we're given is indeed
|
|
|
|
// one of our own. A malicious client could give us a NULL
|
|
|
|
// IInterface, or one of its own or even one of our own but a
|
|
|
|
// different type. All these situations would cause us to crash.
|
|
|
|
//
|
|
|
|
// NOTE: it would be better to use RTTI as we could directly check
|
|
|
|
// that we have a Client*. however, RTTI is disabled in Android.
|
|
|
|
if (s.client != NULL) {
|
2014-11-14 16:01:01 +00:00
|
|
|
sp<IBinder> binder = IInterface::asBinder(s.client);
|
2012-10-22 21:27:45 +00:00
|
|
|
if (binder != NULL) {
|
|
|
|
String16 desc(binder->getInterfaceDescriptor());
|
|
|
|
if (desc == ISurfaceComposerClient::descriptor) {
|
|
|
|
sp<Client> client( static_cast<Client *>(s.client.get()) );
|
|
|
|
transactionFlags |= setClientStateLocked(client, s.state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-06-29 02:09:31 +00:00
|
|
|
}
|
2011-11-08 05:58:03 +00:00
|
|
|
|
2011-10-13 00:39:00 +00:00
|
|
|
if (transactionFlags) {
|
2011-11-08 05:58:03 +00:00
|
|
|
// this triggers the transaction
|
2011-10-13 00:39:00 +00:00
|
|
|
setTransactionFlags(transactionFlags);
|
2011-06-29 02:09:31 +00:00
|
|
|
|
2011-11-08 05:58:03 +00:00
|
|
|
// if this is a synchronous transaction, wait for it to take effect
|
|
|
|
// before returning.
|
|
|
|
if (flags & eSynchronous) {
|
2012-10-16 01:24:43 +00:00
|
|
|
mTransactionPending = true;
|
|
|
|
}
|
|
|
|
if (flags & eAnimation) {
|
|
|
|
mAnimTransactionPending = true;
|
2011-11-08 05:58:03 +00:00
|
|
|
}
|
2012-10-16 01:24:43 +00:00
|
|
|
while (mTransactionPending) {
|
2011-11-08 05:58:03 +00:00
|
|
|
status_t err = mTransactionCV.waitRelative(mStateLock, s2ns(5));
|
|
|
|
if (CC_UNLIKELY(err != NO_ERROR)) {
|
|
|
|
// just in case something goes wrong in SF, return to the
|
|
|
|
// called after a few seconds.
|
2012-10-16 01:24:43 +00:00
|
|
|
ALOGW_IF(err == TIMED_OUT, "setTransactionState timed out!");
|
|
|
|
mTransactionPending = false;
|
2011-11-08 05:58:03 +00:00
|
|
|
break;
|
|
|
|
}
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-09 23:29:12 +00:00
|
|
|
uint32_t SurfaceFlinger::setDisplayStateLocked(const DisplayState& s)
|
|
|
|
{
|
2012-10-04 23:29:19 +00:00
|
|
|
ssize_t dpyIdx = mCurrentState.displays.indexOfKey(s.token);
|
|
|
|
if (dpyIdx < 0)
|
|
|
|
return 0;
|
|
|
|
|
2012-08-09 23:29:12 +00:00
|
|
|
uint32_t flags = 0;
|
2012-10-04 23:29:19 +00:00
|
|
|
DisplayDeviceState& disp(mCurrentState.displays.editValueAt(dpyIdx));
|
2012-08-27 23:28:24 +00:00
|
|
|
if (disp.isValid()) {
|
2012-08-09 23:29:12 +00:00
|
|
|
const uint32_t what = s.what;
|
|
|
|
if (what & DisplayState::eSurfaceChanged) {
|
2014-11-14 16:01:01 +00:00
|
|
|
if (IInterface::asBinder(disp.surface) != IInterface::asBinder(s.surface)) {
|
2012-08-09 23:29:12 +00:00
|
|
|
disp.surface = s.surface;
|
|
|
|
flags |= eDisplayTransactionNeeded;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (what & DisplayState::eLayerStackChanged) {
|
|
|
|
if (disp.layerStack != s.layerStack) {
|
|
|
|
disp.layerStack = s.layerStack;
|
|
|
|
flags |= eDisplayTransactionNeeded;
|
|
|
|
}
|
|
|
|
}
|
2012-09-05 02:30:46 +00:00
|
|
|
if (what & DisplayState::eDisplayProjectionChanged) {
|
2012-08-09 23:29:12 +00:00
|
|
|
if (disp.orientation != s.orientation) {
|
|
|
|
disp.orientation = s.orientation;
|
|
|
|
flags |= eDisplayTransactionNeeded;
|
|
|
|
}
|
|
|
|
if (disp.frame != s.frame) {
|
|
|
|
disp.frame = s.frame;
|
|
|
|
flags |= eDisplayTransactionNeeded;
|
|
|
|
}
|
|
|
|
if (disp.viewport != s.viewport) {
|
|
|
|
disp.viewport = s.viewport;
|
|
|
|
flags |= eDisplayTransactionNeeded;
|
|
|
|
}
|
|
|
|
}
|
2014-07-18 22:34:25 +00:00
|
|
|
if (what & DisplayState::eDisplaySizeChanged) {
|
|
|
|
if (disp.width != s.width) {
|
|
|
|
disp.width = s.width;
|
|
|
|
flags |= eDisplayTransactionNeeded;
|
|
|
|
}
|
|
|
|
if (disp.height != s.height) {
|
|
|
|
disp.height = s.height;
|
|
|
|
flags |= eDisplayTransactionNeeded;
|
|
|
|
}
|
|
|
|
}
|
2012-08-09 23:29:12 +00:00
|
|
|
}
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t SurfaceFlinger::setClientStateLocked(
|
|
|
|
const sp<Client>& client,
|
|
|
|
const layer_state_t& s)
|
|
|
|
{
|
|
|
|
uint32_t flags = 0;
|
2013-03-06 01:47:11 +00:00
|
|
|
sp<Layer> layer(client->getLayerUser(s.surface));
|
2012-08-09 23:29:12 +00:00
|
|
|
if (layer != 0) {
|
|
|
|
const uint32_t what = s.what;
|
|
|
|
if (what & layer_state_t::ePositionChanged) {
|
|
|
|
if (layer->setPosition(s.x, s.y))
|
|
|
|
flags |= eTraversalNeeded;
|
|
|
|
}
|
|
|
|
if (what & layer_state_t::eLayerChanged) {
|
|
|
|
// NOTE: index needs to be calculated before we update the state
|
|
|
|
ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer);
|
|
|
|
if (layer->setLayer(s.z)) {
|
|
|
|
mCurrentState.layersSortedByZ.removeAt(idx);
|
|
|
|
mCurrentState.layersSortedByZ.add(layer);
|
|
|
|
// we need traversal (state changed)
|
|
|
|
// AND transaction (list changed)
|
|
|
|
flags |= eTransactionNeeded|eTraversalNeeded;
|
|
|
|
}
|
|
|
|
}
|
2014-12-06 02:28:32 +00:00
|
|
|
if (what & layer_state_t::eBlurChanged) {
|
|
|
|
ALOGV("eBlurChanged");
|
|
|
|
if (layer->setBlur(uint8_t(255.0f*s.blur+0.5f))) {
|
|
|
|
flags |= eTraversalNeeded;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (what & layer_state_t::eBlurMaskSurfaceChanged) {
|
|
|
|
ALOGV("eBlurMaskSurfaceChanged");
|
|
|
|
sp<Layer> maskLayer = 0;
|
|
|
|
if (s.blurMaskSurface != 0) {
|
|
|
|
maskLayer = client->getLayerUser(s.blurMaskSurface);
|
|
|
|
}
|
|
|
|
if (maskLayer == 0) {
|
|
|
|
ALOGV("eBlurMaskSurfaceChanged. maskLayer == 0");
|
|
|
|
} else {
|
|
|
|
ALOGV("eBlurMaskSurfaceChagned. maskLayer.z == %d", maskLayer->getCurrentState().z);
|
|
|
|
if (maskLayer->isBlurLayer()) {
|
|
|
|
ALOGE("Blur layer can not be used as blur mask surface");
|
|
|
|
maskLayer = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (layer->setBlurMaskLayer(maskLayer)) {
|
|
|
|
flags |= eTraversalNeeded;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (what & layer_state_t::eBlurMaskSamplingChanged) {
|
|
|
|
if (layer->setBlurMaskSampling(s.blurMaskSampling)) {
|
|
|
|
flags |= eTraversalNeeded;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (what & layer_state_t::eBlurMaskAlphaThresholdChanged) {
|
|
|
|
if (layer->setBlurMaskAlphaThreshold(s.blurMaskAlphaThreshold)) {
|
|
|
|
flags |= eTraversalNeeded;
|
|
|
|
}
|
|
|
|
}
|
2012-08-09 23:29:12 +00:00
|
|
|
if (what & layer_state_t::eSizeChanged) {
|
|
|
|
if (layer->setSize(s.w, s.h)) {
|
|
|
|
flags |= eTraversalNeeded;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (what & layer_state_t::eAlphaChanged) {
|
|
|
|
if (layer->setAlpha(uint8_t(255.0f*s.alpha+0.5f)))
|
|
|
|
flags |= eTraversalNeeded;
|
|
|
|
}
|
|
|
|
if (what & layer_state_t::eMatrixChanged) {
|
|
|
|
if (layer->setMatrix(s.matrix))
|
|
|
|
flags |= eTraversalNeeded;
|
|
|
|
}
|
|
|
|
if (what & layer_state_t::eTransparentRegionChanged) {
|
|
|
|
if (layer->setTransparentRegionHint(s.transparentRegion))
|
|
|
|
flags |= eTraversalNeeded;
|
|
|
|
}
|
2015-06-18 21:58:39 +00:00
|
|
|
if (what & layer_state_t::eFlagsChanged) {
|
2012-08-09 23:29:12 +00:00
|
|
|
if (layer->setFlags(s.flags, s.mask))
|
|
|
|
flags |= eTraversalNeeded;
|
|
|
|
}
|
|
|
|
if (what & layer_state_t::eCropChanged) {
|
|
|
|
if (layer->setCrop(s.crop))
|
|
|
|
flags |= eTraversalNeeded;
|
|
|
|
}
|
|
|
|
if (what & layer_state_t::eLayerStackChanged) {
|
|
|
|
// NOTE: index needs to be calculated before we update the state
|
|
|
|
ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer);
|
|
|
|
if (layer->setLayerStack(s.layerStack)) {
|
|
|
|
mCurrentState.layersSortedByZ.removeAt(idx);
|
|
|
|
mCurrentState.layersSortedByZ.add(layer);
|
|
|
|
// we need traversal (state changed)
|
|
|
|
// AND transaction (list changed)
|
|
|
|
flags |= eTransactionNeeded|eTraversalNeeded;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2013-03-13 00:11:48 +00:00
|
|
|
status_t SurfaceFlinger::createLayer(
|
2011-04-20 21:19:32 +00:00
|
|
|
const String8& name,
|
|
|
|
const sp<Client>& client,
|
2013-03-13 00:11:48 +00:00
|
|
|
uint32_t w, uint32_t h, PixelFormat format, uint32_t flags,
|
|
|
|
sp<IBinder>* handle, sp<IGraphicBufferProducer>* gbp)
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2013-03-13 00:11:48 +00:00
|
|
|
//ALOGD("createLayer for (%d x %d), name=%s", w, h, name.string());
|
2009-07-10 01:16:43 +00:00
|
|
|
if (int32_t(w|h) < 0) {
|
2012-07-24 06:11:29 +00:00
|
|
|
ALOGE("createLayer() failed, w or h is negative (w=%d, h=%d)",
|
2009-07-10 01:16:43 +00:00
|
|
|
int(w), int(h));
|
2013-03-13 00:11:48 +00:00
|
|
|
return BAD_VALUE;
|
2009-07-10 01:16:43 +00:00
|
|
|
}
|
2010-08-16 15:49:37 +00:00
|
|
|
|
2013-03-13 00:11:48 +00:00
|
|
|
status_t result = NO_ERROR;
|
|
|
|
|
|
|
|
sp<Layer> layer;
|
|
|
|
|
2012-08-09 02:42:09 +00:00
|
|
|
switch (flags & ISurfaceComposerClient::eFXSurfaceMask) {
|
|
|
|
case ISurfaceComposerClient::eFXSurfaceNormal:
|
2013-03-13 00:11:48 +00:00
|
|
|
result = createNormalLayer(client,
|
|
|
|
name, w, h, flags, format,
|
|
|
|
handle, gbp, &layer);
|
2009-03-04 03:31:44 +00:00
|
|
|
break;
|
2012-08-09 02:42:09 +00:00
|
|
|
case ISurfaceComposerClient::eFXSurfaceDim:
|
2013-03-13 00:11:48 +00:00
|
|
|
result = createDimLayer(client,
|
|
|
|
name, w, h, flags,
|
|
|
|
handle, gbp, &layer);
|
|
|
|
break;
|
2014-12-06 02:28:32 +00:00
|
|
|
case ISurfaceComposerClient::eFXSurfaceBlur:
|
|
|
|
result = createBlurLayer(client,
|
|
|
|
name, w, h, flags,
|
|
|
|
handle, gbp, &layer);
|
|
|
|
break;
|
2013-03-13 00:11:48 +00:00
|
|
|
default:
|
|
|
|
result = BAD_VALUE;
|
2009-03-04 03:31:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-04-30 20:29:25 +00:00
|
|
|
if (result != NO_ERROR) {
|
|
|
|
return result;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
2015-04-30 20:29:25 +00:00
|
|
|
|
|
|
|
result = addClientLayer(client, *handle, *gbp, layer);
|
|
|
|
if (result != NO_ERROR) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
setTransactionFlags(eTransactionNeeded);
|
2013-03-13 00:11:48 +00:00
|
|
|
return result;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2013-03-13 00:11:48 +00:00
|
|
|
status_t SurfaceFlinger::createNormalLayer(const sp<Client>& client,
|
|
|
|
const String8& name, uint32_t w, uint32_t h, uint32_t flags, PixelFormat& format,
|
|
|
|
sp<IBinder>* handle, sp<IGraphicBufferProducer>* gbp, sp<Layer>* outLayer)
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
|
|
|
// initialize the surfaces
|
2012-08-03 01:32:23 +00:00
|
|
|
switch (format) {
|
2009-03-04 03:31:44 +00:00
|
|
|
case PIXEL_FORMAT_TRANSPARENT:
|
|
|
|
case PIXEL_FORMAT_TRANSLUCENT:
|
|
|
|
format = PIXEL_FORMAT_RGBA_8888;
|
|
|
|
break;
|
|
|
|
case PIXEL_FORMAT_OPAQUE:
|
2010-04-06 01:01:24 +00:00
|
|
|
format = PIXEL_FORMAT_RGBX_8888;
|
2009-03-04 03:31:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-06-23 19:55:15 +00:00
|
|
|
*outLayer = DisplayUtils::getInstance()->getLayerInstance(this, client, name, w, h, flags);
|
2013-03-13 00:11:48 +00:00
|
|
|
status_t err = (*outLayer)->setBuffers(w, h, format, flags);
|
|
|
|
if (err == NO_ERROR) {
|
|
|
|
*handle = (*outLayer)->getHandle();
|
2014-03-13 18:55:57 +00:00
|
|
|
*gbp = (*outLayer)->getProducer();
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
2013-03-13 00:11:48 +00:00
|
|
|
|
|
|
|
ALOGE_IF(err, "createNormalLayer() failed (%s)", strerror(-err));
|
|
|
|
return err;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2013-03-13 00:11:48 +00:00
|
|
|
status_t SurfaceFlinger::createDimLayer(const sp<Client>& client,
|
|
|
|
const String8& name, uint32_t w, uint32_t h, uint32_t flags,
|
|
|
|
sp<IBinder>* handle, sp<IGraphicBufferProducer>* gbp, sp<Layer>* outLayer)
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2013-03-13 00:11:48 +00:00
|
|
|
*outLayer = new LayerDim(this, client, name, w, h, flags);
|
|
|
|
*handle = (*outLayer)->getHandle();
|
2014-03-13 18:55:57 +00:00
|
|
|
*gbp = (*outLayer)->getProducer();
|
2013-03-13 00:11:48 +00:00
|
|
|
return NO_ERROR;
|
2011-10-13 23:02:48 +00:00
|
|
|
}
|
|
|
|
|
2014-12-06 02:28:32 +00:00
|
|
|
status_t SurfaceFlinger::createBlurLayer(const sp<Client>& client,
|
|
|
|
const String8& name, uint32_t w, uint32_t h, uint32_t flags,
|
|
|
|
sp<IBinder>* handle, sp<IGraphicBufferProducer>* gbp, sp<Layer>* outLayer)
|
|
|
|
{
|
|
|
|
*outLayer = new LayerBlur(this, client, name, w, h, flags);
|
|
|
|
*handle = (*outLayer)->getHandle();
|
|
|
|
*gbp = (*outLayer)->getProducer();
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2013-02-12 00:40:36 +00:00
|
|
|
status_t SurfaceFlinger::onLayerRemoved(const sp<Client>& client, const sp<IBinder>& handle)
|
2009-04-18 02:36:26 +00:00
|
|
|
{
|
2013-03-15 02:18:13 +00:00
|
|
|
// called by the window manager when it wants to remove a Layer
|
|
|
|
status_t err = NO_ERROR;
|
|
|
|
sp<Layer> l(client->getLayerUser(handle));
|
|
|
|
if (l != NULL) {
|
|
|
|
err = removeLayer(l);
|
|
|
|
ALOGE_IF(err<0 && err != NAME_NOT_FOUND,
|
|
|
|
"error removing layer=%p (%s)", l.get(), strerror(-err));
|
2009-04-18 02:36:26 +00:00
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2013-03-06 01:47:11 +00:00
|
|
|
status_t SurfaceFlinger::onLayerDestroyed(const wp<Layer>& layer)
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2013-03-15 02:18:13 +00:00
|
|
|
// called by ~LayerCleaner() when all references to the IBinder (handle)
|
|
|
|
// are gone
|
2011-05-19 22:38:14 +00:00
|
|
|
status_t err = NO_ERROR;
|
2013-03-06 01:47:11 +00:00
|
|
|
sp<Layer> l(layer.promote());
|
2011-05-19 22:38:14 +00:00
|
|
|
if (l != NULL) {
|
2013-03-15 02:18:13 +00:00
|
|
|
err = removeLayer(l);
|
2012-01-06 19:20:56 +00:00
|
|
|
ALOGE_IF(err<0 && err != NAME_NOT_FOUND,
|
2011-05-19 22:38:14 +00:00
|
|
|
"error removing layer=%p (%s)", l.get(), strerror(-err));
|
|
|
|
}
|
|
|
|
return err;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2012-04-11 05:09:54 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2012-08-24 17:16:42 +00:00
|
|
|
void SurfaceFlinger::onInitializeDisplays() {
|
2013-02-20 00:13:35 +00:00
|
|
|
// reset screen orientation and use primary layer stack
|
2012-08-24 17:16:42 +00:00
|
|
|
Vector<ComposerState> state;
|
|
|
|
Vector<DisplayState> displays;
|
|
|
|
DisplayState d;
|
2013-02-20 00:13:35 +00:00
|
|
|
d.what = DisplayState::eDisplayProjectionChanged |
|
|
|
|
DisplayState::eLayerStackChanged;
|
2012-11-08 23:41:56 +00:00
|
|
|
d.token = mBuiltinDisplays[DisplayDevice::DISPLAY_PRIMARY];
|
2013-02-20 00:13:35 +00:00
|
|
|
d.layerStack = 0;
|
2012-08-24 17:16:42 +00:00
|
|
|
d.orientation = DisplayState::eOrientationDefault;
|
2012-09-09 07:07:17 +00:00
|
|
|
d.frame.makeInvalid();
|
|
|
|
d.viewport.makeInvalid();
|
2014-07-18 22:34:25 +00:00
|
|
|
d.width = 0;
|
|
|
|
d.height = 0;
|
2012-08-24 17:16:42 +00:00
|
|
|
displays.add(d);
|
|
|
|
setTransactionState(state, displays, 0);
|
2014-05-25 08:36:31 +00:00
|
|
|
setPowerModeInternal(getDisplayDevice(d.token), HWC_POWER_MODE_NORMAL);
|
2013-07-17 03:12:42 +00:00
|
|
|
|
|
|
|
const nsecs_t period =
|
|
|
|
getHwComposer().getRefreshPeriod(HWC_DISPLAY_PRIMARY);
|
|
|
|
mAnimFrameTracker.setDisplayRefreshPeriod(period);
|
2012-08-24 17:16:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SurfaceFlinger::initializeDisplays() {
|
|
|
|
class MessageScreenInitialized : public MessageBase {
|
|
|
|
SurfaceFlinger* flinger;
|
|
|
|
public:
|
|
|
|
MessageScreenInitialized(SurfaceFlinger* flinger) : flinger(flinger) { }
|
|
|
|
virtual bool handler() {
|
|
|
|
flinger->onInitializeDisplays();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
sp<MessageBase> msg = new MessageScreenInitialized(this);
|
|
|
|
postMessageAsync(msg); // we may be called from main thread, use async message
|
|
|
|
}
|
|
|
|
|
2014-05-25 08:36:31 +00:00
|
|
|
void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& hw,
|
|
|
|
int mode) {
|
|
|
|
ALOGD("Set power mode=%d, type=%d flinger=%p", mode, hw->getDisplayType(),
|
|
|
|
this);
|
|
|
|
int32_t type = hw->getDisplayType();
|
|
|
|
int currentMode = hw->getPowerMode();
|
2012-08-24 17:16:42 +00:00
|
|
|
|
2014-05-25 08:36:31 +00:00
|
|
|
if (mode == currentMode) {
|
|
|
|
ALOGD("Screen type=%d is already mode=%d", hw->getDisplayType(), mode);
|
2012-09-27 23:02:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-25 08:36:31 +00:00
|
|
|
hw->setPowerMode(mode);
|
|
|
|
if (type >= DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES) {
|
|
|
|
ALOGW("Trying to set power mode for virtual display");
|
|
|
|
return;
|
|
|
|
}
|
2012-09-27 23:02:06 +00:00
|
|
|
|
2014-05-25 08:36:31 +00:00
|
|
|
if (currentMode == HWC_POWER_MODE_OFF) {
|
|
|
|
getHwComposer().setPowerMode(type, mode);
|
2012-09-27 23:02:06 +00:00
|
|
|
if (type == DisplayDevice::DISPLAY_PRIMARY) {
|
|
|
|
// FIXME: eventthread only knows about the main display right now
|
|
|
|
mEventThread->onScreenAcquired();
|
2013-10-14 19:56:09 +00:00
|
|
|
resyncToHardwareVsync(true);
|
2012-09-27 23:02:06 +00:00
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2014-05-25 08:36:31 +00:00
|
|
|
mVisibleRegionsDirty = true;
|
2015-03-05 19:05:59 +00:00
|
|
|
mHasPoweredOff = true;
|
2014-05-25 08:36:31 +00:00
|
|
|
repaintEverything();
|
|
|
|
} else if (mode == HWC_POWER_MODE_OFF) {
|
2012-09-27 23:02:06 +00:00
|
|
|
if (type == DisplayDevice::DISPLAY_PRIMARY) {
|
2013-10-14 19:56:09 +00:00
|
|
|
disableHardwareVsync(true); // also cancels any in-progress resync
|
|
|
|
|
2012-09-13 21:09:01 +00:00
|
|
|
// FIXME: eventthread only knows about the main display right now
|
|
|
|
mEventThread->onScreenReleased();
|
|
|
|
}
|
2012-09-27 23:02:06 +00:00
|
|
|
|
2014-05-25 08:36:31 +00:00
|
|
|
getHwComposer().setPowerMode(type, mode);
|
|
|
|
mVisibleRegionsDirty = true;
|
|
|
|
// from this point on, SF will stop drawing on this display
|
|
|
|
} else {
|
|
|
|
getHwComposer().setPowerMode(type, mode);
|
2012-04-11 05:09:54 +00:00
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2014-05-25 08:36:31 +00:00
|
|
|
void SurfaceFlinger::setPowerMode(const sp<IBinder>& display, int mode) {
|
|
|
|
class MessageSetPowerMode: public MessageBase {
|
2012-10-15 23:51:41 +00:00
|
|
|
SurfaceFlinger& mFlinger;
|
|
|
|
sp<IBinder> mDisplay;
|
2014-05-25 08:36:31 +00:00
|
|
|
int mMode;
|
2012-04-11 05:09:54 +00:00
|
|
|
public:
|
2014-05-25 08:36:31 +00:00
|
|
|
MessageSetPowerMode(SurfaceFlinger& flinger,
|
|
|
|
const sp<IBinder>& disp, int mode) : mFlinger(flinger),
|
|
|
|
mDisplay(disp) { mMode = mode; }
|
2012-04-11 05:09:54 +00:00
|
|
|
virtual bool handler() {
|
2014-05-25 08:36:31 +00:00
|
|
|
sp<DisplayDevice> hw(mFlinger.getDisplayDevice(mDisplay));
|
2012-10-15 23:51:41 +00:00
|
|
|
if (hw == NULL) {
|
2014-05-25 08:36:31 +00:00
|
|
|
ALOGE("Attempt to set power mode = %d for null display %p",
|
2014-07-30 20:00:37 +00:00
|
|
|
mMode, mDisplay.get());
|
2013-08-16 21:28:37 +00:00
|
|
|
} else if (hw->getDisplayType() >= DisplayDevice::DISPLAY_VIRTUAL) {
|
2014-05-25 08:36:31 +00:00
|
|
|
ALOGW("Attempt to set power mode = %d for virtual display",
|
|
|
|
mMode);
|
2012-10-15 23:51:41 +00:00
|
|
|
} else {
|
2014-05-25 08:36:31 +00:00
|
|
|
mFlinger.setPowerModeInternal(hw, mMode);
|
2012-10-15 23:51:41 +00:00
|
|
|
}
|
2012-04-11 05:09:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2014-05-25 08:36:31 +00:00
|
|
|
sp<MessageBase> msg = new MessageSetPowerMode(*this, display, mode);
|
2012-10-15 23:51:41 +00:00
|
|
|
postMessageSync(msg);
|
2012-04-11 05:09:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
status_t SurfaceFlinger::dump(int fd, const Vector<String16>& args)
|
|
|
|
{
|
|
|
|
String8 result;
|
2011-06-27 23:05:52 +00:00
|
|
|
|
2013-04-18 23:41:04 +00:00
|
|
|
IPCThreadState* ipc = IPCThreadState::self();
|
|
|
|
const int pid = ipc->getCallingPid();
|
|
|
|
const int uid = ipc->getCallingUid();
|
|
|
|
if ((uid != AID_SHELL) &&
|
|
|
|
!PermissionCache::checkPermission(sDump, pid, uid)) {
|
2013-04-22 14:55:35 +00:00
|
|
|
result.appendFormat("Permission Denial: "
|
2013-04-18 23:41:04 +00:00
|
|
|
"can't dump SurfaceFlinger from pid=%d, uid=%d\n", pid, uid);
|
2009-03-04 03:31:44 +00:00
|
|
|
} else {
|
2014-12-23 21:57:23 +00:00
|
|
|
// Try to get the main lock, but give up after one second
|
2009-08-26 23:36:26 +00:00
|
|
|
// (this would indicate SF is stuck, but we want to be able to
|
|
|
|
// print something in dumpsys).
|
2014-12-23 21:57:23 +00:00
|
|
|
status_t err = mStateLock.timedLock(s2ns(1));
|
|
|
|
bool locked = (err == NO_ERROR);
|
2009-08-26 23:36:26 +00:00
|
|
|
if (!locked) {
|
2014-12-23 21:57:23 +00:00
|
|
|
result.appendFormat(
|
|
|
|
"SurfaceFlinger appears to be unresponsive (%s [%d]), "
|
|
|
|
"dumping anyways (no locks held)\n", strerror(-err), err);
|
2009-08-26 23:36:26 +00:00
|
|
|
}
|
|
|
|
|
2012-01-20 02:34:40 +00:00
|
|
|
bool dumpAll = true;
|
|
|
|
size_t index = 0;
|
2012-01-29 06:31:55 +00:00
|
|
|
size_t numArgs = args.size();
|
|
|
|
if (numArgs) {
|
|
|
|
if ((index < numArgs) &&
|
|
|
|
(args[index] == String16("--list"))) {
|
|
|
|
index++;
|
2013-04-22 14:55:35 +00:00
|
|
|
listLayersLocked(args, index, result);
|
2012-03-09 06:01:51 +00:00
|
|
|
dumpAll = false;
|
2012-01-29 06:31:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((index < numArgs) &&
|
|
|
|
(args[index] == String16("--latency"))) {
|
2012-01-20 02:34:40 +00:00
|
|
|
index++;
|
2013-04-22 14:55:35 +00:00
|
|
|
dumpStatsLocked(args, index, result);
|
2012-03-09 06:01:51 +00:00
|
|
|
dumpAll = false;
|
2012-01-20 02:34:40 +00:00
|
|
|
}
|
2012-01-29 06:31:55 +00:00
|
|
|
|
|
|
|
if ((index < numArgs) &&
|
|
|
|
(args[index] == String16("--latency-clear"))) {
|
|
|
|
index++;
|
2013-04-22 14:55:35 +00:00
|
|
|
clearStatsLocked(args, index, result);
|
2012-03-09 06:01:51 +00:00
|
|
|
dumpAll = false;
|
2012-01-29 06:31:55 +00:00
|
|
|
}
|
2014-05-08 21:53:26 +00:00
|
|
|
|
|
|
|
if ((index < numArgs) &&
|
|
|
|
(args[index] == String16("--dispsync"))) {
|
|
|
|
index++;
|
|
|
|
mPrimaryDispSync.dump(result);
|
|
|
|
dumpAll = false;
|
|
|
|
}
|
2015-03-05 19:05:59 +00:00
|
|
|
|
|
|
|
if ((index < numArgs) &&
|
|
|
|
(args[index] == String16("--static-screen"))) {
|
|
|
|
index++;
|
|
|
|
dumpStaticScreenStats(result);
|
|
|
|
dumpAll = false;
|
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
2010-04-21 00:55:49 +00:00
|
|
|
|
2012-01-20 02:34:40 +00:00
|
|
|
if (dumpAll) {
|
2013-04-22 14:55:35 +00:00
|
|
|
dumpAllLocked(args, index, result);
|
2012-01-20 02:34:40 +00:00
|
|
|
}
|
2011-01-20 00:15:53 +00:00
|
|
|
|
2012-01-20 02:34:40 +00:00
|
|
|
if (locked) {
|
|
|
|
mStateLock.unlock();
|
2011-01-20 00:15:53 +00:00
|
|
|
}
|
2012-01-20 02:34:40 +00:00
|
|
|
}
|
|
|
|
write(fd, result.string(), result.size());
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
2011-01-20 00:15:53 +00:00
|
|
|
|
2014-02-14 23:03:43 +00:00
|
|
|
void SurfaceFlinger::listLayersLocked(const Vector<String16>& /* args */,
|
|
|
|
size_t& /* index */, String8& result) const
|
2012-01-29 06:31:55 +00:00
|
|
|
{
|
|
|
|
const LayerVector& currentLayers = mCurrentState.layersSortedByZ;
|
|
|
|
const size_t count = currentLayers.size();
|
|
|
|
for (size_t i=0 ; i<count ; i++) {
|
2013-03-06 01:47:11 +00:00
|
|
|
const sp<Layer>& layer(currentLayers[i]);
|
2013-04-22 14:55:35 +00:00
|
|
|
result.appendFormat("%s\n", layer->getName().string());
|
2012-01-29 06:31:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-20 02:34:40 +00:00
|
|
|
void SurfaceFlinger::dumpStatsLocked(const Vector<String16>& args, size_t& index,
|
2013-04-22 14:55:35 +00:00
|
|
|
String8& result) const
|
2012-01-20 02:34:40 +00:00
|
|
|
{
|
|
|
|
String8 name;
|
|
|
|
if (index < args.size()) {
|
|
|
|
name = String8(args[index]);
|
|
|
|
index++;
|
|
|
|
}
|
2011-01-20 00:15:53 +00:00
|
|
|
|
2013-02-05 21:30:24 +00:00
|
|
|
const nsecs_t period =
|
|
|
|
getHwComposer().getRefreshPeriod(HWC_DISPLAY_PRIMARY);
|
2014-03-07 20:44:02 +00:00
|
|
|
result.appendFormat("%" PRId64 "\n", period);
|
2013-02-05 21:30:24 +00:00
|
|
|
|
|
|
|
if (name.isEmpty()) {
|
2014-03-20 17:28:31 +00:00
|
|
|
mAnimFrameTracker.dumpStats(result);
|
2013-02-05 21:30:24 +00:00
|
|
|
} else {
|
2014-07-17 18:36:08 +00:00
|
|
|
bool found = false;
|
2013-02-05 21:30:24 +00:00
|
|
|
const LayerVector& currentLayers = mCurrentState.layersSortedByZ;
|
|
|
|
const size_t count = currentLayers.size();
|
|
|
|
for (size_t i=0 ; i<count ; i++) {
|
2013-03-06 01:47:11 +00:00
|
|
|
const sp<Layer>& layer(currentLayers[i]);
|
2013-02-05 21:30:24 +00:00
|
|
|
if (name == layer->getName()) {
|
2014-07-17 18:36:08 +00:00
|
|
|
found = true;
|
2014-03-20 17:28:31 +00:00
|
|
|
layer->dumpFrameStats(result);
|
2013-02-05 21:30:24 +00:00
|
|
|
}
|
2012-01-20 02:34:40 +00:00
|
|
|
}
|
2014-07-17 18:36:08 +00:00
|
|
|
if (!found && !strncmp(name.string(), "SurfaceView", 11)) {
|
|
|
|
lastSurfaceViewLayer->dumpFrameStats(result);
|
|
|
|
}
|
2012-01-20 02:34:40 +00:00
|
|
|
}
|
|
|
|
}
|
2011-07-15 01:01:49 +00:00
|
|
|
|
2012-01-29 06:31:55 +00:00
|
|
|
void SurfaceFlinger::clearStatsLocked(const Vector<String16>& args, size_t& index,
|
2014-02-14 23:03:43 +00:00
|
|
|
String8& /* result */)
|
2012-01-29 06:31:55 +00:00
|
|
|
{
|
|
|
|
String8 name;
|
|
|
|
if (index < args.size()) {
|
|
|
|
name = String8(args[index]);
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
const LayerVector& currentLayers = mCurrentState.layersSortedByZ;
|
|
|
|
const size_t count = currentLayers.size();
|
|
|
|
for (size_t i=0 ; i<count ; i++) {
|
2013-03-06 01:47:11 +00:00
|
|
|
const sp<Layer>& layer(currentLayers[i]);
|
2012-01-29 06:31:55 +00:00
|
|
|
if (name.isEmpty() || (name == layer->getName())) {
|
2014-03-20 17:28:31 +00:00
|
|
|
layer->clearFrameStats();
|
2012-01-29 06:31:55 +00:00
|
|
|
}
|
|
|
|
}
|
2013-02-05 21:30:24 +00:00
|
|
|
|
2014-03-20 17:28:31 +00:00
|
|
|
mAnimFrameTracker.clearStats();
|
2012-01-29 06:31:55 +00:00
|
|
|
}
|
|
|
|
|
2013-07-17 03:12:42 +00:00
|
|
|
// This should only be called from the main thread. Otherwise it would need
|
|
|
|
// the lock and should use mCurrentState rather than mDrawingState.
|
|
|
|
void SurfaceFlinger::logFrameStats() {
|
|
|
|
const LayerVector& drawingLayers = mDrawingState.layersSortedByZ;
|
|
|
|
const size_t count = drawingLayers.size();
|
|
|
|
for (size_t i=0 ; i<count ; i++) {
|
|
|
|
const sp<Layer>& layer(drawingLayers[i]);
|
|
|
|
layer->logFrameStats();
|
|
|
|
}
|
|
|
|
|
|
|
|
mAnimFrameTracker.logAndResetStats(String8("<win-anim>"));
|
|
|
|
}
|
|
|
|
|
2012-09-25 02:07:20 +00:00
|
|
|
/*static*/ void SurfaceFlinger::appendSfConfigString(String8& result)
|
|
|
|
{
|
|
|
|
static const char* config =
|
|
|
|
" [sf"
|
|
|
|
#ifdef HAS_CONTEXT_PRIORITY
|
|
|
|
" HAS_CONTEXT_PRIORITY"
|
|
|
|
#endif
|
|
|
|
#ifdef NEVER_DEFAULT_TO_ASYNC_MODE
|
|
|
|
" NEVER_DEFAULT_TO_ASYNC_MODE"
|
|
|
|
#endif
|
|
|
|
#ifdef TARGET_DISABLE_TRIPLE_BUFFERING
|
|
|
|
" TARGET_DISABLE_TRIPLE_BUFFERING"
|
|
|
|
#endif
|
|
|
|
"]";
|
|
|
|
result.append(config);
|
|
|
|
}
|
|
|
|
|
2015-03-05 19:05:59 +00:00
|
|
|
void SurfaceFlinger::dumpStaticScreenStats(String8& result) const
|
|
|
|
{
|
|
|
|
result.appendFormat("Static screen stats:\n");
|
|
|
|
for (size_t b = 0; b < NUM_BUCKETS - 1; ++b) {
|
|
|
|
float bucketTimeSec = mFrameBuckets[b] / 1e9;
|
|
|
|
float percent = 100.0f *
|
|
|
|
static_cast<float>(mFrameBuckets[b]) / mTotalTime;
|
|
|
|
result.appendFormat(" < %zd frames: %.3f s (%.1f%%)\n",
|
|
|
|
b + 1, bucketTimeSec, percent);
|
|
|
|
}
|
|
|
|
float bucketTimeSec = mFrameBuckets[NUM_BUCKETS - 1] / 1e9;
|
|
|
|
float percent = 100.0f *
|
|
|
|
static_cast<float>(mFrameBuckets[NUM_BUCKETS - 1]) / mTotalTime;
|
|
|
|
result.appendFormat(" %zd+ frames: %.3f s (%.1f%%)\n",
|
|
|
|
NUM_BUCKETS - 1, bucketTimeSec, percent);
|
|
|
|
}
|
|
|
|
|
2013-04-22 14:55:35 +00:00
|
|
|
void SurfaceFlinger::dumpAllLocked(const Vector<String16>& args, size_t& index,
|
|
|
|
String8& result) const
|
2012-01-20 02:34:40 +00:00
|
|
|
{
|
2013-04-22 15:52:16 +00:00
|
|
|
bool colorize = false;
|
|
|
|
if (index < args.size()
|
|
|
|
&& (args[index] == String16("--color"))) {
|
|
|
|
colorize = true;
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
Colorizer colorizer(colorize);
|
|
|
|
|
2012-01-20 02:34:40 +00:00
|
|
|
// figure out if we're stuck somewhere
|
|
|
|
const nsecs_t now = systemTime();
|
|
|
|
const nsecs_t inSwapBuffers(mDebugInSwapBuffers);
|
|
|
|
const nsecs_t inTransaction(mDebugInTransaction);
|
|
|
|
nsecs_t inSwapBuffersDuration = (inSwapBuffers) ? now-inSwapBuffers : 0;
|
|
|
|
nsecs_t inTransactionDuration = (inTransaction) ? now-inTransaction : 0;
|
2011-11-30 01:55:46 +00:00
|
|
|
|
2012-09-25 02:07:20 +00:00
|
|
|
/*
|
|
|
|
* Dump library configuration.
|
|
|
|
*/
|
2013-04-22 15:52:16 +00:00
|
|
|
|
|
|
|
colorizer.bold(result);
|
2012-09-25 02:07:20 +00:00
|
|
|
result.append("Build configuration:");
|
2013-04-22 15:52:16 +00:00
|
|
|
colorizer.reset(result);
|
2012-09-25 02:07:20 +00:00
|
|
|
appendSfConfigString(result);
|
|
|
|
appendUiConfigString(result);
|
|
|
|
appendGuiConfigString(result);
|
|
|
|
result.append("\n");
|
|
|
|
|
2013-04-22 15:52:16 +00:00
|
|
|
colorizer.bold(result);
|
2013-03-29 00:44:13 +00:00
|
|
|
result.append("Sync configuration: ");
|
2013-04-22 15:52:16 +00:00
|
|
|
colorizer.reset(result);
|
2013-03-29 00:44:13 +00:00
|
|
|
result.append(SyncFeatures::getInstance().toString());
|
|
|
|
result.append("\n");
|
|
|
|
|
2014-04-25 23:58:34 +00:00
|
|
|
colorizer.bold(result);
|
|
|
|
result.append("DispSync configuration: ");
|
|
|
|
colorizer.reset(result);
|
2014-07-13 21:37:16 +00:00
|
|
|
result.appendFormat("app phase %" PRId64 " ns, sf phase %" PRId64 " ns, "
|
|
|
|
"present offset %d ns (refresh %" PRId64 " ns)",
|
2014-04-25 23:58:34 +00:00
|
|
|
vsyncPhaseOffsetNs, sfVsyncPhaseOffsetNs, PRESENT_TIME_OFFSET_FROM_VSYNC_NS,
|
|
|
|
mHwc->getRefreshPeriod(HWC_DISPLAY_PRIMARY));
|
|
|
|
result.append("\n");
|
|
|
|
|
2015-03-05 19:05:59 +00:00
|
|
|
// Dump static screen stats
|
|
|
|
result.append("\n");
|
|
|
|
dumpStaticScreenStats(result);
|
|
|
|
result.append("\n");
|
|
|
|
|
2012-01-20 02:34:40 +00:00
|
|
|
/*
|
|
|
|
* Dump the visible layer list
|
|
|
|
*/
|
|
|
|
const LayerVector& currentLayers = mCurrentState.layersSortedByZ;
|
|
|
|
const size_t count = currentLayers.size();
|
2013-04-22 15:52:16 +00:00
|
|
|
colorizer.bold(result);
|
2014-03-07 20:44:02 +00:00
|
|
|
result.appendFormat("Visible layers (count = %zu)\n", count);
|
2013-04-22 15:52:16 +00:00
|
|
|
colorizer.reset(result);
|
2012-01-20 02:34:40 +00:00
|
|
|
for (size_t i=0 ; i<count ; i++) {
|
2013-03-06 01:47:11 +00:00
|
|
|
const sp<Layer>& layer(currentLayers[i]);
|
2013-04-22 15:52:16 +00:00
|
|
|
layer->dump(result, colorizer);
|
2012-01-20 02:34:40 +00:00
|
|
|
}
|
2011-11-30 01:55:46 +00:00
|
|
|
|
2012-08-11 01:50:38 +00:00
|
|
|
/*
|
|
|
|
* Dump Display state
|
|
|
|
*/
|
|
|
|
|
2013-04-22 15:52:16 +00:00
|
|
|
colorizer.bold(result);
|
2014-03-07 20:44:02 +00:00
|
|
|
result.appendFormat("Displays (%zu entries)\n", mDisplays.size());
|
2013-04-22 15:52:16 +00:00
|
|
|
colorizer.reset(result);
|
2012-08-11 01:50:38 +00:00
|
|
|
for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
|
|
|
|
const sp<const DisplayDevice>& hw(mDisplays[dpy]);
|
2013-04-22 14:55:35 +00:00
|
|
|
hw->dump(result);
|
2012-08-11 01:50:38 +00:00
|
|
|
}
|
|
|
|
|
2012-01-20 02:34:40 +00:00
|
|
|
/*
|
|
|
|
* Dump SurfaceFlinger global state
|
|
|
|
*/
|
2010-04-21 00:55:49 +00:00
|
|
|
|
2013-04-22 15:52:16 +00:00
|
|
|
colorizer.bold(result);
|
2013-04-22 14:55:35 +00:00
|
|
|
result.append("SurfaceFlinger global state:\n");
|
2013-04-22 15:52:16 +00:00
|
|
|
colorizer.reset(result);
|
2010-04-21 00:55:49 +00:00
|
|
|
|
2012-08-05 04:10:38 +00:00
|
|
|
HWComposer& hwc(getHwComposer());
|
2012-08-05 07:40:46 +00:00
|
|
|
sp<const DisplayDevice> hw(getDefaultDisplayDevice());
|
2013-03-29 00:44:13 +00:00
|
|
|
|
2013-04-22 15:52:16 +00:00
|
|
|
colorizer.bold(result);
|
|
|
|
result.appendFormat("EGL implementation : %s\n",
|
|
|
|
eglQueryStringImplementationANDROID(mEGLDisplay, EGL_VERSION));
|
|
|
|
colorizer.reset(result);
|
|
|
|
result.appendFormat("%s\n",
|
2013-03-29 00:44:13 +00:00
|
|
|
eglQueryStringImplementationANDROID(mEGLDisplay, EGL_EXTENSIONS));
|
|
|
|
|
2013-06-07 22:35:48 +00:00
|
|
|
mRenderEngine->dump(result);
|
2009-08-26 23:36:26 +00:00
|
|
|
|
2012-08-05 07:40:46 +00:00
|
|
|
hw->undefinedRegion.dump(result, "undefinedRegion");
|
2014-05-25 08:36:31 +00:00
|
|
|
result.appendFormat(" orientation=%d, isDisplayOn=%d\n",
|
|
|
|
hw->getOrientation(), hw->isDisplayOn());
|
2013-04-22 14:55:35 +00:00
|
|
|
result.appendFormat(
|
2012-01-20 02:34:40 +00:00
|
|
|
" last eglSwapBuffers() time: %f us\n"
|
|
|
|
" last transaction time : %f us\n"
|
2012-02-05 08:19:27 +00:00
|
|
|
" transaction-flags : %08x\n"
|
2012-01-20 02:34:40 +00:00
|
|
|
" refresh-rate : %f fps\n"
|
|
|
|
" x-dpi : %f\n"
|
2013-03-22 07:24:39 +00:00
|
|
|
" y-dpi : %f\n"
|
|
|
|
" gpu_to_cpu_unsupported : %d\n"
|
|
|
|
,
|
2012-01-20 02:34:40 +00:00
|
|
|
mLastSwapBufferTime/1000.0,
|
|
|
|
mLastTransactionTime/1000.0,
|
2012-02-05 08:19:27 +00:00
|
|
|
mTransactionFlags,
|
2012-09-10 21:08:09 +00:00
|
|
|
1e9 / hwc.getRefreshPeriod(HWC_DISPLAY_PRIMARY),
|
|
|
|
hwc.getDpiX(HWC_DISPLAY_PRIMARY),
|
2013-03-22 07:24:39 +00:00
|
|
|
hwc.getDpiY(HWC_DISPLAY_PRIMARY),
|
|
|
|
!mGpuToCpuSupported);
|
2012-01-20 02:34:40 +00:00
|
|
|
|
2013-04-22 14:55:35 +00:00
|
|
|
result.appendFormat(" eglSwapBuffers time: %f us\n",
|
2012-01-20 02:34:40 +00:00
|
|
|
inSwapBuffersDuration/1000.0);
|
|
|
|
|
2013-04-22 14:55:35 +00:00
|
|
|
result.appendFormat(" transaction time: %f us\n",
|
2012-01-20 02:34:40 +00:00
|
|
|
inTransactionDuration/1000.0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* VSYNC state
|
|
|
|
*/
|
2013-04-22 14:55:35 +00:00
|
|
|
mEventThread->dump(result);
|
2012-01-20 02:34:40 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Dump HWComposer state
|
|
|
|
*/
|
2013-04-22 15:52:16 +00:00
|
|
|
colorizer.bold(result);
|
2013-04-22 14:55:35 +00:00
|
|
|
result.append("h/w composer state:\n");
|
2013-04-22 15:52:16 +00:00
|
|
|
colorizer.reset(result);
|
2013-04-22 14:55:35 +00:00
|
|
|
result.appendFormat(" h/w composer %s and %s\n",
|
2012-01-20 02:34:40 +00:00
|
|
|
hwc.initCheck()==NO_ERROR ? "present" : "not present",
|
2013-09-13 03:04:35 +00:00
|
|
|
(mDebugDisableHWC || mDebugRegion || mDaltonize
|
|
|
|
|| mHasColorMatrix) ? "disabled" : "enabled");
|
2013-04-22 14:55:35 +00:00
|
|
|
hwc.dump(result);
|
2012-01-20 02:34:40 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Dump gralloc state
|
|
|
|
*/
|
|
|
|
const GraphicBufferAllocator& alloc(GraphicBufferAllocator::get());
|
|
|
|
alloc.dump(result);
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2013-03-06 01:47:11 +00:00
|
|
|
const Vector< sp<Layer> >&
|
2013-03-21 21:06:52 +00:00
|
|
|
SurfaceFlinger::getLayerSortedByZForHwcDisplay(int id) {
|
2012-10-15 23:51:41 +00:00
|
|
|
// Note: mStateLock is held here
|
2013-03-21 21:06:52 +00:00
|
|
|
wp<IBinder> dpy;
|
|
|
|
for (size_t i=0 ; i<mDisplays.size() ; i++) {
|
|
|
|
if (mDisplays.valueAt(i)->getHwcDisplayId() == id) {
|
|
|
|
dpy = mDisplays.keyAt(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dpy == NULL) {
|
|
|
|
ALOGE("getLayerSortedByZForHwcDisplay: invalid hwc display id %d", id);
|
|
|
|
// Just use the primary display so we have something to return
|
|
|
|
dpy = getBuiltInDisplay(DisplayDevice::DISPLAY_PRIMARY);
|
|
|
|
}
|
|
|
|
return getDisplayDevice(dpy)->getVisibleLayersSortedByZ();
|
2012-10-04 22:58:54 +00:00
|
|
|
}
|
|
|
|
|
2012-08-31 17:53:36 +00:00
|
|
|
bool SurfaceFlinger::startDdmConnection()
|
|
|
|
{
|
|
|
|
void* libddmconnection_dso =
|
|
|
|
dlopen("libsurfaceflinger_ddmconnection.so", RTLD_NOW);
|
|
|
|
if (!libddmconnection_dso) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
void (*DdmConnection_start)(const char* name);
|
|
|
|
DdmConnection_start =
|
2014-07-13 21:37:16 +00:00
|
|
|
(decltype(DdmConnection_start))dlsym(libddmconnection_dso, "DdmConnection_start");
|
2012-08-31 17:53:36 +00:00
|
|
|
if (!DdmConnection_start) {
|
|
|
|
dlclose(libddmconnection_dso);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
(*DdmConnection_start)(getServiceName());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
status_t SurfaceFlinger::onTransact(
|
|
|
|
uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
|
|
|
|
{
|
|
|
|
switch (code) {
|
|
|
|
case CREATE_CONNECTION:
|
2013-03-16 01:31:56 +00:00
|
|
|
case CREATE_DISPLAY:
|
2011-06-29 02:09:31 +00:00
|
|
|
case SET_TRANSACTION_STATE:
|
2009-03-04 03:31:44 +00:00
|
|
|
case BOOT_FINISHED:
|
2014-03-20 17:28:31 +00:00
|
|
|
case CLEAR_ANIMATION_FRAME_STATS:
|
|
|
|
case GET_ANIMATION_FRAME_STATS:
|
2014-05-25 08:36:31 +00:00
|
|
|
case SET_POWER_MODE:
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
|
|
|
// codes that require permission check
|
|
|
|
IPCThreadState* ipc = IPCThreadState::self();
|
|
|
|
const int pid = ipc->getCallingPid();
|
2009-05-22 02:21:59 +00:00
|
|
|
const int uid = ipc->getCallingUid();
|
2015-04-11 03:20:13 +00:00
|
|
|
if ((uid != AID_GRAPHICS && uid != AID_SYSTEM) &&
|
2011-06-27 23:05:52 +00:00
|
|
|
!PermissionCache::checkPermission(sAccessSurfaceFlinger, pid, uid)) {
|
2012-01-06 19:20:56 +00:00
|
|
|
ALOGE("Permission Denial: "
|
2009-06-16 01:24:59 +00:00
|
|
|
"can't access SurfaceFlinger pid=%d, uid=%d", pid, uid);
|
|
|
|
return PERMISSION_DENIED;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
2010-09-24 18:26:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CAPTURE_SCREEN:
|
|
|
|
{
|
|
|
|
// codes that require permission check
|
|
|
|
IPCThreadState* ipc = IPCThreadState::self();
|
|
|
|
const int pid = ipc->getCallingPid();
|
|
|
|
const int uid = ipc->getCallingUid();
|
2011-06-27 23:05:52 +00:00
|
|
|
if ((uid != AID_GRAPHICS) &&
|
|
|
|
!PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) {
|
2012-01-06 19:20:56 +00:00
|
|
|
ALOGE("Permission Denial: "
|
2010-09-24 18:26:58 +00:00
|
|
|
"can't read framebuffer pid=%d, uid=%d", pid, uid);
|
|
|
|
return PERMISSION_DENIED;
|
|
|
|
}
|
|
|
|
break;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
}
|
2010-09-24 18:26:58 +00:00
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
status_t err = BnSurfaceComposer::onTransact(code, data, reply, flags);
|
|
|
|
if (err == UNKNOWN_TRANSACTION || err == PERMISSION_DENIED) {
|
2009-06-27 02:06:36 +00:00
|
|
|
CHECK_INTERFACE(ISurfaceComposer, data, reply);
|
2011-12-15 17:51:17 +00:00
|
|
|
if (CC_UNLIKELY(!PermissionCache::checkCallingPermission(sHardwareTest))) {
|
2009-06-16 01:24:59 +00:00
|
|
|
IPCThreadState* ipc = IPCThreadState::self();
|
|
|
|
const int pid = ipc->getCallingPid();
|
|
|
|
const int uid = ipc->getCallingUid();
|
2012-01-06 19:20:56 +00:00
|
|
|
ALOGE("Permission Denial: "
|
2009-06-16 01:24:59 +00:00
|
|
|
"can't access SurfaceFlinger pid=%d, uid=%d", pid, uid);
|
2009-03-04 03:31:44 +00:00
|
|
|
return PERMISSION_DENIED;
|
|
|
|
}
|
|
|
|
int n;
|
|
|
|
switch (code) {
|
2009-04-17 03:04:08 +00:00
|
|
|
case 1000: // SHOW_CPU, NOT SUPPORTED ANYMORE
|
2010-09-14 05:57:58 +00:00
|
|
|
case 1001: // SHOW_FPS, NOT SUPPORTED ANYMORE
|
2009-03-04 03:31:44 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
case 1002: // SHOW_UPDATES
|
|
|
|
n = data.readInt32();
|
|
|
|
mDebugRegion = n ? n : (mDebugRegion ? 0 : 1);
|
2011-08-23 04:44:41 +00:00
|
|
|
invalidateHwcGeometry();
|
|
|
|
repaintEverything();
|
2009-03-04 03:31:44 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
case 1004:{ // repaint everything
|
2011-08-23 04:44:41 +00:00
|
|
|
repaintEverything();
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
case 1005:{ // force transaction
|
2012-08-09 23:29:12 +00:00
|
|
|
setTransactionFlags(
|
|
|
|
eTransactionNeeded|
|
|
|
|
eDisplayTransactionNeeded|
|
|
|
|
eTraversalNeeded);
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
return NO_ERROR;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
2012-02-24 04:05:39 +00:00
|
|
|
case 1006:{ // send empty update
|
|
|
|
signalRefresh();
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
2011-08-23 04:44:41 +00:00
|
|
|
case 1008: // toggle use of hw composer
|
|
|
|
n = data.readInt32();
|
|
|
|
mDebugDisableHWC = n ? 1 : 0;
|
|
|
|
invalidateHwcGeometry();
|
|
|
|
repaintEverything();
|
|
|
|
return NO_ERROR;
|
2011-08-24 01:03:18 +00:00
|
|
|
case 1009: // toggle use of transform hint
|
|
|
|
n = data.readInt32();
|
|
|
|
mDebugDisableTransformHint = n ? 1 : 0;
|
|
|
|
invalidateHwcGeometry();
|
|
|
|
repaintEverything();
|
|
|
|
return NO_ERROR;
|
2009-03-04 03:31:44 +00:00
|
|
|
case 1010: // interrogate.
|
2009-04-17 03:04:08 +00:00
|
|
|
reply->writeInt32(0);
|
2009-03-04 03:31:44 +00:00
|
|
|
reply->writeInt32(0);
|
|
|
|
reply->writeInt32(mDebugRegion);
|
2012-04-18 09:28:45 +00:00
|
|
|
reply->writeInt32(0);
|
2012-02-07 05:21:05 +00:00
|
|
|
reply->writeInt32(mDebugDisableHWC);
|
2009-03-04 03:31:44 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
case 1013: {
|
|
|
|
Mutex::Autolock _l(mStateLock);
|
2012-08-05 07:40:46 +00:00
|
|
|
sp<const DisplayDevice> hw(getDefaultDisplayDevice());
|
|
|
|
reply->writeInt32(hw->getPageFlipCount());
|
2013-09-02 04:36:12 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
case 1014: {
|
|
|
|
// daltonize
|
|
|
|
n = data.readInt32();
|
|
|
|
switch (n % 10) {
|
|
|
|
case 1: mDaltonizer.setType(Daltonizer::protanomaly); break;
|
|
|
|
case 2: mDaltonizer.setType(Daltonizer::deuteranomaly); break;
|
|
|
|
case 3: mDaltonizer.setType(Daltonizer::tritanomaly); break;
|
|
|
|
}
|
|
|
|
if (n >= 10) {
|
|
|
|
mDaltonizer.setMode(Daltonizer::correction);
|
|
|
|
} else {
|
|
|
|
mDaltonizer.setMode(Daltonizer::simulation);
|
|
|
|
}
|
|
|
|
mDaltonize = n > 0;
|
|
|
|
invalidateHwcGeometry();
|
|
|
|
repaintEverything();
|
2013-09-13 03:04:35 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
case 1015: {
|
|
|
|
// apply a color matrix
|
|
|
|
n = data.readInt32();
|
|
|
|
mHasColorMatrix = n ? 1 : 0;
|
|
|
|
if (n) {
|
|
|
|
// color matrix is sent as mat3 matrix followed by vec3
|
|
|
|
// offset, then packed into a mat4 where the last row is
|
|
|
|
// the offset and extra values are 0
|
2013-10-03 23:40:52 +00:00
|
|
|
for (size_t i = 0 ; i < 4; i++) {
|
|
|
|
for (size_t j = 0; j < 4; j++) {
|
|
|
|
mColorMatrix[i][j] = data.readFloat();
|
|
|
|
}
|
2013-09-13 03:04:35 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mColorMatrix = mat4();
|
|
|
|
}
|
|
|
|
invalidateHwcGeometry();
|
|
|
|
repaintEverything();
|
|
|
|
return NO_ERROR;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
2014-04-24 23:42:35 +00:00
|
|
|
// This is an experimental interface
|
|
|
|
// Needs to be shifted to proper binder interface when we productize
|
|
|
|
case 1016: {
|
2014-06-10 21:43:32 +00:00
|
|
|
n = data.readInt32();
|
|
|
|
mPrimaryDispSync.setRefreshSkipCount(n);
|
2014-04-24 23:42:35 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
}
|
2015-03-23 22:50:23 +00:00
|
|
|
case 1017: {
|
|
|
|
n = data.readInt32();
|
|
|
|
mForceFullDamage = static_cast<bool>(n);
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
2015-04-14 18:34:01 +00:00
|
|
|
case 1018: { // Modify Choreographer's phase offset
|
|
|
|
n = data.readInt32();
|
|
|
|
mEventThread->setPhaseOffset(static_cast<nsecs_t>(n));
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
case 1019: { // Modify SurfaceFlinger's phase offset
|
|
|
|
n = data.readInt32();
|
|
|
|
mSFEventThread->setPhaseOffset(static_cast<nsecs_t>(n));
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-08-23 04:44:41 +00:00
|
|
|
void SurfaceFlinger::repaintEverything() {
|
2012-07-31 19:38:26 +00:00
|
|
|
android_atomic_or(1, &mRepaintEverything);
|
2012-02-01 02:24:27 +00:00
|
|
|
signalTransaction();
|
2011-08-23 04:44:41 +00:00
|
|
|
}
|
|
|
|
|
2013-03-01 21:42:57 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// Capture screen into an IGraphiBufferProducer
|
2010-10-11 19:37:43 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2013-07-09 00:09:41 +00:00
|
|
|
/* The code below is here to handle b/8734824
|
|
|
|
*
|
|
|
|
* We create a IGraphicBufferProducer wrapper that forwards all calls
|
2014-07-13 19:47:02 +00:00
|
|
|
* from the surfaceflinger thread to the calling binder thread, where they
|
|
|
|
* are executed. This allows the calling thread in the calling process to be
|
|
|
|
* reused and not depend on having "enough" binder threads to handle the
|
|
|
|
* requests.
|
2013-07-09 00:09:41 +00:00
|
|
|
*/
|
|
|
|
class GraphicProducerWrapper : public BBinder, public MessageHandler {
|
2014-07-13 19:47:02 +00:00
|
|
|
/* Parts of GraphicProducerWrapper are run on two different threads,
|
|
|
|
* communicating by sending messages via Looper but also by shared member
|
|
|
|
* data. Coherence maintenance is subtle and in places implicit (ugh).
|
|
|
|
*
|
|
|
|
* Don't rely on Looper's sendMessage/handleMessage providing
|
|
|
|
* release/acquire semantics for any data not actually in the Message.
|
|
|
|
* Data going from surfaceflinger to binder threads needs to be
|
|
|
|
* synchronized explicitly.
|
|
|
|
*
|
|
|
|
* Barrier open/wait do provide release/acquire semantics. This provides
|
|
|
|
* implicit synchronization for data coming back from binder to
|
|
|
|
* surfaceflinger threads.
|
|
|
|
*/
|
|
|
|
|
2013-07-09 00:09:41 +00:00
|
|
|
sp<IGraphicBufferProducer> impl;
|
|
|
|
sp<Looper> looper;
|
|
|
|
status_t result;
|
|
|
|
bool exitPending;
|
|
|
|
bool exitRequested;
|
2014-07-13 19:47:02 +00:00
|
|
|
Barrier barrier;
|
2013-07-09 00:09:41 +00:00
|
|
|
uint32_t code;
|
|
|
|
Parcel const* data;
|
|
|
|
Parcel* reply;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
MSG_API_CALL,
|
|
|
|
MSG_EXIT
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2014-07-13 19:47:02 +00:00
|
|
|
* Called on surfaceflinger thread. This is called by our "fake"
|
|
|
|
* BpGraphicBufferProducer. We package the data and reply Parcel and
|
|
|
|
* forward them to the binder thread.
|
2013-07-09 00:09:41 +00:00
|
|
|
*/
|
|
|
|
virtual status_t transact(uint32_t code,
|
2014-02-14 23:03:43 +00:00
|
|
|
const Parcel& data, Parcel* reply, uint32_t /* flags */) {
|
2013-07-09 00:09:41 +00:00
|
|
|
this->code = code;
|
|
|
|
this->data = &data;
|
|
|
|
this->reply = reply;
|
|
|
|
if (exitPending) {
|
2014-07-13 19:47:02 +00:00
|
|
|
// if we've exited, we run the message synchronously right here.
|
|
|
|
// note (JH): as far as I can tell from looking at the code, this
|
|
|
|
// never actually happens. if it does, i'm not sure if it happens
|
|
|
|
// on the surfaceflinger or binder thread.
|
2013-07-09 00:09:41 +00:00
|
|
|
handleMessage(Message(MSG_API_CALL));
|
|
|
|
} else {
|
|
|
|
barrier.close();
|
2014-07-13 19:47:02 +00:00
|
|
|
// Prevent stores to this->{code, data, reply} from being
|
|
|
|
// reordered later than the construction of Message.
|
|
|
|
atomic_thread_fence(memory_order_release);
|
2013-07-09 00:09:41 +00:00
|
|
|
looper->sendMessage(this, Message(MSG_API_CALL));
|
|
|
|
barrier.wait();
|
|
|
|
}
|
2014-03-20 01:15:34 +00:00
|
|
|
return result;
|
2013-07-09 00:09:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-07-13 19:47:02 +00:00
|
|
|
* here we run on the binder thread. All we've got to do is
|
2013-07-09 00:09:41 +00:00
|
|
|
* call the real BpGraphicBufferProducer.
|
|
|
|
*/
|
|
|
|
virtual void handleMessage(const Message& message) {
|
2014-07-13 19:47:02 +00:00
|
|
|
int what = message.what;
|
|
|
|
// Prevent reads below from happening before the read from Message
|
|
|
|
atomic_thread_fence(memory_order_acquire);
|
|
|
|
if (what == MSG_API_CALL) {
|
2014-11-14 16:01:01 +00:00
|
|
|
result = IInterface::asBinder(impl)->transact(code, data[0], reply);
|
2013-07-09 00:09:41 +00:00
|
|
|
barrier.open();
|
2014-07-13 19:47:02 +00:00
|
|
|
} else if (what == MSG_EXIT) {
|
2013-07-09 00:09:41 +00:00
|
|
|
exitRequested = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2014-07-13 19:47:02 +00:00
|
|
|
GraphicProducerWrapper(const sp<IGraphicBufferProducer>& impl)
|
|
|
|
: impl(impl),
|
|
|
|
looper(new Looper(true)),
|
|
|
|
exitPending(false),
|
|
|
|
exitRequested(false)
|
|
|
|
{}
|
|
|
|
|
|
|
|
// Binder thread
|
2013-07-09 00:09:41 +00:00
|
|
|
status_t waitForResponse() {
|
|
|
|
do {
|
|
|
|
looper->pollOnce(-1);
|
|
|
|
} while (!exitRequested);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-07-13 19:47:02 +00:00
|
|
|
// Client thread
|
2013-07-09 00:09:41 +00:00
|
|
|
void exit(status_t result) {
|
2013-07-30 17:19:24 +00:00
|
|
|
this->result = result;
|
2013-07-09 00:09:41 +00:00
|
|
|
exitPending = true;
|
2014-07-13 19:47:02 +00:00
|
|
|
// Ensure this->result is visible to the binder thread before it
|
|
|
|
// handles the message.
|
|
|
|
atomic_thread_fence(memory_order_release);
|
2013-07-09 00:09:41 +00:00
|
|
|
looper->sendMessage(this, Message(MSG_EXIT));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-03-01 21:42:57 +00:00
|
|
|
status_t SurfaceFlinger::captureScreen(const sp<IBinder>& display,
|
|
|
|
const sp<IGraphicBufferProducer>& producer,
|
2014-05-22 22:59:05 +00:00
|
|
|
Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
|
2014-02-14 23:03:43 +00:00
|
|
|
uint32_t minLayerZ, uint32_t maxLayerZ,
|
2014-11-18 01:38:33 +00:00
|
|
|
bool useIdentityTransform, ISurfaceComposer::Rotation rotation,
|
|
|
|
bool useReadPixels) {
|
2013-03-01 21:42:57 +00:00
|
|
|
|
|
|
|
if (CC_UNLIKELY(display == 0))
|
|
|
|
return BAD_VALUE;
|
|
|
|
|
|
|
|
if (CC_UNLIKELY(producer == 0))
|
|
|
|
return BAD_VALUE;
|
|
|
|
|
2013-08-13 22:55:43 +00:00
|
|
|
// if we have secure windows on this display, never allow the screen capture
|
|
|
|
// unless the producer interface is local (i.e.: we can take a screenshot for
|
|
|
|
// ourselves).
|
2014-11-14 16:01:01 +00:00
|
|
|
if (!IInterface::asBinder(producer)->localBinder()) {
|
2013-08-13 22:55:43 +00:00
|
|
|
Mutex::Autolock _l(mStateLock);
|
|
|
|
sp<const DisplayDevice> hw(getDisplayDevice(display));
|
|
|
|
if (hw->getSecureLayerVisible()) {
|
|
|
|
ALOGW("FB is protected: PERMISSION_DENIED");
|
|
|
|
return PERMISSION_DENIED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-04 23:20:31 +00:00
|
|
|
// Convert to surfaceflinger's internal rotation type.
|
|
|
|
Transform::orientation_flags rotationFlags;
|
|
|
|
switch (rotation) {
|
|
|
|
case ISurfaceComposer::eRotateNone:
|
|
|
|
rotationFlags = Transform::ROT_0;
|
|
|
|
break;
|
|
|
|
case ISurfaceComposer::eRotate90:
|
|
|
|
rotationFlags = Transform::ROT_90;
|
|
|
|
break;
|
|
|
|
case ISurfaceComposer::eRotate180:
|
|
|
|
rotationFlags = Transform::ROT_180;
|
|
|
|
break;
|
|
|
|
case ISurfaceComposer::eRotate270:
|
|
|
|
rotationFlags = Transform::ROT_270;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rotationFlags = Transform::ROT_0;
|
|
|
|
ALOGE("Invalid rotation passed to captureScreen(): %d\n", rotation);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-03-01 21:42:57 +00:00
|
|
|
class MessageCaptureScreen : public MessageBase {
|
|
|
|
SurfaceFlinger* flinger;
|
|
|
|
sp<IBinder> display;
|
|
|
|
sp<IGraphicBufferProducer> producer;
|
2014-05-22 22:59:05 +00:00
|
|
|
Rect sourceCrop;
|
2013-03-01 21:42:57 +00:00
|
|
|
uint32_t reqWidth, reqHeight;
|
|
|
|
uint32_t minLayerZ,maxLayerZ;
|
2014-02-14 23:03:43 +00:00
|
|
|
bool useIdentityTransform;
|
2014-09-04 23:20:31 +00:00
|
|
|
Transform::orientation_flags rotation;
|
2014-11-18 01:38:33 +00:00
|
|
|
bool useReadPixels;
|
2013-03-01 21:42:57 +00:00
|
|
|
status_t result;
|
|
|
|
public:
|
|
|
|
MessageCaptureScreen(SurfaceFlinger* flinger,
|
|
|
|
const sp<IBinder>& display,
|
|
|
|
const sp<IGraphicBufferProducer>& producer,
|
2014-05-22 22:59:05 +00:00
|
|
|
Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
|
2014-02-14 23:03:43 +00:00
|
|
|
uint32_t minLayerZ, uint32_t maxLayerZ,
|
2014-11-18 01:38:33 +00:00
|
|
|
bool useIdentityTransform, Transform::orientation_flags rotation,
|
|
|
|
bool useReadPixels)
|
2013-03-01 21:42:57 +00:00
|
|
|
: flinger(flinger), display(display), producer(producer),
|
2014-05-22 22:59:05 +00:00
|
|
|
sourceCrop(sourceCrop), reqWidth(reqWidth), reqHeight(reqHeight),
|
2013-03-01 21:42:57 +00:00
|
|
|
minLayerZ(minLayerZ), maxLayerZ(maxLayerZ),
|
2014-02-14 23:03:43 +00:00
|
|
|
useIdentityTransform(useIdentityTransform),
|
2014-09-04 23:20:31 +00:00
|
|
|
rotation(rotation),
|
2014-11-18 01:38:33 +00:00
|
|
|
useReadPixels(useReadPixels),
|
2013-03-01 21:42:57 +00:00
|
|
|
result(PERMISSION_DENIED)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
status_t getResult() const {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
virtual bool handler() {
|
|
|
|
Mutex::Autolock _l(flinger->mStateLock);
|
|
|
|
sp<const DisplayDevice> hw(flinger->getDisplayDevice(display));
|
2014-11-18 01:38:33 +00:00
|
|
|
bool useReadPixels = this->useReadPixels && !flinger->mGpuToCpuSupported;
|
2014-02-14 23:03:43 +00:00
|
|
|
result = flinger->captureScreenImplLocked(hw, producer,
|
2014-05-22 22:59:05 +00:00
|
|
|
sourceCrop, reqWidth, reqHeight, minLayerZ, maxLayerZ,
|
2014-11-18 01:38:33 +00:00
|
|
|
useIdentityTransform, rotation, useReadPixels);
|
2014-11-14 16:01:01 +00:00
|
|
|
static_cast<GraphicProducerWrapper*>(IInterface::asBinder(producer).get())->exit(result);
|
2013-03-01 21:42:57 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-04-10 23:27:17 +00:00
|
|
|
// make sure to process transactions before screenshots -- a transaction
|
|
|
|
// might already be pending but scheduled for VSYNC; this guarantees we
|
|
|
|
// will handle it before the screenshot. When VSYNC finally arrives
|
|
|
|
// the scheduled transaction will be a no-op. If no transactions are
|
|
|
|
// scheduled at this time, this will end-up being a no-op as well.
|
|
|
|
mEventQueue.invalidateTransactionNow();
|
|
|
|
|
2013-07-09 00:09:41 +00:00
|
|
|
// this creates a "fake" BBinder which will serve as a "fake" remote
|
|
|
|
// binder to receive the marshaled calls and forward them to the
|
|
|
|
// real remote (a BpGraphicBufferProducer)
|
|
|
|
sp<GraphicProducerWrapper> wrapper = new GraphicProducerWrapper(producer);
|
|
|
|
|
|
|
|
// the asInterface() call below creates our "fake" BpGraphicBufferProducer
|
|
|
|
// which does the marshaling work forwards to our "fake remote" above.
|
2013-03-01 21:42:57 +00:00
|
|
|
sp<MessageBase> msg = new MessageCaptureScreen(this,
|
2013-07-09 00:09:41 +00:00
|
|
|
display, IGraphicBufferProducer::asInterface( wrapper ),
|
2014-05-22 22:59:05 +00:00
|
|
|
sourceCrop, reqWidth, reqHeight, minLayerZ, maxLayerZ,
|
2014-11-18 01:38:33 +00:00
|
|
|
useIdentityTransform, rotationFlags, useReadPixels);
|
2013-07-09 00:09:41 +00:00
|
|
|
|
|
|
|
status_t res = postMessageAsync(msg);
|
2013-03-01 21:42:57 +00:00
|
|
|
if (res == NO_ERROR) {
|
2013-07-09 00:09:41 +00:00
|
|
|
res = wrapper->waitForResponse();
|
2013-03-01 21:42:57 +00:00
|
|
|
}
|
|
|
|
return res;
|
2011-10-13 23:02:48 +00:00
|
|
|
}
|
|
|
|
|
2013-04-11 05:55:41 +00:00
|
|
|
|
|
|
|
void SurfaceFlinger::renderScreenImplLocked(
|
|
|
|
const sp<const DisplayDevice>& hw,
|
2014-05-22 22:59:05 +00:00
|
|
|
Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
|
2013-04-11 05:55:41 +00:00
|
|
|
uint32_t minLayerZ, uint32_t maxLayerZ,
|
2014-09-04 23:20:31 +00:00
|
|
|
bool yswap, bool useIdentityTransform, Transform::orientation_flags rotation)
|
2013-04-11 05:55:41 +00:00
|
|
|
{
|
|
|
|
ATRACE_CALL();
|
2013-08-08 04:24:32 +00:00
|
|
|
RenderEngine& engine(getRenderEngine());
|
2013-04-11 05:55:41 +00:00
|
|
|
|
|
|
|
// get screen geometry
|
2014-11-13 22:18:56 +00:00
|
|
|
const int32_t hw_w = hw->getWidth();
|
|
|
|
const int32_t hw_h = hw->getHeight();
|
|
|
|
const bool filtering = static_cast<int32_t>(reqWidth) != hw_w ||
|
2015-03-23 21:32:15 +00:00
|
|
|
static_cast<int32_t>(reqHeight) != hw_h;
|
2013-04-11 05:55:41 +00:00
|
|
|
|
2014-05-22 22:59:05 +00:00
|
|
|
// if a default or invalid sourceCrop is passed in, set reasonable values
|
|
|
|
if (sourceCrop.width() == 0 || sourceCrop.height() == 0 ||
|
|
|
|
!sourceCrop.isValid()) {
|
|
|
|
sourceCrop.setLeftTop(Point(0, 0));
|
|
|
|
sourceCrop.setRightBottom(Point(hw_w, hw_h));
|
|
|
|
}
|
|
|
|
|
|
|
|
// ensure that sourceCrop is inside screen
|
|
|
|
if (sourceCrop.left < 0) {
|
|
|
|
ALOGE("Invalid crop rect: l = %d (< 0)", sourceCrop.left);
|
|
|
|
}
|
2014-06-11 18:20:54 +00:00
|
|
|
if (sourceCrop.right > hw_w) {
|
|
|
|
ALOGE("Invalid crop rect: r = %d (> %d)", sourceCrop.right, hw_w);
|
2014-05-22 22:59:05 +00:00
|
|
|
}
|
|
|
|
if (sourceCrop.top < 0) {
|
|
|
|
ALOGE("Invalid crop rect: t = %d (< 0)", sourceCrop.top);
|
|
|
|
}
|
2014-06-11 18:20:54 +00:00
|
|
|
if (sourceCrop.bottom > hw_h) {
|
|
|
|
ALOGE("Invalid crop rect: b = %d (> %d)", sourceCrop.bottom, hw_h);
|
2014-05-22 22:59:05 +00:00
|
|
|
}
|
|
|
|
|
2013-04-11 05:55:41 +00:00
|
|
|
// make sure to clear all GL error flags
|
2013-08-08 04:24:32 +00:00
|
|
|
engine.checkErrors();
|
2013-04-11 05:55:41 +00:00
|
|
|
|
2015-08-21 01:18:30 +00:00
|
|
|
if (DisplayDevice::DISPLAY_PRIMARY == hw->getDisplayType() &&
|
|
|
|
hw->isPanelInverseMounted()) {
|
|
|
|
rotation = (Transform::orientation_flags)
|
|
|
|
(rotation ^ Transform::ROT_180);
|
|
|
|
}
|
|
|
|
|
2013-04-11 05:55:41 +00:00
|
|
|
// set-up our viewport
|
2014-09-04 23:20:31 +00:00
|
|
|
engine.setViewportAndProjection(
|
|
|
|
reqWidth, reqHeight, sourceCrop, hw_h, yswap, rotation);
|
2013-08-08 04:24:32 +00:00
|
|
|
engine.disableTexturing();
|
2013-04-11 05:55:41 +00:00
|
|
|
|
|
|
|
// redraw the screen entirely...
|
2013-08-08 04:24:32 +00:00
|
|
|
engine.clearWithColor(0, 0, 0, 1);
|
2013-04-11 05:55:41 +00:00
|
|
|
|
|
|
|
const LayerVector& layers( mDrawingState.layersSortedByZ );
|
|
|
|
const size_t count = layers.size();
|
|
|
|
for (size_t i=0 ; i<count ; ++i) {
|
|
|
|
const sp<Layer>& layer(layers[i]);
|
2013-06-05 23:59:15 +00:00
|
|
|
const Layer::State& state(layer->getDrawingState());
|
2013-04-11 05:55:41 +00:00
|
|
|
if (state.layerStack == hw->getLayerStack()) {
|
|
|
|
if (state.z >= minLayerZ && state.z <= maxLayerZ) {
|
2015-06-23 19:55:15 +00:00
|
|
|
if (canDrawLayerinScreenShot(hw,layer)) {
|
2013-04-11 05:55:41 +00:00
|
|
|
if (filtering) layer->setFiltering(true);
|
2014-02-14 23:03:43 +00:00
|
|
|
layer->draw(hw, useIdentityTransform);
|
2013-04-11 05:55:41 +00:00
|
|
|
if (filtering) layer->setFiltering(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// compositionComplete is needed for older driver
|
|
|
|
hw->compositionComplete();
|
2013-08-29 01:11:46 +00:00
|
|
|
hw->setViewportAndProjection();
|
2013-04-11 05:55:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-01 21:42:57 +00:00
|
|
|
status_t SurfaceFlinger::captureScreenImplLocked(
|
|
|
|
const sp<const DisplayDevice>& hw,
|
|
|
|
const sp<IGraphicBufferProducer>& producer,
|
2014-05-22 22:59:05 +00:00
|
|
|
Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
|
2014-02-14 23:03:43 +00:00
|
|
|
uint32_t minLayerZ, uint32_t maxLayerZ,
|
2014-11-18 01:38:33 +00:00
|
|
|
bool useIdentityTransform, Transform::orientation_flags rotation,
|
|
|
|
bool useReadPixels)
|
2010-09-29 20:02:36 +00:00
|
|
|
{
|
2012-03-12 19:18:42 +00:00
|
|
|
ATRACE_CALL();
|
|
|
|
|
2013-04-11 05:55:41 +00:00
|
|
|
// get screen geometry
|
2015-06-09 23:44:40 +00:00
|
|
|
uint32_t hw_w = hw->getWidth();
|
|
|
|
uint32_t hw_h = hw->getHeight();
|
|
|
|
|
|
|
|
if (rotation & Transform::ROT_90) {
|
|
|
|
std::swap(hw_w, hw_h);
|
|
|
|
}
|
2013-04-11 05:55:41 +00:00
|
|
|
|
|
|
|
if ((reqWidth > hw_w) || (reqHeight > hw_h)) {
|
|
|
|
ALOGE("size mismatch (%d, %d) > (%d, %d)",
|
|
|
|
reqWidth, reqHeight, hw_w, hw_h);
|
|
|
|
return BAD_VALUE;
|
|
|
|
}
|
|
|
|
|
2014-12-06 02:28:32 +00:00
|
|
|
++mActiveFrameSequence;
|
|
|
|
|
2013-04-11 05:55:41 +00:00
|
|
|
reqWidth = (!reqWidth) ? hw_w : reqWidth;
|
|
|
|
reqHeight = (!reqHeight) ? hw_h : reqHeight;
|
|
|
|
|
2013-04-24 17:03:08 +00:00
|
|
|
// create a surface (because we're a producer, and we need to
|
|
|
|
// dequeue/queue a buffer)
|
2013-09-16 22:24:53 +00:00
|
|
|
sp<Surface> sur = new Surface(producer, false);
|
2013-04-24 17:03:08 +00:00
|
|
|
ANativeWindow* window = sur.get();
|
2010-09-29 20:02:36 +00:00
|
|
|
|
2015-05-21 20:48:24 +00:00
|
|
|
status_t result = native_window_api_connect(window, NATIVE_WINDOW_API_EGL);
|
|
|
|
if (result == NO_ERROR) {
|
2013-08-06 23:07:33 +00:00
|
|
|
uint32_t usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN |
|
|
|
|
GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE;
|
2013-03-01 21:42:57 +00:00
|
|
|
|
2013-04-24 17:03:08 +00:00
|
|
|
int err = 0;
|
|
|
|
err = native_window_set_buffers_dimensions(window, reqWidth, reqHeight);
|
2013-08-21 22:23:15 +00:00
|
|
|
err |= native_window_set_scaling_mode(window, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW);
|
2013-04-24 17:03:08 +00:00
|
|
|
err |= native_window_set_buffers_format(window, HAL_PIXEL_FORMAT_RGBA_8888);
|
|
|
|
err |= native_window_set_usage(window, usage);
|
2013-03-01 21:42:57 +00:00
|
|
|
|
2013-04-24 17:03:08 +00:00
|
|
|
if (err == NO_ERROR) {
|
|
|
|
ANativeWindowBuffer* buffer;
|
|
|
|
/* TODO: Once we have the sync framework everywhere this can use
|
|
|
|
* server-side waits on the fence that dequeueBuffer returns.
|
|
|
|
*/
|
|
|
|
result = native_window_dequeue_buffer_and_wait(window, &buffer);
|
|
|
|
if (result == NO_ERROR) {
|
2014-08-15 19:27:24 +00:00
|
|
|
int syncFd = -1;
|
2013-04-24 17:03:08 +00:00
|
|
|
// create an EGLImage from the buffer so we can later
|
|
|
|
// turn it into a texture
|
|
|
|
EGLImageKHR image = eglCreateImageKHR(mEGLDisplay, EGL_NO_CONTEXT,
|
|
|
|
EGL_NATIVE_BUFFER_ANDROID, buffer, NULL);
|
|
|
|
if (image != EGL_NO_IMAGE_KHR) {
|
2013-08-08 04:24:32 +00:00
|
|
|
// this binds the given EGLImage as a framebuffer for the
|
|
|
|
// duration of this scope.
|
2014-11-18 01:38:33 +00:00
|
|
|
RenderEngine::BindImageAsFramebuffer imageBond(getRenderEngine(), image,
|
|
|
|
useReadPixels, reqWidth, reqHeight);
|
2013-08-08 04:24:32 +00:00
|
|
|
if (imageBond.getStatus() == NO_ERROR) {
|
2013-04-24 17:03:08 +00:00
|
|
|
// this will in fact render into our dequeued buffer
|
|
|
|
// via an FBO, which means we didn't have to create
|
|
|
|
// an EGLSurface and therefore we're not
|
|
|
|
// dependent on the context's EGLConfig.
|
2014-09-04 23:20:31 +00:00
|
|
|
renderScreenImplLocked(
|
|
|
|
hw, sourceCrop, reqWidth, reqHeight, minLayerZ, maxLayerZ, true,
|
|
|
|
useIdentityTransform, rotation);
|
2013-09-20 00:08:37 +00:00
|
|
|
|
2014-08-15 19:27:24 +00:00
|
|
|
// Attempt to create a sync khr object that can produce a sync point. If that
|
|
|
|
// isn't available, create a non-dupable sync object in the fallback path and
|
|
|
|
// wait on it directly.
|
|
|
|
EGLSyncKHR sync;
|
|
|
|
if (!DEBUG_SCREENSHOTS) {
|
|
|
|
sync = eglCreateSyncKHR(mEGLDisplay, EGL_SYNC_NATIVE_FENCE_ANDROID, NULL);
|
2014-10-23 23:17:04 +00:00
|
|
|
// native fence fd will not be populated until flush() is done.
|
|
|
|
getRenderEngine().flush();
|
2014-08-15 19:27:24 +00:00
|
|
|
} else {
|
|
|
|
sync = EGL_NO_SYNC_KHR;
|
|
|
|
}
|
2013-10-09 23:38:02 +00:00
|
|
|
if (sync != EGL_NO_SYNC_KHR) {
|
2014-08-15 19:27:24 +00:00
|
|
|
// get the sync fd
|
|
|
|
syncFd = eglDupNativeFenceFDANDROID(mEGLDisplay, sync);
|
|
|
|
if (syncFd == EGL_NO_NATIVE_FENCE_FD_ANDROID) {
|
|
|
|
ALOGW("captureScreen: failed to dup sync khr object");
|
|
|
|
syncFd = -1;
|
|
|
|
}
|
2013-10-09 23:38:02 +00:00
|
|
|
eglDestroySyncKHR(mEGLDisplay, sync);
|
2014-08-15 19:27:24 +00:00
|
|
|
} else {
|
|
|
|
// fallback path
|
|
|
|
sync = eglCreateSyncKHR(mEGLDisplay, EGL_SYNC_FENCE_KHR, NULL);
|
|
|
|
if (sync != EGL_NO_SYNC_KHR) {
|
|
|
|
EGLint result = eglClientWaitSyncKHR(mEGLDisplay, sync,
|
|
|
|
EGL_SYNC_FLUSH_COMMANDS_BIT_KHR, 2000000000 /*2 sec*/);
|
|
|
|
EGLint eglErr = eglGetError();
|
|
|
|
if (result == EGL_TIMEOUT_EXPIRED_KHR) {
|
|
|
|
ALOGW("captureScreen: fence wait timed out");
|
|
|
|
} else {
|
|
|
|
ALOGW_IF(eglErr != EGL_SUCCESS,
|
|
|
|
"captureScreen: error waiting on EGL fence: %#x", eglErr);
|
|
|
|
}
|
|
|
|
eglDestroySyncKHR(mEGLDisplay, sync);
|
2013-10-09 23:38:02 +00:00
|
|
|
} else {
|
2014-08-15 19:27:24 +00:00
|
|
|
ALOGW("captureScreen: error creating EGL fence: %#x", eglGetError());
|
2013-10-09 23:38:02 +00:00
|
|
|
}
|
|
|
|
}
|
2014-11-18 01:38:33 +00:00
|
|
|
if (useReadPixels) {
|
|
|
|
sp<GraphicBuffer> buf = static_cast<GraphicBuffer*>(buffer);
|
|
|
|
void* vaddr;
|
|
|
|
if (buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, &vaddr) == NO_ERROR) {
|
|
|
|
getRenderEngine().readPixels(0, 0, buffer->stride, reqHeight,
|
|
|
|
(uint32_t *)vaddr);
|
|
|
|
buf->unlock();
|
|
|
|
}
|
|
|
|
}
|
2013-09-20 00:08:37 +00:00
|
|
|
if (DEBUG_SCREENSHOTS) {
|
|
|
|
uint32_t* pixels = new uint32_t[reqWidth*reqHeight];
|
|
|
|
getRenderEngine().readPixels(0, 0, reqWidth, reqHeight, pixels);
|
|
|
|
checkScreenshot(reqWidth, reqHeight, reqWidth, pixels,
|
|
|
|
hw, minLayerZ, maxLayerZ);
|
|
|
|
delete [] pixels;
|
|
|
|
}
|
|
|
|
|
2013-04-24 17:03:08 +00:00
|
|
|
} else {
|
|
|
|
ALOGE("got GL_FRAMEBUFFER_COMPLETE_OES error while taking screenshot");
|
|
|
|
result = INVALID_OPERATION;
|
|
|
|
}
|
|
|
|
// destroy our image
|
|
|
|
eglDestroyImageKHR(mEGLDisplay, image);
|
|
|
|
} else {
|
|
|
|
result = BAD_VALUE;
|
2010-09-29 20:02:36 +00:00
|
|
|
}
|
2014-10-21 18:09:17 +00:00
|
|
|
// queueBuffer takes ownership of syncFd
|
2015-05-21 20:48:24 +00:00
|
|
|
result = window->queueBuffer(window, buffer, syncFd);
|
2010-09-29 20:02:36 +00:00
|
|
|
}
|
2013-04-24 17:03:08 +00:00
|
|
|
} else {
|
|
|
|
result = BAD_VALUE;
|
2010-09-29 20:02:36 +00:00
|
|
|
}
|
2013-04-24 17:03:08 +00:00
|
|
|
native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL);
|
2010-09-29 20:02:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-09-20 00:08:37 +00:00
|
|
|
void SurfaceFlinger::checkScreenshot(size_t w, size_t s, size_t h, void const* vaddr,
|
|
|
|
const sp<const DisplayDevice>& hw, uint32_t minLayerZ, uint32_t maxLayerZ) {
|
2013-07-03 19:34:01 +00:00
|
|
|
if (DEBUG_SCREENSHOTS) {
|
2013-09-20 00:08:37 +00:00
|
|
|
for (size_t y=0 ; y<h ; y++) {
|
|
|
|
uint32_t const * p = (uint32_t const *)vaddr + y*s;
|
|
|
|
for (size_t x=0 ; x<w ; x++) {
|
2013-07-03 19:34:01 +00:00
|
|
|
if (p[x] != 0xFF000000) return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ALOGE("*** we just took a black screenshot ***\n"
|
|
|
|
"requested minz=%d, maxz=%d, layerStack=%d",
|
|
|
|
minLayerZ, maxLayerZ, hw->getLayerStack());
|
|
|
|
const LayerVector& layers( mDrawingState.layersSortedByZ );
|
|
|
|
const size_t count = layers.size();
|
|
|
|
for (size_t i=0 ; i<count ; ++i) {
|
|
|
|
const sp<Layer>& layer(layers[i]);
|
|
|
|
const Layer::State& state(layer->getDrawingState());
|
|
|
|
const bool visible = (state.layerStack == hw->getLayerStack())
|
|
|
|
&& (state.z >= minLayerZ && state.z <= maxLayerZ)
|
|
|
|
&& (layer->isVisible());
|
2014-03-07 20:44:02 +00:00
|
|
|
ALOGE("%c index=%zu, name=%s, layerStack=%d, z=%d, visible=%d, flags=%x, alpha=%x",
|
2013-07-03 19:34:01 +00:00
|
|
|
visible ? '+' : '-',
|
|
|
|
i, layer->getName().string(), state.layerStack, state.z,
|
|
|
|
layer->isVisible(), state.flags, state.alpha);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-23 19:55:15 +00:00
|
|
|
/* ------------------------------------------------------------------------
|
|
|
|
* Extensions
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool SurfaceFlinger::updateLayerVisibleNonTransparentRegion(const int& /*dpy*/,
|
|
|
|
const sp<Layer>& layer, bool& /*bIgnoreLayers*/, int& /*indexLOI*/,
|
|
|
|
uint32_t layerStack, const int& /*i*/) {
|
|
|
|
|
|
|
|
const Layer::State& s(layer->getDrawingState());
|
|
|
|
|
|
|
|
// only consider the layers on the given layer stack
|
2015-08-21 01:18:30 +00:00
|
|
|
if (s.layerStack != layerStack) {
|
|
|
|
/* set the visible region as empty since we have removed the
|
|
|
|
* layerstack check in rebuildLayerStack() function
|
|
|
|
*/
|
|
|
|
Region visibleNonTransRegion;
|
|
|
|
visibleNonTransRegion.set(Rect(0,0));
|
|
|
|
layer->setVisibleNonTransparentRegion(visibleNonTransRegion);
|
|
|
|
|
2015-06-23 19:55:15 +00:00
|
|
|
return true;
|
2015-08-21 01:18:30 +00:00
|
|
|
}
|
2015-06-23 19:55:15 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SurfaceFlinger::canDrawLayerinScreenShot(
|
|
|
|
const sp<const DisplayDevice>& /*hw*/,
|
|
|
|
const sp<Layer>& layer) {
|
|
|
|
return layer->isVisible();
|
|
|
|
}
|
|
|
|
|
2015-07-17 04:34:43 +00:00
|
|
|
void SurfaceFlinger::drawWormHoleIfRequired(HWComposer::LayerListIterator& /*cur*/,
|
|
|
|
const HWComposer::LayerListIterator& /*end*/,
|
|
|
|
const sp<const DisplayDevice>& hw,
|
|
|
|
const Region& region) {
|
|
|
|
drawWormhole(hw, region);
|
|
|
|
}
|
|
|
|
|
2010-09-24 18:26:58 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2012-07-24 06:11:29 +00:00
|
|
|
SurfaceFlinger::LayerVector::LayerVector() {
|
|
|
|
}
|
|
|
|
|
|
|
|
SurfaceFlinger::LayerVector::LayerVector(const LayerVector& rhs)
|
2013-03-06 01:47:11 +00:00
|
|
|
: SortedVector<sp<Layer> >(rhs) {
|
2012-07-24 06:11:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int SurfaceFlinger::LayerVector::do_compare(const void* lhs,
|
|
|
|
const void* rhs) const
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2012-08-01 05:59:38 +00:00
|
|
|
// sort layers per layer-stack, then by z-order and finally by sequence
|
2013-03-06 01:47:11 +00:00
|
|
|
const sp<Layer>& l(*reinterpret_cast<const sp<Layer>*>(lhs));
|
|
|
|
const sp<Layer>& r(*reinterpret_cast<const sp<Layer>*>(rhs));
|
2012-08-01 05:59:38 +00:00
|
|
|
|
2013-06-05 23:59:15 +00:00
|
|
|
uint32_t ls = l->getCurrentState().layerStack;
|
|
|
|
uint32_t rs = r->getCurrentState().layerStack;
|
2012-08-01 05:59:38 +00:00
|
|
|
if (ls != rs)
|
|
|
|
return ls - rs;
|
|
|
|
|
2013-06-05 23:59:15 +00:00
|
|
|
uint32_t lz = l->getCurrentState().z;
|
|
|
|
uint32_t rz = r->getCurrentState().z;
|
2012-08-01 05:59:38 +00:00
|
|
|
if (lz != rz)
|
|
|
|
return lz - rz;
|
|
|
|
|
|
|
|
return l->sequence - r->sequence;
|
2012-07-24 06:11:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2012-08-27 23:28:24 +00:00
|
|
|
SurfaceFlinger::DisplayDeviceState::DisplayDeviceState()
|
2014-07-18 22:34:25 +00:00
|
|
|
: type(DisplayDevice::DISPLAY_ID_INVALID), width(0), height(0) {
|
2012-08-09 23:29:12 +00:00
|
|
|
}
|
|
|
|
|
2012-08-27 23:28:24 +00:00
|
|
|
SurfaceFlinger::DisplayDeviceState::DisplayDeviceState(DisplayDevice::DisplayType type)
|
2014-07-18 22:34:25 +00:00
|
|
|
: type(type), layerStack(DisplayDevice::NO_LAYER_STACK), orientation(0), width(0), height(0) {
|
2012-09-04 22:05:38 +00:00
|
|
|
viewport.makeInvalid();
|
|
|
|
frame.makeInvalid();
|
2010-06-01 22:12:58 +00:00
|
|
|
}
|
2009-07-03 01:11:53 +00:00
|
|
|
|
2010-06-01 22:12:58 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2010-06-03 06:28:45 +00:00
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
}; // namespace android
|
2013-08-08 04:24:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
#if defined(__gl_h_)
|
|
|
|
#error "don't include gl/gl.h in this file"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__gl2_h_)
|
|
|
|
#error "don't include gl2/gl2.h in this file"
|
|
|
|
#endif
|