| 77 | } |
| 78 | |
| 79 | Valdi::Result<Valdi::Ref<AndroidBitmap>> AndroidBitmap::make(const Valdi::BitmapInfo& info) { |
| 80 | const GlobalRefJavaObjectBase* config = nullptr; |
| 81 | switch (info.colorType) { |
| 82 | case Valdi::ColorTypeBGRA8888: { |
| 83 | static auto kConfig = getBitmapConfigForName("ARGB_8888"); |
| 84 | config = &kConfig; |
| 85 | break; |
| 86 | } |
| 87 | case Valdi::ColorTypeAlpha8: { |
| 88 | static auto kConfig = getBitmapConfigForName("ALPHA_8"); |
| 89 | config = &kConfig; |
| 90 | break; |
| 91 | } |
| 92 | default: |
| 93 | return Valdi::Error("Unsupported Bitmap color type for Android Bitmap"); |
| 94 | } |
| 95 | |
| 96 | auto& cache = JavaEnv::getCache(); |
| 97 | auto jBitmap = cache.getBitmapCreateBitmapMethod().call(cache.getBitmapClass().getClass(), |
| 98 | static_cast<int32_t>(info.width), |
| 99 | static_cast<int32_t>(info.height), |
| 100 | BitmapConfigType(JavaEnv(), config->get())); |
| 101 | |
| 102 | if (jBitmap.isNull()) { |
| 103 | return Valdi::Error("Bitmap.createBitmap returned null"); |
| 104 | } |
| 105 | |
| 106 | // // Ensure premultiplied state matches alphaType expectation |
| 107 | // if (info.alphaType == Valdi::AlphaTypePremul || info.alphaType == Valdi::AlphaTypeOpaque) { |
| 108 | // cache.getBitmapSetPremultipliedMethod().call(jBitmap, true); |
| 109 | // } else if (info.alphaType == Valdi::AlphaTypeUnpremul) { |
| 110 | // cache.getBitmapSetPremultipliedMethod().call(jBitmap, false); |
| 111 | // } |
| 112 | |
| 113 | return Valdi::makeShared<AndroidBitmap>(jBitmap); |
| 114 | } |
| 115 | |
| 116 | AndroidBitmapHandler::AndroidBitmapHandler(JavaEnv env, jobject bitmapHandler, bool isOwned) |
| 117 | : AndroidBitmap(JavaEnv::getCache().getBitmapHandlerGetBitmapMethod().call(bitmapHandler)), |
no test coverage detected