summaryrefslogtreecommitdiffstats
path: root/services/surfaceflinger
diff options
context:
space:
mode:
Diffstat (limited to 'services/surfaceflinger')
-rw-r--r--services/surfaceflinger/Android.mk9
-rw-r--r--services/surfaceflinger/DisplayHardware/HWComposer.cpp2
-rw-r--r--services/surfaceflinger/DisplayUtils.cpp8
-rw-r--r--services/surfaceflinger/ExSurfaceFlinger/ExHWComposer.cpp77
-rw-r--r--services/surfaceflinger/ExSurfaceFlinger/ExHWComposer.h57
-rw-r--r--services/surfaceflinger/ExSurfaceFlinger/ExLayer.cpp207
-rw-r--r--services/surfaceflinger/ExSurfaceFlinger/ExLayer.h68
-rw-r--r--services/surfaceflinger/ExSurfaceFlinger/ExSurfaceFlinger.cpp256
-rw-r--r--services/surfaceflinger/ExSurfaceFlinger/ExSurfaceFlinger.h86
-rw-r--r--services/surfaceflinger/ExSurfaceFlinger/ExVirtualDisplaySurface.cpp93
-rw-r--r--services/surfaceflinger/ExSurfaceFlinger/ExVirtualDisplaySurface.h55
11 files changed, 909 insertions, 9 deletions
diff --git a/services/surfaceflinger/Android.mk b/services/surfaceflinger/Android.mk
index c921329..c2b74ed 100644
--- a/services/surfaceflinger/Android.mk
+++ b/services/surfaceflinger/Android.mk
@@ -107,15 +107,16 @@ LOCAL_SHARED_LIBRARIES := \
libgui \
libpowermanager
-
ifeq ($(TARGET_USES_QCOM_BSP), true)
- LOCAL_WHOLE_STATIC_LIBRARIES += libexsurfaceflinger
- LOCAL_C_INCLUDES += vendor/qcom/opensource/display-frameworks/native/services/surfaceflinger
- LOCAL_C_INCLUDES += vendor/qcom/opensource/display-frameworks/include
LOCAL_C_INCLUDES += $(call project-path-for,qcom-display)/libgralloc
LOCAL_C_INCLUDES += $(call project-path-for,qcom-display)/libqdutils
LOCAL_SHARED_LIBRARIES += libqdutils
LOCAL_CFLAGS += -DQTI_BSP
+ LOCAL_SRC_FILES += \
+ ExSurfaceFlinger/ExLayer.cpp \
+ ExSurfaceFlinger/ExSurfaceFlinger.cpp \
+ ExSurfaceFlinger/ExVirtualDisplaySurface.cpp \
+ ExSurfaceFlinger/ExHWComposer.cpp
endif
ifeq ($(TARGET_HAVE_UI_BLUR),true)
diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.cpp b/services/surfaceflinger/DisplayHardware/HWComposer.cpp
index b60687f..a43597a 100644
--- a/services/surfaceflinger/DisplayHardware/HWComposer.cpp
+++ b/services/surfaceflinger/DisplayHardware/HWComposer.cpp
@@ -37,7 +37,7 @@
#include <hardware/hardware.h>
#include <hardware/hwcomposer.h>
#ifdef QTI_BSP
-#include <exhwcomposer_defs.h>
+#include <hardware/display_defs.h>
#endif
#include <android/configuration.h>
diff --git a/services/surfaceflinger/DisplayUtils.cpp b/services/surfaceflinger/DisplayUtils.cpp
index 0555232..96daeac 100644
--- a/services/surfaceflinger/DisplayUtils.cpp
+++ b/services/surfaceflinger/DisplayUtils.cpp
@@ -40,10 +40,10 @@
#include "DisplayHardware/FramebufferSurface.h"
#include "DisplayUtils.h"
#ifdef QTI_BSP
-#include <ExSurfaceFlinger.h>
-#include <ExLayer.h>
-#include <DisplayHardware/ExHWComposer.h>
-#include <DisplayHardware/ExVirtualDisplaySurface.h>
+#include <ExSurfaceFlinger/ExSurfaceFlinger.h>
+#include <ExSurfaceFlinger/ExLayer.h>
+#include <ExSurfaceFlinger/ExHWComposer.h>
+#include <ExSurfaceFlinger/ExVirtualDisplaySurface.h>
#include <gralloc_priv.h>
#endif
#include <dlfcn.h>
diff --git a/services/surfaceflinger/ExSurfaceFlinger/ExHWComposer.cpp b/services/surfaceflinger/ExSurfaceFlinger/ExHWComposer.cpp
new file mode 100644
index 0000000..2b41098
--- /dev/null
+++ b/services/surfaceflinger/ExSurfaceFlinger/ExHWComposer.cpp
@@ -0,0 +1,77 @@
+/* Copyright (c) 2015, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of The Linux Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "ExSurfaceFlinger.h"
+#include "ExLayer.h"
+#include "ExHWComposer.h"
+#ifdef QTI_BSP
+#include <hardware/display_defs.h>
+#endif
+
+namespace android {
+
+ExHWComposer::ExHWComposer(const sp<SurfaceFlinger>& flinger,
+ EventHandler& handler)
+ : HWComposer(flinger, handler) {
+
+ mVDSEnabled = false;
+ char property[PROPERTY_VALUE_MAX] = {0};
+
+ /* Read system property for VDS solution.
+ * This property is expected to be setup once during bootup
+ */
+ if( (property_get("persist.hwc.enable_vds", property, NULL) > 0) &&
+ ((!strncmp(property, "1", strlen("1"))) ||
+ !strncasecmp(property, "true", strlen("true")))) {
+ /* HAL virtual display is using VDS based implementation */
+ mVDSEnabled = true;
+ }
+
+ mDebugLogs = false;
+ if((property_get("persist.debug.qdframework.logs", property, NULL) > 0) &&
+ (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
+ (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
+ mDebugLogs = true;
+ }
+
+ ALOGD_IF(isDebug(),"Creating custom HWC %s",__FUNCTION__);
+}
+
+ExHWComposer::~ExHWComposer() {
+}
+
+bool ExHWComposer::isCompositionTypeBlit(const int32_t compType) const {
+#ifdef QTI_BSP
+ return (compType == HWC_BLIT);
+#else
+ ALOGD_IF(mDebugLogs, "%s: compType = %d", __FUNCTION__, compType);
+#endif
+ return false;
+}
+
+}; // namespace android
diff --git a/services/surfaceflinger/ExSurfaceFlinger/ExHWComposer.h b/services/surfaceflinger/ExSurfaceFlinger/ExHWComposer.h
new file mode 100644
index 0000000..2016ff0
--- /dev/null
+++ b/services/surfaceflinger/ExSurfaceFlinger/ExHWComposer.h
@@ -0,0 +1,57 @@
+/* Copyright (c) 2015, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of The Linux Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ANDROID_EX_HWCOMPOSER_H
+#define ANDROID_EX_HWCOMPOSER_H
+
+#include <DisplayHardware/HWComposer.h>
+
+namespace android {
+
+class ExHWComposer : public HWComposer
+{
+public:
+
+ ExHWComposer(
+ const sp<SurfaceFlinger>& flinger,
+ EventHandler& handler);
+
+ virtual ~ExHWComposer();
+
+protected:
+ bool mVDSEnabled;
+ inline bool isVDSEnabled() const { return mVDSEnabled; };
+ bool mDebugLogs;
+ bool isDebug() { return mDebugLogs; }
+ bool isCompositionTypeBlit(const int32_t compType) const;
+};
+
+
+}; //namespace android
+
+#endif //ANDROID_EX_HWCOMPOSER_H
diff --git a/services/surfaceflinger/ExSurfaceFlinger/ExLayer.cpp b/services/surfaceflinger/ExSurfaceFlinger/ExLayer.cpp
new file mode 100644
index 0000000..fa45579
--- /dev/null
+++ b/services/surfaceflinger/ExSurfaceFlinger/ExLayer.cpp
@@ -0,0 +1,207 @@
+/* Copyright (c) 2015, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of The Linux Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdlib.h>
+#include <stdint.h>
+#include <sys/types.h>
+
+#include <utils/Errors.h>
+#include <utils/Log.h>
+
+#include <ui/GraphicBuffer.h>
+#ifdef QTI_BSP
+#include <gralloc_priv.h>
+#include <hardware/display_defs.h>
+#endif
+
+#include "ExLayer.h"
+
+namespace android {
+
+/* Calculates the aspect ratio for external display based on the video w/h */
+static Rect getAspectRatio(const sp<const DisplayDevice>& hw,
+ const int& srcWidth, const int& srcHeight) {
+ Rect outRect;
+ int fbWidth = hw->getWidth();
+ int fbHeight = hw->getHeight();
+ int x , y = 0;
+ int w = fbWidth, h = fbHeight;
+ if (srcWidth * fbHeight > fbWidth * srcHeight) {
+ h = fbWidth * srcHeight / srcWidth;
+ w = fbWidth;
+ } else if (srcWidth * fbHeight < fbWidth * srcHeight) {
+ w = fbHeight * srcWidth / srcHeight;
+ h = fbHeight;
+ }
+ x = (fbWidth - w) / 2;
+ y = (fbHeight - h) / 2;
+ outRect.left = x;
+ outRect.top = y;
+ outRect.right = x + w;
+ outRect.bottom = y + h;
+
+ return outRect;
+}
+
+ExLayer::ExLayer(SurfaceFlinger* flinger, const sp<Client>& client,
+ const String8& name, uint32_t w, uint32_t h, uint32_t flags)
+ : Layer(flinger, client, name, w, h, flags) {
+
+ char property[PROPERTY_VALUE_MAX] = {0};
+
+ mDebugLogs = false;
+ mIsGPUAllowedForProtected = false;
+ if((property_get("persist.debug.qdframework.logs", property, NULL) > 0) &&
+ (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
+ (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
+ mDebugLogs = true;
+ }
+
+ ALOGD_IF(isDebug(),"Creating custom Layer %s",__FUNCTION__);
+
+ if ((property_get("persist.gralloc.cp.level3", property, NULL) > 0) &&
+ (atoi(property) == 1)) {
+ mIsGPUAllowedForProtected = true;
+ }
+}
+
+ExLayer::~ExLayer() {
+}
+
+bool ExLayer::isExtOnly() const {
+ const sp<GraphicBuffer>& activeBuffer(mActiveBuffer);
+ if (activeBuffer != 0) {
+#ifdef QTI_BSP
+ ANativeWindowBuffer* buffer = activeBuffer->getNativeBuffer();
+ if(buffer) {
+ private_handle_t* hnd = static_cast<private_handle_t*>
+ (const_cast<native_handle_t*>(buffer->handle));
+ /* return true if layer is EXT_ONLY */
+ return (hnd && (hnd->flags & private_handle_t::PRIV_FLAGS_EXTERNAL_ONLY));
+ }
+#endif
+ }
+ return false;
+}
+
+bool ExLayer::isIntOnly() const {
+ const sp<GraphicBuffer>& activeBuffer(mActiveBuffer);
+ if (activeBuffer != 0) {
+#ifdef QTI_BSP
+ ANativeWindowBuffer* buffer = activeBuffer->getNativeBuffer();
+ if(buffer) {
+ private_handle_t* hnd = static_cast<private_handle_t*>
+ (const_cast<native_handle_t*>(buffer->handle));
+ /* return true if layer is INT_ONLY */
+ return (hnd && (hnd->flags & private_handle_t::PRIV_FLAGS_INTERNAL_ONLY));
+ }
+#endif
+ }
+ return false;
+}
+
+bool ExLayer::isSecureDisplay() const {
+ const sp<GraphicBuffer>& activeBuffer(mActiveBuffer);
+ if (activeBuffer != 0) {
+#ifdef QTI_BSP
+ ANativeWindowBuffer* buffer = activeBuffer->getNativeBuffer();
+ if(buffer) {
+ private_handle_t* hnd = static_cast<private_handle_t*>
+ (const_cast<native_handle_t*>(buffer->handle));
+ /* return true if layer is SECURE_DISPLAY */
+ return (hnd && (hnd->flags & private_handle_t::PRIV_FLAGS_SECURE_DISPLAY));
+ }
+#endif
+ }
+ return false;
+}
+
+bool ExLayer::isYuvLayer() const {
+ const sp<GraphicBuffer>& activeBuffer(mActiveBuffer);
+ if(activeBuffer != 0) {
+#ifdef QTI_BSP
+ ANativeWindowBuffer* buffer = activeBuffer->getNativeBuffer();
+ if(buffer) {
+ private_handle_t* hnd = static_cast<private_handle_t*>
+ (const_cast<native_handle_t*>(buffer->handle));
+ /* return true if layer is YUV */
+ return (hnd && (hnd->bufferType == BUFFER_TYPE_VIDEO));
+ }
+#endif
+ }
+ return false;
+}
+
+void ExLayer::setPosition(const sp<const DisplayDevice>& hw,
+ HWComposer::HWCLayerInterface& layer, const State& state) {
+ /* Set dest_rect to display width and height, if external_only flag
+ * for the layer is enabled or if its yuvLayer in extended mode.
+ */
+ uint32_t w = hw->getWidth();
+ uint32_t h = hw->getHeight();
+ bool extendedMode = ExSurfaceFlinger::isExtendedMode();
+ if(isExtOnly()) {
+ /* Position: fullscreen for ext_only */
+ Rect r(0, 0, w, h);
+ layer.setFrame(r);
+ } else if(hw->getDisplayType() > 0 && (extendedMode && isYuvLayer())) {
+ /* Need to position the video full screen on external with aspect ratio */
+ Rect r = getAspectRatio(hw, state.active.w, state.active.h);
+ layer.setFrame(r);
+ }
+ return;
+}
+
+void ExLayer::setAcquiredFenceIfBlit(int &fenceFd,
+ HWComposer::HWCLayerInterface& layer) {
+#ifdef QTI_BSP
+ if (layer.getCompositionType() == HWC_BLIT) {
+ sp<Fence> fence = mSurfaceFlingerConsumer->getCurrentFence();
+ if (fence->isValid()) {
+ fenceFd = fence->dup();
+ if (fenceFd == -1) {
+ ALOGW("%s: failed to dup layer fence, skipping sync: %d",
+ __FUNCTION__,errno);
+ }
+ }
+ }
+#else
+ ALOGD_IF(isDebug(),"Not a BLIT Layer, compType = %d fencefd = %d",
+ layer.getCompositionType(), fenceFd);
+#endif
+}
+
+bool ExLayer::canAllowGPUForProtected() const {
+ if(isProtected()) {
+ return mIsGPUAllowedForProtected;
+ } else {
+ return false;
+ }
+}
+
+}; // namespace android
diff --git a/services/surfaceflinger/ExSurfaceFlinger/ExLayer.h b/services/surfaceflinger/ExSurfaceFlinger/ExLayer.h
new file mode 100644
index 0000000..01c74a8
--- /dev/null
+++ b/services/surfaceflinger/ExSurfaceFlinger/ExLayer.h
@@ -0,0 +1,68 @@
+/* Copyright (c) 2015, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of The Linux Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ANDROID_EX_LAYER_H
+#define ANDROID_EX_LAYER_H
+
+#include <stdint.h>
+#include <sys/types.h>
+#include <cutils/properties.h>
+
+#include <Layer.h>
+#include "ExSurfaceFlinger.h"
+
+namespace android {
+
+class ExSurfaceFlinger;
+
+class ExLayer : public Layer
+{
+public:
+ ExLayer(SurfaceFlinger* flinger, const sp<Client>& client,
+ const String8& name, uint32_t w, uint32_t h, uint32_t flags);
+ virtual ~ExLayer();
+
+ virtual bool isExtOnly() const;
+ virtual bool isIntOnly() const;
+ virtual bool isSecureDisplay() const;
+ virtual bool isYuvLayer() const;
+ virtual void setPosition(const sp<const DisplayDevice>& hw,
+ HWComposer::HWCLayerInterface& layer, const State& state);
+ virtual void setAcquiredFenceIfBlit(int &fenceFd,
+ HWComposer::HWCLayerInterface& layer);
+ virtual bool canAllowGPUForProtected() const;
+
+protected:
+ bool mDebugLogs;
+ bool isDebug() { return mDebugLogs; }
+ bool mIsGPUAllowedForProtected;
+};
+
+}; // namespace android
+
+#endif // ANDROID_EX_LAYER_H
diff --git a/services/surfaceflinger/ExSurfaceFlinger/ExSurfaceFlinger.cpp b/services/surfaceflinger/ExSurfaceFlinger/ExSurfaceFlinger.cpp
new file mode 100644
index 0000000..3579abb
--- /dev/null
+++ b/services/surfaceflinger/ExSurfaceFlinger/ExSurfaceFlinger.cpp
@@ -0,0 +1,256 @@
+/* Copyright (c) 2015, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of The Linux Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "ExSurfaceFlinger.h"
+#include "ExLayer.h"
+#include <cutils/properties.h>
+#ifdef QTI_BSP
+#include <hardware/display_defs.h>
+#endif
+#define ATRACE_TAG ATRACE_TAG_GRAPHICS
+
+namespace android {
+
+bool ExSurfaceFlinger::sExtendedMode = false;
+
+ExSurfaceFlinger::ExSurfaceFlinger() {
+ char property[PROPERTY_VALUE_MAX] = {0};
+
+ mDebugLogs = false;
+ if((property_get("persist.debug.qdframework.logs", property, NULL) > 0) &&
+ (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
+ (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
+ mDebugLogs = true;
+ }
+
+ ALOGD_IF(isDebug(),"Creating custom SurfaceFlinger %s",__FUNCTION__);
+
+ mDisableExtAnimation = false;
+ if((property_get("sys.disable_ext_animation", property, "0") > 0) &&
+ (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
+ (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
+ mDisableExtAnimation = true;
+ }
+
+ ALOGD_IF(isDebug(),"Animation on external is %s in %s",
+ mDisableExtAnimation ? "disabled" : "not disabled", __FUNCTION__);
+}
+
+ExSurfaceFlinger::~ExSurfaceFlinger() { }
+
+void ExSurfaceFlinger::updateExtendedMode() {
+ char prop[PROPERTY_VALUE_MAX];
+ property_get("sys.extended_mode", prop, "0");
+ sExtendedMode = atoi(prop) ? true : false;
+}
+
+void ExSurfaceFlinger::getIndexLOI(size_t dpy,
+ const LayerVector& currentLayers,
+ bool& bIgnoreLayers,
+ int& indexLOI ) {
+ size_t i = currentLayers.size();
+ while(i--) {
+ const sp<Layer>& layer = currentLayers[i];
+ /* iterate through the layer list to find ext_only layers and store
+ * the index
+ */
+ if (layer->isSecureDisplay()) {
+ bIgnoreLayers = true;
+ indexLOI = -1;
+ if(!dpy)
+ indexLOI = i;
+ break;
+ }
+ /* iterate through the layer list to find ext_only layers or yuv
+ * layer(extended_mode) and store the index
+ */
+ if ((dpy && (layer->isExtOnly() ||
+ (isExtendedMode() && layer->isYuvLayer())))) {
+ bIgnoreLayers= true;
+ indexLOI = i;
+ }
+ }
+ return;
+}
+
+bool ExSurfaceFlinger::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 add the layer marked as "external_only" or yuvLayer
+ * (extended_mode) to external list and
+ * only remove the layer marked as "external_only" or yuvLayer in
+ * extended_mode from primary list
+ * and do not add the layer marked as "internal_only" to external list
+ * Add secure UI layers to primary and remove other layers from internal
+ * and external list
+ */
+ if(((bIgnoreLayers && indexLOI != (int)i) ||
+ (!dpy && layer->isExtOnly()) ||
+ (!dpy && isExtendedMode() && layer->isYuvLayer()))||
+ (dpy && layer->isIntOnly())) {
+ /* Ignore all other layers except the layers marked as ext_only
+ * by setting visible non transparent region empty
+ */
+ Region visibleNonTransRegion;
+ visibleNonTransRegion.set(Rect(0,0));
+ layer->setVisibleNonTransparentRegion(visibleNonTransRegion);
+ return true;
+ }
+ /* only consider the layers on the given later stack
+ * Override layers created using presentation class by the layers having
+ * ext_only flag enabled
+ */
+ if(s.layerStack != layerStack && !bIgnoreLayers) {
+ /* 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);
+ return true;
+ }
+ return false;
+}
+
+void ExSurfaceFlinger::delayDPTransactionIfNeeded(
+ const Vector<DisplayState>& displays) {
+ /* Delay the display projection transaction by 50ms only when the disable
+ * external rotation animation feature is enabled
+ */
+ if(mDisableExtAnimation) {
+ size_t count = displays.size();
+ for (size_t i=0 ; i<count ; i++) {
+ const DisplayState& s(displays[i]);
+ if((mDisplays.indexOfKey(s.token) >= 0) && (s.token !=
+ mBuiltinDisplays[DisplayDevice::DISPLAY_PRIMARY])) {
+ const uint32_t what = s.what;
+ /* Invalidate and Delay the binder thread by 50 ms on
+ * eDisplayProjectionChanged to trigger a draw cycle so that
+ * it can fix one incorrect frame on the External, when we
+ * disable external animation
+ */
+ if (what & DisplayState::eDisplayProjectionChanged) {
+ invalidateHwcGeometry();
+ repaintEverything();
+ usleep(50000);
+ }
+ }
+ }
+ }
+}
+
+bool ExSurfaceFlinger::canDrawLayerinScreenShot(
+ const sp<const DisplayDevice>& hw,
+ const sp<Layer>& layer) {
+ int dispType = hw->getDisplayType();
+ /* a) Don't draw SecureDisplayLayer or ProtectedLayer.
+ * b) Don't let ext_only and extended_mode to be captured
+ * If not, we would see incorrect image during rotation
+ * on primary.
+ */
+ if(!layer->isSecureDisplay()
+ && !layer->isProtected()
+ && !(!dispType && (layer->isExtOnly() ||
+ (isExtendedMode() && layer->isYuvLayer())))
+ && layer->isVisible() ){
+ return true;
+ }
+ return false;
+}
+
+void ExSurfaceFlinger::isfreezeSurfacePresent(bool& freezeSurfacePresent,
+ const sp<const DisplayDevice>& hw,
+ const int32_t& id) {
+ freezeSurfacePresent = false;
+ /* Get the layers in the current drawing state */
+ const LayerVector& layers(mDrawingState.layersSortedByZ);
+ const size_t layerCount = layers.size();
+ /* Look for ScreenShotSurface in external layer list, only when
+ * disable external rotation animation feature is enabled
+ */
+ if(mDisableExtAnimation && (id != HWC_DISPLAY_PRIMARY)) {
+ for (size_t i = 0 ; i < layerCount ; ++i) {
+ static int screenShotLen = strlen("ScreenshotSurface");
+ const sp<Layer>& layer(layers[i]);
+ const Layer::State& s(layer->getDrawingState());
+ /* check the layers associated with external display */
+ if(s.layerStack == hw->getLayerStack()) {
+ if(!strncmp(layer->getName(), "ScreenshotSurface",
+ screenShotLen)) {
+ /* Screenshot layer is present, and animation in
+ * progress
+ */
+ freezeSurfacePresent = true;
+ break;
+ }
+ }
+ }
+ }
+}
+
+void ExSurfaceFlinger::setOrientationEventControl(bool& freezeSurfacePresent,
+ const int32_t& id) {
+ HWComposer& hwc(getHwComposer());
+ HWComposer::LayerListIterator cur = hwc.begin(id);
+
+ if(freezeSurfacePresent) {
+ /* If freezeSurfacePresent, set ANIMATING flag
+ * which is used to support disable animation on external
+ */
+ cur->setAnimating(true);
+ }
+}
+
+void ExSurfaceFlinger::updateVisibleRegionsDirty() {
+ /* If extended_mode is set, and set mVisibleRegionsDirty
+ * as we need to rebuildLayerStack
+ */
+ if(isExtendedMode()) {
+ mVisibleRegionsDirty = true;
+ }
+}
+
+void ExSurfaceFlinger::drawWormHoleIfRequired(HWComposer::LayerListIterator& cur,
+ const HWComposer::LayerListIterator& end,
+ const sp<const DisplayDevice>& hw,
+ const Region& region) {
+ if (cur != end) {
+#ifdef QTI_BSP
+ if (cur->getCompositionType() != HWC_BLIT)
+ drawWormhole(hw, region);
+#endif
+ } else {
+ drawWormhole(hw, region);
+ }
+}
+
+}; // namespace android
diff --git a/services/surfaceflinger/ExSurfaceFlinger/ExSurfaceFlinger.h b/services/surfaceflinger/ExSurfaceFlinger/ExSurfaceFlinger.h
new file mode 100644
index 0000000..628fac7
--- /dev/null
+++ b/services/surfaceflinger/ExSurfaceFlinger/ExSurfaceFlinger.h
@@ -0,0 +1,86 @@
+/* Copyright (c) 2015, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of The Linux Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ANDROID_EX_SURFACE_FLINGER_H
+#define ANDROID_EX_SURFACE_FLINGER_H
+
+#include "SurfaceFlinger.h"
+
+namespace android {
+
+class ExSurfaceFlinger : public SurfaceFlinger
+{
+public:
+
+ ExSurfaceFlinger();
+
+protected:
+ friend class ExLayer;
+
+ virtual void updateExtendedMode();
+ virtual void getIndexLOI(size_t dpy,
+ const LayerVector& currentLayers,
+ bool& bIgnoreLayers,
+ int& indexLOI);
+ virtual bool updateLayerVisibleNonTransparentRegion(
+ const int& dpy, const sp<Layer>& layer,
+ bool& bIgnoreLayers, int& indexLOI,
+ uint32_t layerStack, const int& i);
+ virtual void delayDPTransactionIfNeeded(
+ const Vector<DisplayState>& displays);
+ virtual bool canDrawLayerinScreenShot(
+ const sp<const DisplayDevice>& hw,
+ const sp<Layer>& layer);
+ virtual void isfreezeSurfacePresent(
+ bool& freezeSurfacePresent,
+ const sp<const DisplayDevice>& hw,
+ const int32_t& id);
+ virtual void setOrientationEventControl(
+ bool& freezeSurfacePresent,
+ const int32_t& id);
+ virtual void updateVisibleRegionsDirty();
+ virtual void drawWormHoleIfRequired(HWComposer::LayerListIterator& /*cur*/,
+ const HWComposer::LayerListIterator& /*end*/,
+ const sp<const DisplayDevice>& hw,
+ const Region& region);
+ virtual ~ExSurfaceFlinger();
+
+ /* Extended Mode
+ * No video on primary but video will be shown full
+ * screen on External
+ */
+ static bool sExtendedMode;
+ static bool isExtendedMode() { return sExtendedMode; }
+ bool mDebugLogs;
+ bool isDebug() { return mDebugLogs; }
+ bool mDisableExtAnimation;
+};
+
+}; //namespace android
+
+#endif //ANDROID_EX_SURFACE_FLINGER_H
diff --git a/services/surfaceflinger/ExSurfaceFlinger/ExVirtualDisplaySurface.cpp b/services/surfaceflinger/ExSurfaceFlinger/ExVirtualDisplaySurface.cpp
new file mode 100644
index 0000000..e4ad758
--- /dev/null
+++ b/services/surfaceflinger/ExSurfaceFlinger/ExVirtualDisplaySurface.cpp
@@ -0,0 +1,93 @@
+/* Copyright (c) 2015, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of The Linux Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "ExVirtualDisplaySurface.h"
+#ifdef QTI_BSP
+#include <gralloc_priv.h>
+#endif
+
+namespace android {
+
+#define VDS_LOGE(msg, ...) ALOGE("[%s] " msg, \
+ mDisplayName.string(), ##__VA_ARGS__)
+#define VDS_LOGW_IF(cond, msg, ...) ALOGW_IF(cond, "[%s] " msg, \
+ mDisplayName.string(), ##__VA_ARGS__)
+#define VDS_LOGV(msg, ...) ALOGV("[%s] " msg, \
+ mDisplayName.string(), ##__VA_ARGS__)
+
+ExVirtualDisplaySurface::ExVirtualDisplaySurface(HWComposer& hwc, int32_t dispId,
+ const sp<IGraphicBufferProducer>& sink,
+ const sp<IGraphicBufferProducer>& bqProducer,
+ const sp<IGraphicBufferConsumer>& bqConsumer,
+ const String8& name,
+ bool secure)
+: VirtualDisplaySurface(hwc, dispId, sink, bqProducer, bqConsumer, name),
+ mSecure(secure) {
+ sink->query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, &mSinkUsage);
+ mSinkUsage |= GRALLOC_USAGE_HW_COMPOSER;
+ setOutputUsage(mSinkUsage);
+}
+
+status_t ExVirtualDisplaySurface::beginFrame(bool mustRecompose) {
+ if (mDisplayId < 0)
+ return NO_ERROR;
+
+ mMustRecompose = mustRecompose;
+ /* For WFD use cases we must always set the recompose flag in order
+ * to support pause/resume functionality
+ */
+ if (mOutputUsage & GRALLOC_USAGE_HW_VIDEO_ENCODER) {
+ mMustRecompose = true;
+ }
+
+ VDS_LOGW_IF(mDbgState != DBG_STATE_IDLE,
+ "Unexpected beginFrame() in %s state", dbgStateStr());
+ mDbgState = DBG_STATE_BEGUN;
+
+ return refreshOutputBuffer();
+
+}
+
+/* Helper to update the output usage when the display is secure */
+void ExVirtualDisplaySurface::setOutputUsage(uint32_t /*flag*/) {
+ mOutputUsage = mSinkUsage;
+ if (mSecure && (mOutputUsage & GRALLOC_USAGE_HW_VIDEO_ENCODER)) {
+ /* TODO: Currently, the framework can only say whether the display
+ * and its subsequent session are secure or not. However, there is
+ * no mechanism to distinguish the different levels of security.
+ * The current solution assumes WV L3 protection.
+ */
+ mOutputUsage |= GRALLOC_USAGE_PROTECTED;
+#ifdef QTI_BSP
+ mOutputUsage |= GRALLOC_USAGE_PRIVATE_MM_HEAP |
+ GRALLOC_USAGE_PRIVATE_UNCACHED;
+#endif
+ }
+}
+
+}; // namespace android
diff --git a/services/surfaceflinger/ExSurfaceFlinger/ExVirtualDisplaySurface.h b/services/surfaceflinger/ExSurfaceFlinger/ExVirtualDisplaySurface.h
new file mode 100644
index 0000000..ab71594
--- /dev/null
+++ b/services/surfaceflinger/ExSurfaceFlinger/ExVirtualDisplaySurface.h
@@ -0,0 +1,55 @@
+/* Copyright (c) 2015, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of The Linux Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ANDROID_EX_VIRTUAL_DISPLAY_SURFACE_H
+#define ANDROID_EX_VIRTUAL_DISPLAY_SURFACE_H
+
+#include <DisplayHardware/VirtualDisplaySurface.h>
+
+namespace android {
+
+class ExVirtualDisplaySurface : public VirtualDisplaySurface {
+public:
+ ExVirtualDisplaySurface(HWComposer& hwc, int32_t dispId,
+ const sp<IGraphicBufferProducer>& sink,
+ const sp<IGraphicBufferProducer>& bqProducer,
+ const sp<IGraphicBufferConsumer>& bqConsumer,
+ const String8& name,
+ bool secure);
+
+private:
+ virtual status_t beginFrame(bool mustRecompose);
+ virtual void setOutputUsage(uint32_t flag);
+ bool mSecure;
+ int mSinkUsage;
+};
+
+}; // namespace android
+
+#endif // ANDROID_EX_VIRTUAL_DISPLAY_SURFACE_H
+