diff options
| author | 2021-10-07 23:50:15 +0000 | |
|---|---|---|
| committer | 2021-10-07 23:50:15 +0000 | |
| commit | c03b0fa033117c03430e361d561aa910e95a0478 (patch) | |
| tree | 9c6aaee5a3023a6c237394b44e06a3fdb46f6747 /cmds/bootanimation/BootAnimation.cpp | |
| parent | 8cc0f40cf250d9c66dc15d0e8bc3a41db9a7cfa1 (diff) | |
| parent | 531b8f4f2605c44cf73e8421f674a1c7a9c277ff (diff) | |
Merge "Merge Android 12"
Diffstat (limited to 'cmds/bootanimation/BootAnimation.cpp')
| -rw-r--r-- | cmds/bootanimation/BootAnimation.cpp | 133 |
1 files changed, 79 insertions, 54 deletions
diff --git a/cmds/bootanimation/BootAnimation.cpp b/cmds/bootanimation/BootAnimation.cpp index 57f0e0c93b05..3109c5c1e075 100644 --- a/cmds/bootanimation/BootAnimation.cpp +++ b/cmds/bootanimation/BootAnimation.cpp @@ -34,6 +34,7 @@ #include <cutils/atomic.h> #include <cutils/properties.h> +#include <android/imagedecoder.h> #include <androidfw/AssetManager.h> #include <binder/IPCThreadState.h> #include <utils/Errors.h> @@ -42,7 +43,7 @@ #include <android-base/properties.h> -#include <ui/DisplayConfig.h> +#include <ui/DisplayMode.h> #include <ui/PixelFormat.h> #include <ui/Rect.h> #include <ui/Region.h> @@ -52,14 +53,6 @@ #include <gui/Surface.h> #include <gui/SurfaceComposerClient.h> -// TODO: Fix Skia. -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-parameter" -#include <SkBitmap.h> -#include <SkImage.h> -#include <SkStream.h> -#pragma GCC diagnostic pop - #include <GLES/gl.h> #include <GLES/glext.h> #include <EGL/eglext.h> @@ -72,6 +65,8 @@ namespace android { +using ui::DisplayMode; + static const char OEM_BOOTANIMATION_FILE[] = "/oem/media/bootanimation.zip"; static const char PRODUCT_BOOTANIMATION_DARK_FILE[] = "/product/media/bootanimation-dark.zip"; static const char PRODUCT_BOOTANIMATION_FILE[] = "/product/media/bootanimation.zip"; @@ -117,8 +112,8 @@ static constexpr size_t TEXT_POS_LEN_MAX = 16; // --------------------------------------------------------------------------- BootAnimation::BootAnimation(sp<Callbacks> callbacks) - : Thread(false), mClockEnabled(true), mTimeIsAccurate(false), mTimeFormat12Hour(false), - mTimeCheckThread(nullptr), mCallbacks(callbacks), mLooper(new Looper(false)) { + : Thread(false), mLooper(new Looper(false)), mClockEnabled(true), mTimeIsAccurate(false), + mTimeFormat12Hour(false), mTimeCheckThread(nullptr), mCallbacks(callbacks) { mSession = new SurfaceComposerClient(); std::string powerCtl = android::base::GetProperty("sys.powerctl", ""); @@ -168,22 +163,51 @@ void BootAnimation::binderDied(const wp<IBinder>&) { requestExit(); } +static void* decodeImage(const void* encodedData, size_t dataLength, AndroidBitmapInfo* outInfo) { + AImageDecoder* decoder = nullptr; + AImageDecoder_createFromBuffer(encodedData, dataLength, &decoder); + if (!decoder) { + return nullptr; + } + + const AImageDecoderHeaderInfo* info = AImageDecoder_getHeaderInfo(decoder); + outInfo->width = AImageDecoderHeaderInfo_getWidth(info); + outInfo->height = AImageDecoderHeaderInfo_getHeight(info); + outInfo->format = AImageDecoderHeaderInfo_getAndroidBitmapFormat(info); + outInfo->stride = AImageDecoder_getMinimumStride(decoder); + outInfo->flags = 0; + + const size_t size = outInfo->stride * outInfo->height; + void* pixels = malloc(size); + int result = AImageDecoder_decodeImage(decoder, pixels, outInfo->stride, size); + AImageDecoder_delete(decoder); + + if (result != ANDROID_IMAGE_DECODER_SUCCESS) { + free(pixels); + return nullptr; + } + return pixels; +} + status_t BootAnimation::initTexture(Texture* texture, AssetManager& assets, const char* name) { Asset* asset = assets.open(name, Asset::ACCESS_BUFFER); if (asset == nullptr) return NO_INIT; - SkBitmap bitmap; - sk_sp<SkData> data = SkData::MakeWithoutCopy(asset->getBuffer(false), - asset->getLength()); - sk_sp<SkImage> image = SkImage::MakeFromEncoded(data); - image->asLegacyBitmap(&bitmap, SkImage::kRO_LegacyBitmapMode); + + AndroidBitmapInfo bitmapInfo; + void* pixels = decodeImage(asset->getBuffer(false), asset->getLength(), &bitmapInfo); + auto pixelDeleter = std::unique_ptr<void, decltype(free)*>{ pixels, free }; + asset->close(); delete asset; - const int w = bitmap.width(); - const int h = bitmap.height(); - const void* p = bitmap.getPixels(); + if (!pixels) { + return NO_INIT; + } + + const int w = bitmapInfo.width; + const int h = bitmapInfo.height; GLint crop[4] = { 0, h, w, -h }; texture->w = w; @@ -192,22 +216,22 @@ status_t BootAnimation::initTexture(Texture* texture, AssetManager& assets, glGenTextures(1, &texture->name); glBindTexture(GL_TEXTURE_2D, texture->name); - switch (bitmap.colorType()) { - case kAlpha_8_SkColorType: + switch (bitmapInfo.format) { + case ANDROID_BITMAP_FORMAT_A_8: glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_ALPHA, - GL_UNSIGNED_BYTE, p); + GL_UNSIGNED_BYTE, pixels); break; - case kARGB_4444_SkColorType: + case ANDROID_BITMAP_FORMAT_RGBA_4444: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, - GL_UNSIGNED_SHORT_4_4_4_4, p); + GL_UNSIGNED_SHORT_4_4_4_4, pixels); break; - case kN32_SkColorType: + case ANDROID_BITMAP_FORMAT_RGBA_8888: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, - GL_UNSIGNED_BYTE, p); + GL_UNSIGNED_BYTE, pixels); break; - case kRGB_565_SkColorType: + case ANDROID_BITMAP_FORMAT_RGB_565: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, - GL_UNSIGNED_SHORT_5_6_5, p); + GL_UNSIGNED_SHORT_5_6_5, pixels); break; default: break; @@ -223,20 +247,21 @@ status_t BootAnimation::initTexture(Texture* texture, AssetManager& assets, } status_t BootAnimation::initTexture(FileMap* map, int* width, int* height) { - SkBitmap bitmap; - sk_sp<SkData> data = SkData::MakeWithoutCopy(map->getDataPtr(), - map->getDataLength()); - sk_sp<SkImage> image = SkImage::MakeFromEncoded(data); - image->asLegacyBitmap(&bitmap, SkImage::kRO_LegacyBitmapMode); + AndroidBitmapInfo bitmapInfo; + void* pixels = decodeImage(map->getDataPtr(), map->getDataLength(), &bitmapInfo); + auto pixelDeleter = std::unique_ptr<void, decltype(free)*>{ pixels, free }; // FileMap memory is never released until application exit. // Release it now as the texture is already loaded and the memory used for // the packed resource can be released. delete map; - const int w = bitmap.width(); - const int h = bitmap.height(); - const void* p = bitmap.getPixels(); + if (!pixels) { + return NO_INIT; + } + + const int w = bitmapInfo.width; + const int h = bitmapInfo.height; GLint crop[4] = { 0, h, w, -h }; int tw = 1 << (31 - __builtin_clz(w)); @@ -244,28 +269,28 @@ status_t BootAnimation::initTexture(FileMap* map, int* width, int* height) { if (tw < w) tw <<= 1; if (th < h) th <<= 1; - switch (bitmap.colorType()) { - case kN32_SkColorType: + switch (bitmapInfo.format) { + case ANDROID_BITMAP_FORMAT_RGBA_8888: if (!mUseNpotTextures && (tw != w || th != h)) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); glTexSubImage2D(GL_TEXTURE_2D, 0, - 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, p); + 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels); } else { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, - GL_UNSIGNED_BYTE, p); + GL_UNSIGNED_BYTE, pixels); } break; - case kRGB_565_SkColorType: + case ANDROID_BITMAP_FORMAT_RGB_565: if (!mUseNpotTextures && (tw != w || th != h)) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tw, th, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr); glTexSubImage2D(GL_TEXTURE_2D, 0, - 0, 0, w, h, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, p); + 0, 0, w, h, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, pixels); } else { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, - GL_UNSIGNED_SHORT_5_6_5, p); + GL_UNSIGNED_SHORT_5_6_5, pixels); } break; default: @@ -322,14 +347,14 @@ public: continue; } - DisplayConfig displayConfig; - const status_t error = SurfaceComposerClient::getActiveDisplayConfig( - mBootAnimation->mDisplayToken, &displayConfig); + DisplayMode displayMode; + const status_t error = SurfaceComposerClient::getActiveDisplayMode( + mBootAnimation->mDisplayToken, &displayMode); if (error != NO_ERROR) { - SLOGE("Can't get active display configuration."); + SLOGE("Can't get active display mode."); } - mBootAnimation->resizeSurface(displayConfig.resolution.getWidth(), - displayConfig.resolution.getHeight()); + mBootAnimation->resizeSurface(displayMode.resolution.getWidth(), + displayMode.resolution.getHeight()); } } } while (numEvents > 0); @@ -378,15 +403,15 @@ status_t BootAnimation::readyToRun() { if (mDisplayToken == nullptr) return NAME_NOT_FOUND; - DisplayConfig displayConfig; + DisplayMode displayMode; const status_t error = - SurfaceComposerClient::getActiveDisplayConfig(mDisplayToken, &displayConfig); + SurfaceComposerClient::getActiveDisplayMode(mDisplayToken, &displayMode); if (error != NO_ERROR) return error; 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 = displayConfig.resolution; + ui::Size resolution = displayMode.resolution; resolution = limitSurfaceSize(resolution.width, resolution.height); // create the native surface sp<SurfaceControl> control = session()->createSurface(String8("BootAnimation"), @@ -397,7 +422,7 @@ status_t BootAnimation::readyToRun() { // this guest property specifies multi-display IDs to show the boot animation // multiple ids can be set with comma (,) as separator, for example: // setprop persist.boot.animation.displays 19260422155234049,19261083906282754 - Vector<uint64_t> physicalDisplayIds; + Vector<PhysicalDisplayId> physicalDisplayIds; char displayValue[PROPERTY_VALUE_MAX] = ""; property_get(DISPLAYS_PROP_NAME, displayValue, ""); bool isValid = displayValue[0] != '\0'; @@ -415,7 +440,7 @@ status_t BootAnimation::readyToRun() { } if (isValid) { std::istringstream stream(displayValue); - for (PhysicalDisplayId id; stream >> id; ) { + for (PhysicalDisplayId id; stream >> id.value; ) { physicalDisplayIds.add(id); if (stream.peek() == ',') stream.ignore(); |