MCPcopy Create free account
hub / github.com/Snapchat/Valdi / make

Method make

valdi/src/valdi/android/AndroidBitmap.cpp:79–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77}
78
79Valdi::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
116AndroidBitmapHandler::AndroidBitmapHandler(JavaEnv env, jobject bitmapHandler, bool isOwned)
117 : AndroidBitmap(JavaEnv::getCache().getBitmapHandlerGetBitmapMethod().call(bitmapHandler)),

Callers 1

makeViewOperationsMethod · 0.45

Calls 7

getBitmapConfigForNameFunction · 0.85
callMethod · 0.65
getMethod · 0.65
ErrorInterface · 0.50
JavaEnvClass · 0.50
getClassMethod · 0.45
isNullMethod · 0.45

Tested by

no test coverage detected