#include "SurfaceUI.h" #include #include #if PLATFORM_SDK_VERSION <= __ANDROID_API_Q__ #include #include #include #include #else #include #include #include #include #include #include #include #include #include #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 session = new SurfaceComposerClient(); sp 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 session = new SurfaceComposerClient(); sp 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(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