| 100 | } |
| 101 | |
| 102 | Valdi::Result<sk_sp<SkData>> bitmapToData(const Valdi::Ref<Valdi::IBitmap>& bitmap, |
| 103 | const Valdi::BitmapInfo& info, |
| 104 | bool copy) { |
| 105 | auto* bytes = bitmap->lockBytes(); |
| 106 | if (bytes == nullptr) { |
| 107 | return Valdi::Error("Failed to lock bytes"); |
| 108 | } |
| 109 | |
| 110 | auto size = info.rowBytes * static_cast<size_t>(info.height); |
| 111 | |
| 112 | if (copy) { |
| 113 | auto data = SkData::MakeWithCopy(bytes, size); |
| 114 | bitmap->unlockBytes(); |
| 115 | return data; |
| 116 | } else { |
| 117 | return SkData::MakeWithProc(bytes, size, &releaseBitmap, Valdi::unsafeBridgeRetain(bitmap.get())); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | } // namespace snap::drawing |
no test coverage detected