summaryrefslogtreecommitdiff
authorStark Li <stark.li@amlogic.com>2017-02-16 11:41:42 (GMT)
committer Stark Li <stark.li@amlogic.com>2017-02-24 11:28:31 (GMT)
commitf71f6c3b23ca91745aef93a0bb242362f070a298 (patch)
tree522d3d2981a3c85e29c5ab53414f019d44e00855
parent945ecb09f7f14ffc9c88c86a397cad38c74f1429 (diff)
downloadhwcomposer-f71f6c3b23ca91745aef93a0bb242362f070a298.zip
hwcomposer-f71f6c3b23ca91745aef93a0bb242362f070a298.tar.gz
hwcomposer-f71f6c3b23ca91745aef93a0bb242362f070a298.tar.bz2
PD#138788: add secure layer support
Change-Id: I729aeb01836ae60f0a410a445ab8bd8c762d31af
Diffstat
-rw-r--r--hwc2/common/devices/PhysicalDevice.cpp118
-rw-r--r--hwc2/common/devices/PrimaryDevice.cpp36
-rw-r--r--hwc2/common/observers/UeventObserver.cpp38
-rw-r--r--hwc2/common/utils/Utils.cpp11
-rw-r--r--hwc2/common/utils/Utils.h9
-rw-r--r--hwc2/include/IDisplayDevice.h1
-rw-r--r--hwc2/include/PhysicalDevice.h18
-rw-r--r--hwc2/include/PrimaryDevice.h3
-rw-r--r--hwc2/include/UeventObserver.h4
-rw-r--r--hwc2/platforms/Android.mk11
10 files changed, 195 insertions, 54 deletions
diff --git a/hwc2/common/devices/PhysicalDevice.cpp b/hwc2/common/devices/PhysicalDevice.cpp
index 67ba255..8ce0491 100644
--- a/hwc2/common/devices/PhysicalDevice.cpp
+++ b/hwc2/common/devices/PhysicalDevice.cpp
@@ -39,7 +39,9 @@ PhysicalDevice::PhysicalDevice(hwc2_display_t id, Hwcomposer& hwc, DeviceControl
mControlFactory(controlFactory),
mVsyncObserver(NULL),
mIsConnected(false),
+ mSecure(false),
mFramebufferHnd(NULL),
+ mSystemControl(NULL),
mFbSlot(0),
mComposer(NULL),
mPriorFrameRetireFence(-1),
@@ -74,7 +76,18 @@ PhysicalDevice::PhysicalDevice(hwc2_display_t id, Hwcomposer& hwc, DeviceControl
// set capacity of layers, layer's changed type, layer's changed request.
mHwcLayersChangeType.setCapacity(LAYER_MAX_NUM_CHANGE_TYPE);
mHwcLayersChangeRequest.setCapacity(LAYER_MAX_NUM_CHANGE_REQUEST);
+ mHwcGlesLayers.setCapacity(LAYER_MAX_NUM_CHANGE_TYPE);
mHwcLayers.setCapacity(LAYER_MAX_NUM_SUPPORT);
+#ifdef HWC_ENABLE_SECURE_LAYER
+ mHwcSecureLayers.setCapacity(LAYER_MAX_NUM_SECURE_PROTECTED);
+ mHwcSecureLayers.clear();
+#endif
+
+ // clear layers vectors.
+ mHwcLayersChangeType.clear();
+ mHwcLayersChangeRequest.clear();
+ mHwcGlesLayers.clear();
+ mHwcLayers.clear();
mGE2DRenderSortedLayerIds.setCapacity(GE2D_COMPOSE_MAX_LAYERS);
mGE2DRenderSortedLayerIds.clear();
@@ -105,11 +118,34 @@ bool PhysicalDevice::initialize() {
mDisplayHdmi = new DisplayHdmi(mId);
mDisplayHdmi->initialize();
+ UeventObserver *observer = Hwcomposer::getInstance().getUeventObserver();
+ if (observer) {
+ observer->registerListener(
+ Utils::getHdcpUeventEnvelope(),
+ hdcpEventListener,
+ this);
+ } else {
+ ETRACE("PhysicalDevice::Uevent observer is NULL");
+ }
mInitialized = true;
return true;
}
+void PhysicalDevice::hdcpEventListener(void *data, bool status)
+{
+ PhysicalDevice *pThis = (PhysicalDevice*)data;
+ if (pThis) {
+ pThis->setSecureStatus(status);
+ }
+}
+
+void PhysicalDevice::setSecureStatus(bool status)
+{
+ DTRACE("hdcp event: %d", status);
+ mSecure = status;
+}
+
void PhysicalDevice::deinitialize() {
Mutex::Autolock _l(mLock);
@@ -151,6 +187,23 @@ int32_t PhysicalDevice::acceptDisplayChanges() {
hwc2_layer_t layerId = mHwcLayersChangeType.keyAt(i);
layer = mHwcLayersChangeType.valueAt(i);
if (layer) {
+#ifdef HWC_ENABLE_SECURE_LAYER
+ // deal non secure display.
+ if (!mSecure && !mHwcSecureLayers.isEmpty()) {
+ for (uint32_t j=0; j<mHwcSecureLayers.size(); j++) {
+ hwc2_layer_t secureLayerId = mHwcSecureLayers.keyAt(j);
+ HwcLayer* secureLayer = mHwcSecureLayers.valueAt(j);
+ // deal secure layers release fence and composition type on non secure display.
+ addReleaseFence(secureLayerId, secureLayer->getDuppedAcquireFence());
+ if (layerId == secureLayerId) {
+ if (layer->getCompositionType() != HWC2_COMPOSITION_DEVICE) {
+ layer->setCompositionType(HWC2_COMPOSITION_DEVICE);
+ continue;
+ }
+ }
+ }
+ }
+#endif
if (layer->getCompositionType() == HWC2_COMPOSITION_DEVICE
|| layer->getCompositionType() == HWC2_COMPOSITION_SOLID_COLOR) {
layer->setCompositionType(HWC2_COMPOSITION_CLIENT);
@@ -163,6 +216,13 @@ int32_t PhysicalDevice::acceptDisplayChanges() {
mHwcLayersChangeType.clear();
mHwcLayersChangeRequest.clear();
+#ifdef HWC_ENABLE_SECURE_LAYER
+ // deal non secure display device.
+ if (!mHwcSecureLayers.isEmpty()) {
+ mHwcSecureLayers.clear();
+ }
+#endif
+
return HWC2_ERROR_NONE;
}
@@ -225,6 +285,22 @@ int32_t PhysicalDevice::getChangedCompositionTypes(
hwc2_layer_t layerId = mHwcLayersChangeType.keyAt(i);
layer = mHwcLayersChangeType.valueAt(i);
if (layer) {
+#ifdef HWC_ENABLE_SECURE_LAYER
+ // deal non secure display.
+ if (!mSecure && !mHwcSecureLayers.isEmpty()) {
+ for (uint32_t j=0; j<mHwcSecureLayers.size(); j++) {
+ hwc2_layer_t secureLayerId = mHwcSecureLayers.keyAt(j);
+ if (layerId == secureLayerId) {
+ if (layer->getCompositionType() != HWC2_COMPOSITION_DEVICE) {
+ outLayers[i] = layerId;
+ outTypes[i] = HWC2_COMPOSITION_DEVICE;
+ continue;
+ }
+ }
+ }
+ }
+#endif
+
if (layer->getCompositionType() == HWC2_COMPOSITION_DEVICE
|| layer->getCompositionType() == HWC2_COMPOSITION_SOLID_COLOR) {
// change all other device type to client.
@@ -1027,10 +1103,23 @@ int32_t PhysicalDevice::validateDisplay(uint32_t* outNumTypes,
private_handle_t const* hnd =
reinterpret_cast<private_handle_t const*>(layer->getBufferHandle());
if (hnd) {
+ // continous buffer.
if (!(hnd->flags & private_handle_t::PRIV_FLAGS_CONTINUOUS_BUF)) {
DTRACE("continous buffer flag is not set!");
mIsContinuousBuf = false;
}
+
+#ifdef GRALLOC_ENABLE_SECURE_LAYER
+ // secure or protected layer.
+ if (!mSecure && (hnd->flags & private_handle_t::PRIV_FLAGS_SECURE_PROTECTED)) {
+ ETRACE("layer's secure or protected buffer flag is set!");
+ if (layer->getCompositionType() != HWC2_COMPOSITION_DEVICE) {
+ mHwcLayersChangeType.add(layerId, layer);
+ }
+ mHwcSecureLayers.add(layerId, layer);
+ continue;
+ }
+#endif
if (hnd && layer->getCompositionType() == HWC2_COMPOSITION_DEVICE) {
// video overlay.
if (hnd->flags & private_handle_t::PRIV_FLAGS_VIDEO_OMX) {
@@ -1246,9 +1335,38 @@ bool PhysicalDevice::updateDisplayConfigs() {
mVsyncObserver->setRefreshRate(mDisplayHdmi->getActiveRefreshRate());
//ETRACE("updateDisplayConfigs rate:%d", mDisplayHdmi->getActiveRefreshRate());
+ // check hdcp authentication status when hotplug is happen.
+ if (mSystemControl == NULL) {
+ mSystemControl = getSystemControlService();
+ } else {
+ DTRACE("already have system control instance.");
+ }
+ if (mSystemControl != NULL) {
+ // mSecure = Utils::checkHdcp();
+ int status = 0;
+ mSystemControl->isHDCPTxAuthSuccess(status);
+ DTRACE("hdcp status: %d", status);
+ mSecure = (status == 1) ? true : false;
+ } else {
+ ETRACE("can't get system control.");
+ }
+
return true;
}
+sp<ISystemControlService> PhysicalDevice::getSystemControlService()
+{
+ sp<IServiceManager> sm = defaultServiceManager();
+ if (sm == NULL) {
+ ETRACE("Couldn't get default ServiceManager\n");
+ return NULL;
+ }
+ sp<IBinder> binder = sm->getService(String16("system_control"));
+ sp<ISystemControlService> sc = interface_cast<ISystemControlService>(binder);
+
+ return sc;
+}
+
void PhysicalDevice::onVsync(int64_t timestamp) {
RETURN_VOID_IF_NOT_INIT();
ATRACE("timestamp = %lld", timestamp);
diff --git a/hwc2/common/devices/PrimaryDevice.cpp b/hwc2/common/devices/PrimaryDevice.cpp
index 550876c..eca8957 100644
--- a/hwc2/common/devices/PrimaryDevice.cpp
+++ b/hwc2/common/devices/PrimaryDevice.cpp
@@ -44,13 +44,8 @@ bool PrimaryDevice::initialize()
UeventObserver *observer = Hwcomposer::getInstance().getUeventObserver();
if (observer) {
observer->registerListener(
- Utils::getHotplugInString(),
- hotplugInEventListener,
- this);
-
- observer->registerListener(
- Utils::getHotplugOutString(),
- hotplugOutEventListener,
+ Utils::getHotplugUeventEnvelope(),
+ hotplugEventListener,
this);
} else {
ETRACE("Uevent observer is NULL");
@@ -64,19 +59,11 @@ void PrimaryDevice::deinitialize()
PhysicalDevice::deinitialize();
}
-void PrimaryDevice::hotplugInEventListener(void *data)
-{
- PrimaryDevice *pThis = (PrimaryDevice*)data;
- if (pThis) {
- pThis->hotplugListener(true);
- }
-}
-
-void PrimaryDevice::hotplugOutEventListener(void *data)
+void PrimaryDevice::hotplugEventListener(void *data, bool status)
{
PrimaryDevice *pThis = (PrimaryDevice*)data;
if (pThis) {
- pThis->hotplugListener(false);
+ pThis->hotplugListener(status);
}
}
@@ -88,13 +75,16 @@ void PrimaryDevice::hotplugListener(bool connected)
updateHotplugState(connected);
// update display configs
- if (connected && !updateDisplayConfigs()) {
- ETRACE("failed to update display config");
- return;
+ if (connected) {
+ if (!updateDisplayConfigs()) {
+ ETRACE("failed to update display config");
+ return;
+ }
+
+ if (getDisplayId() == HWC_DISPLAY_EXTERNAL) {
+ getDevice().hotplug(getDisplayId(), connected);
+ }
}
-
- if (connected)
- getDevice().hotplug(getDisplayId(), connected);
}
} // namespace amlogic
diff --git a/hwc2/common/observers/UeventObserver.cpp b/hwc2/common/observers/UeventObserver.cpp
index e9d944f..7590bcd 100644
--- a/hwc2/common/observers/UeventObserver.cpp
+++ b/hwc2/common/observers/UeventObserver.cpp
@@ -127,17 +127,16 @@ void UeventObserver::start()
}
}
-
-void UeventObserver::registerListener(const char *event, UeventListenerFunc func, void *data)
+void UeventObserver::registerListener(const char *envelope, UeventListenerFunc func, void *data)
{
- if (!event || !func) {
+ if (!envelope || !func) {
ETRACE("invalid event string or listener to register");
return;
}
- String8 key(event);
+ String8 key(envelope);
if (mListeners.indexOfKey(key) >= 0) {
- ETRACE("listener for uevent %s exists", event);
+ ETRACE("listener for uevent %s exists", envelope);
return;
}
@@ -188,26 +187,31 @@ bool UeventObserver::threadLoop()
void UeventObserver::onUevent()
{
char *msg = mUeventMessage;
- const char *envelope = Utils::getUeventEnvelope();
+ UeventListener *listener = NULL;
+
DTRACE("onUevent: %s", mUeventMessage);
- if (strncmp(msg, envelope, strlen(envelope)) != 0)
- return;
+ for (uint32_t i=0; i<mListeners.size(); i++) {
+ const char *envelope = mListeners.keyAt(i).string();
+ if (strncmp(msg, envelope, strlen(envelope)) == 0) {
+ listener = mListeners.valueAt(i);
+ break;
+ } else {
+ continue;
+ }
+ }
+
+ if (!listener) return;
msg += strlen(msg) + 1;
- UeventListener *listener;
String8 key;
while (*msg) {
key = String8(msg);
DTRACE("received Uevent: %s", msg);
- if (mListeners.indexOfKey(key) >= 0) {
- DTRACE("received Uevent: %s", msg);
- listener = mListeners.valueFor(key);
- if (listener) {
- listener->func(listener->data);
- } else {
- ETRACE("no listener for uevent %s", msg);
- }
+ if (key.contains(Utils::getSwitchState1())) {
+ listener->func(listener->data, true);
+ } else if (key.contains(Utils::getSwitchState0())) {
+ listener->func(listener->data, false);
}
msg += strlen(msg) + 1;
}
diff --git a/hwc2/common/utils/Utils.cpp b/hwc2/common/utils/Utils.cpp
index fa6cb84..89bad2a 100644
--- a/hwc2/common/utils/Utils.cpp
+++ b/hwc2/common/utils/Utils.cpp
@@ -210,17 +210,22 @@ bool Utils::checkVinfo(framebuffer_info_t *fbInfo) {
return false;
}
-const char* Utils::getUeventEnvelope()
+const char* Utils::getHotplugUeventEnvelope()
{
return "change@/devices/virtual/switch/hdmi_audio";
}
-const char* Utils::getHotplugOutString()
+const char* Utils::getHdcpUeventEnvelope()
+{
+ return "change@/devices/virtual/switch/hdcp";
+}
+
+const char* Utils::getSwitchState0()
{
return "SWITCH_STATE=0";
}
-const char* Utils::getHotplugInString()
+const char* Utils::getSwitchState1()
{
return "SWITCH_STATE=1";
}
diff --git a/hwc2/common/utils/Utils.h b/hwc2/common/utils/Utils.h
index 956e331..53a55d0 100644
--- a/hwc2/common/utils/Utils.h
+++ b/hwc2/common/utils/Utils.h
@@ -47,12 +47,13 @@ public:
#if WITH_LIBPLAYER_MODULE
static bool checkSysfsStatus(const char* sysfstr, char* lastr, int32_t size);
#endif
-
+ static bool checkOutputMode(char* curmode, int32_t* rate);
static bool checkVinfo(framebuffer_info_t *fbinfo);
- static const char* getUeventEnvelope();
- static const char* getHotplugInString();
- static const char* getHotplugOutString();
+ static const char* getHotplugUeventEnvelope();
+ static const char* getHdcpUeventEnvelope();
+ static const char* getSwitchState0();
+ static const char* getSwitchState1();
template <typename T, typename S>
static inline bool compareRect(T a, S b) {
diff --git a/hwc2/include/IDisplayDevice.h b/hwc2/include/IDisplayDevice.h
index ada3534..5de0000 100644
--- a/hwc2/include/IDisplayDevice.h
+++ b/hwc2/include/IDisplayDevice.h
@@ -29,6 +29,7 @@ namespace android {
namespace amlogic {
enum {
+ LAYER_MAX_NUM_SECURE_PROTECTED = 5,
LAYER_MAX_NUM_CHANGE_REQUEST = 8,
LAYER_MAX_NUM_CHANGE_TYPE = 16,
LAYER_MAX_NUM_SUPPORT = LAYER_MAX_NUM_CHANGE_TYPE,
diff --git a/hwc2/include/PhysicalDevice.h b/hwc2/include/PhysicalDevice.h
index a27f0a7..9657c0a 100644
--- a/hwc2/include/PhysicalDevice.h
+++ b/hwc2/include/PhysicalDevice.h
@@ -26,6 +26,12 @@
#include <IComposer.h>
#include <DisplayHdmi.h>
+#include <systemcontrol/ISystemControlService.h>
+#include <systemcontrol/DisplayMode.h>
+#include <binder/Binder.h>
+#include <binder/IServiceManager.h>
+#include <utils/RefBase.h>
+
namespace android {
namespace amlogic {
@@ -76,6 +82,8 @@ public:
friend class Hwcomposer;
friend class HwcLayer;
+ // typedef sp<ISystemControlService> IScs;
+
// Required by HWC2
virtual int32_t acceptDisplayChanges();
virtual bool createLayer(hwc2_layer_t* outLayer);
@@ -163,6 +171,10 @@ private:
void dumpLayers(KeyedVector<hwc2_layer_t, HwcLayer*> layers);
void clearFramebuffer();
+ sp<ISystemControlService> getSystemControlService();
+ static void hdcpEventListener(void *data, bool status);
+ void setSecureStatus(bool status);
+
template <typename T, typename S>
static inline bool compareSize(T a, S b) {
if ((int32_t)(a.right - a.left) == (int32_t)(b.right - b.left)
@@ -176,6 +188,7 @@ private:
hwc2_display_t mId;
const char *mName;
bool mIsConnected;
+ bool mSecure;
Hwcomposer& mHwc;
DisplayHdmi* mDisplayHdmi;
DeviceControlFactory *mControlFactory;
@@ -191,6 +204,8 @@ private:
FBContext *mFramebufferContext;
int32_t mFbSlot;
+ sp<ISystemControlService> mSystemControl;
+
int32_t /*android_color_mode_t*/ mColorMode;
int32_t /*hwc2_power_mode_t*/ mPowerMode;
@@ -218,6 +233,9 @@ private:
KeyedVector<hwc2_layer_t, HwcLayer*> mHwcLayersChangeRequest;
KeyedVector<hwc2_layer_t, HwcLayer*> mHwcGlesLayers;
KeyedVector<hwc2_layer_t, HwcLayer*> mHwcLayers;
+#ifdef HWC_ENABLE_SECURE_LAYER
+ KeyedVector<hwc2_layer_t, HwcLayer*> mHwcSecureLayers;
+#endif
// HDR Capabilities
hdr_capabilities_t mHdrCapabilities;
diff --git a/hwc2/include/PrimaryDevice.h b/hwc2/include/PrimaryDevice.h
index 2b4d84c..979a5f7 100644
--- a/hwc2/include/PrimaryDevice.h
+++ b/hwc2/include/PrimaryDevice.h
@@ -39,8 +39,7 @@ public:
virtual int32_t setOutputBuffer(buffer_handle_t buffer, int32_t releaseFence) { return HWC2_ERROR_NONE; }
private:
- static void hotplugInEventListener(void *data);
- static void hotplugOutEventListener(void *data);
+ static void hotplugEventListener(void *data, bool status);
void hotplugListener(bool connected);
};
diff --git a/hwc2/include/UeventObserver.h b/hwc2/include/UeventObserver.h
index 5e40046..0dc5b36 100644
--- a/hwc2/include/UeventObserver.h
+++ b/hwc2/include/UeventObserver.h
@@ -26,7 +26,7 @@
namespace android {
namespace amlogic {
-typedef void (*UeventListenerFunc)(void *data);
+typedef void (*UeventListenerFunc)(void *data, bool status);
class UeventObserver
{
@@ -38,7 +38,7 @@ public:
bool initialize();
void deinitialize();
void start();
- void registerListener(const char *event, UeventListenerFunc func, void *data);
+ void registerListener(const char *key, UeventListenerFunc func, void *data);
private:
DECLARE_THREAD(UeventObserverThread, UeventObserver);
diff --git a/hwc2/platforms/Android.mk b/hwc2/platforms/Android.mk
index e1a62de..23eb276 100644
--- a/hwc2/platforms/Android.mk
+++ b/hwc2/platforms/Android.mk
@@ -42,8 +42,8 @@ LOCAL_SHARED_LIBRARIES := \
libfbcnf \
libge2d \
libbinder \
- libsystemcontrolservice\
- libgui\
+ libsystemcontrolservice \
+ libgui
LOCAL_STATIC_LIBRARIES := \
libomxutil
@@ -53,7 +53,8 @@ LOCAL_C_INCLUDES := \
system/core/libsync \
system/core/libsync/include \
system/core/include \
- vendor/amlogic/system/libge2d/inlcude
+ vendor/amlogic/system/libge2d/inlcude \
+ vendor/amlogic/frameworks/services
LOCAL_C_INCLUDES += $(LOCAL_PATH) \
$(LOCAL_PATH)/../include \
@@ -93,6 +94,10 @@ ifeq ($(TARGET_APP_LAYER_USE_CONTINUOUS_BUFFER),true)
LOCAL_CFLAGS += -DUSE_CONTINOUS_BUFFER_COMPOSER
endif
+ifeq ($(TARGET_SUPPORT_SECURE_LAYER),true)
+LOCAL_CFLAGS += -DHWC_ENABLE_SECURE_LAYER
+endif
+
# WITH_LIBPLAYER_MODULE := true
ifneq ($(WITH_LIBPLAYER_MODULE),false)
LOCAL_SHARED_LIBRARIES += libamavutils_alsa