|
10 | 10 | #include "flutter/fml/make_copyable.h" |
11 | 11 | #include "flutter/fml/trace_event.h" |
12 | 12 | #include "flutter/impeller/core/allocator.h" |
| 13 | +#include "flutter/impeller/core/texture.h" |
13 | 14 | #include "flutter/impeller/display_list/dl_image_impeller.h" |
14 | 15 | #include "flutter/impeller/renderer/command_buffer.h" |
15 | 16 | #include "flutter/impeller/renderer/context.h" |
| 17 | +#include "flutter/lib/ui/painting/image_decoder_skia.h" |
16 | 18 | #include "impeller/base/strings.h" |
17 | 19 | #include "impeller/display_list/skia_conversions.h" |
18 | 20 | #include "impeller/geometry/size.h" |
19 | | - |
20 | 21 | #include "third_party/skia/include/core/SkAlphaType.h" |
21 | 22 | #include "third_party/skia/include/core/SkBitmap.h" |
22 | 23 | #include "third_party/skia/include/core/SkColorSpace.h" |
|
31 | 32 |
|
32 | 33 | namespace flutter { |
33 | 34 |
|
| 35 | +class MallocDeviceBuffer : public impeller::DeviceBuffer { |
| 36 | + public: |
| 37 | + explicit MallocDeviceBuffer(impeller::DeviceBufferDescriptor desc) |
| 38 | + : impeller::DeviceBuffer(desc) { |
| 39 | + data_ = static_cast<uint8_t*>(malloc(desc.size)); |
| 40 | + } |
| 41 | + |
| 42 | + ~MallocDeviceBuffer() override { free(data_); } |
| 43 | + |
| 44 | + bool SetLabel(const std::string& label) override { return true; } |
| 45 | + |
| 46 | + bool SetLabel(const std::string& label, impeller::Range range) override { |
| 47 | + return true; |
| 48 | + } |
| 49 | + |
| 50 | + uint8_t* OnGetContents() const override { return data_; } |
| 51 | + |
| 52 | + bool OnCopyHostBuffer(const uint8_t* source, |
| 53 | + impeller::Range source_range, |
| 54 | + size_t offset) override { |
| 55 | + memcpy(data_ + offset, source + source_range.offset, source_range.length); |
| 56 | + return true; |
| 57 | + } |
| 58 | + |
| 59 | + private: |
| 60 | + uint8_t* data_; |
| 61 | + |
| 62 | + FML_DISALLOW_COPY_AND_ASSIGN(MallocDeviceBuffer); |
| 63 | +}; |
| 64 | + |
| 65 | +#ifdef FML_OS_ANDROID |
| 66 | +static constexpr bool kShouldUseMallocDeviceBuffer = true; |
| 67 | +#else |
| 68 | +static constexpr bool kShouldUseMallocDeviceBuffer = false; |
| 69 | +#endif // FML_OS_ANDROID |
| 70 | + |
34 | 71 | namespace { |
35 | 72 | /** |
36 | 73 | * Loads the gamut as a set of three points (triangle). |
@@ -485,7 +522,8 @@ void ImageDecoderImpeller::Decode(fml::RefPtr<ImageDescriptor> descriptor, |
485 | 522 | gpu_disabled_switch]() { |
486 | 523 | sk_sp<DlImage> image; |
487 | 524 | std::string decode_error; |
488 | | - if (context->GetCapabilities()->SupportsBufferToTextureBlits()) { |
| 525 | + if (!kShouldUseMallocDeviceBuffer && |
| 526 | + context->GetCapabilities()->SupportsBufferToTextureBlits()) { |
489 | 527 | std::tie(image, decode_error) = UploadTextureToPrivate( |
490 | 528 | context, bitmap_result.device_buffer, bitmap_result.image_info, |
491 | 529 | bitmap_result.sk_bitmap, gpu_disabled_switch); |
@@ -529,7 +567,9 @@ bool ImpellerAllocator::allocPixelRef(SkBitmap* bitmap) { |
529 | 567 | (bitmap->width() * bitmap->bytesPerPixel()); |
530 | 568 |
|
531 | 569 | std::shared_ptr<impeller::DeviceBuffer> device_buffer = |
532 | | - allocator_->CreateBuffer(descriptor); |
| 570 | + kShouldUseMallocDeviceBuffer |
| 571 | + ? std::make_shared<MallocDeviceBuffer>(descriptor) |
| 572 | + : allocator_->CreateBuffer(descriptor); |
533 | 573 |
|
534 | 574 | struct ImpellerPixelRef final : public SkPixelRef { |
535 | 575 | ImpellerPixelRef(int w, int h, void* s, size_t r) |
|
0 commit comments