You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
172 lines
5.3 KiB
172 lines
5.3 KiB
4 months ago
|
#include "SurfaceUI.h"
|
||
|
#include <cutils/properties.h>
|
||
|
#include <android-base/properties.h>
|
||
|
|
||
|
#if PLATFORM_SDK_VERSION <= __ANDROID_API_Q__
|
||
|
#include <ui/DisplayInfo.h>
|
||
|
#include <gui/SurfaceComposerClient.h>
|
||
|
#include <gui/SurfaceControl.h>
|
||
|
#include <gui/Surface.h>
|
||
|
#else
|
||
|
#include <input/DisplayViewport.h>
|
||
|
#include <ui/DisplayMode.h>
|
||
|
#include <ui/PixelFormat.h>
|
||
|
#include <ui/Rect.h>
|
||
|
#include <ui/Region.h>
|
||
|
#include <gui/ISurfaceComposer.h>
|
||
|
#include <gui/DisplayEventReceiver.h>
|
||
|
#include <gui/Surface.h>
|
||
|
#include <gui/SurfaceComposerClient.h>
|
||
|
#endif
|
||
|
|
||
|
namespace android {
|
||
|
SurfaceUI::SurfaceUI()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
SurfaceUI::~SurfaceUI()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
int SurfaceUI::GetDisplayOrientation() const
|
||
|
{
|
||
|
std::string orientation;
|
||
|
orientation = android::base::GetProperty("persist.prop.screenorientation", "landscape");
|
||
|
if (orientation == "landscape") {
|
||
|
return DISPLAY_ORIENTATION_0;
|
||
|
} else if (orientation == "portrait") {
|
||
|
return DISPLAY_ORIENTATION_90;
|
||
|
} else if (orientation == "seascape") {
|
||
|
return DISPLAY_ORIENTATION_180;
|
||
|
} else if (orientation == "upsideDown") {
|
||
|
return DISPLAY_ORIENTATION_270;
|
||
|
} else {
|
||
|
ALOGE("GetDisplayOrientation: value is %s", orientation.c_str());
|
||
|
return -1;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#if PLATFORM_SDK_VERSION <= __ANDROID_API_Q__
|
||
|
SurfaceQverUI::SurfaceQverUI()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
SurfaceQverUI::~SurfaceQverUI()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
bool SurfaceQverUI::CreateSurface()
|
||
|
{
|
||
|
SurfaceComposerClient::Transaction t;
|
||
|
sp<SurfaceComposerClient> session = new SurfaceComposerClient();
|
||
|
sp<IBinder> token = SurfaceComposerClient::getInternalDisplayToken();
|
||
|
if (token == nullptr) {
|
||
|
ALOGE("CreateSurface: token is NULL");
|
||
|
return false;
|
||
|
}
|
||
|
DisplayInfo dinfo;
|
||
|
if (SurfaceComposerClient::getDisplayInfo(token, &dinfo)) {
|
||
|
ALOGE("CreateSurface: get display info is failure");
|
||
|
return false;
|
||
|
}
|
||
|
// set display size
|
||
|
surfaceW = dinfo.w;
|
||
|
surfaceH = dinfo.h;
|
||
|
int orient = GetDisplayOrientation();
|
||
|
if (orient == DISPLAY_ORIENTATION_90 || orient == DISPLAY_ORIENTATION_270) {
|
||
|
surfaceW = dinfo.h;
|
||
|
surfaceH = dinfo.w;
|
||
|
}
|
||
|
if (orient != -1) {
|
||
|
Rect destRect = Rect(surfaceW, surfaceH);
|
||
|
Rect viewport = destRect;
|
||
|
ALOGD("CreateSurface: Reset display size[%d*%d] orentation[%d]", surfaceW, surfaceH, orient);
|
||
|
t.setDisplayProjection(token, orient, viewport, destRect);
|
||
|
}
|
||
|
// create the native surface
|
||
|
controlPlayer = session->createSurface(String8("Bootvideo_Player"),
|
||
|
surfaceW, surfaceH, PIXEL_FORMAT_BGRA_8888);
|
||
|
controlUi = session->createSurface(String8("Bootvideo_UI"),
|
||
|
surfaceW, surfaceH, PIXEL_FORMAT_BGRA_8888);
|
||
|
// set layer
|
||
|
t.setLayer(controlPlayer, 0x3fffffff).apply();
|
||
|
t.setLayer(controlUi, 0x40000000).apply();
|
||
|
return true;
|
||
|
}
|
||
|
#else
|
||
|
SurfaceSverUI::SurfaceSverUI()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
SurfaceSverUI::~SurfaceSverUI()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
ui::Size SurfaceSverUI::limitSurfaceSize(int width, int height) const
|
||
|
{
|
||
|
ui::Size limited(width, height);
|
||
|
bool wasLimited = false;
|
||
|
const float aspectRatio = float(width) / float(height);
|
||
|
if (mMaxWidth != 0 && width > mMaxWidth) {
|
||
|
limited.height = mMaxWidth / aspectRatio;
|
||
|
limited.width = mMaxWidth;
|
||
|
wasLimited = true;
|
||
|
}
|
||
|
if (mMaxHeight != 0 && limited.height > mMaxHeight) {
|
||
|
limited.height = mMaxHeight;
|
||
|
limited.width = mMaxHeight * aspectRatio;
|
||
|
wasLimited = true;
|
||
|
}
|
||
|
SLOGV_IF(wasLimited, "Surface size has been limited to [%dx%d] from [%dx%d]",
|
||
|
limited.width, limited.height, width, height);
|
||
|
return limited;
|
||
|
}
|
||
|
|
||
|
bool SurfaceSverUI::CreateSurface()
|
||
|
{
|
||
|
SurfaceComposerClient::Transaction t;
|
||
|
sp<SurfaceComposerClient> session = new SurfaceComposerClient();
|
||
|
sp<IBinder> token = SurfaceComposerClient::getInternalDisplayToken();
|
||
|
if (token == nullptr) {
|
||
|
ALOGE("CreateSurface: token is NULL");
|
||
|
return false;
|
||
|
}
|
||
|
ui::DisplayMode displayMode;
|
||
|
const status_t error =
|
||
|
SurfaceComposerClient::getActiveDisplayMode(token, &displayMode);
|
||
|
if (error != NO_ERROR) {
|
||
|
return false;
|
||
|
}
|
||
|
// set display size
|
||
|
mMaxWidth = android::base::GetIntProperty("ro.surface_flinger.max_graphics_width", 0);
|
||
|
mMaxHeight = android::base::GetIntProperty("ro.surface_flinger.max_graphics_height", 0);
|
||
|
ui::Size resolution = displayMode.resolution;
|
||
|
resolution = limitSurfaceSize(resolution.width, resolution.height);
|
||
|
|
||
|
surfaceW = resolution.width;
|
||
|
surfaceH = resolution.height;
|
||
|
int orient = GetDisplayOrientation();
|
||
|
if (orient == DISPLAY_ORIENTATION_90 || orient == DISPLAY_ORIENTATION_270) {
|
||
|
surfaceW = resolution.height;
|
||
|
surfaceH = resolution.width;
|
||
|
}
|
||
|
if (orient != -1) {
|
||
|
Rect destRect = Rect(surfaceW, surfaceH);
|
||
|
Rect viewport = destRect;
|
||
|
ALOGD("CreateSurface: Reset display size[%d*%d] orentation[%d]", surfaceW, surfaceH, orient);
|
||
|
t.setDisplayProjection(token, static_cast<ui::Rotation>(orient), viewport, destRect);
|
||
|
}
|
||
|
// create the native surface
|
||
|
controlPlayer = session->createSurface(String8("Bootvideo_Player"),
|
||
|
surfaceW, surfaceH, PIXEL_FORMAT_BGRA_8888);
|
||
|
controlUi = session->createSurface(String8("Bootvideo_UI"),
|
||
|
surfaceW, surfaceH, PIXEL_FORMAT_BGRA_8888);
|
||
|
// set layer
|
||
|
t.setLayer(controlPlayer, 0x3fffffff).apply();
|
||
|
t.setLayer(controlUi, 0x40000000).apply();
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
#endif
|
||
|
} // namespace android
|