Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 7a64505

Browse files
author
Jonah Williams
authored
Revert "[Impeller] remove image upload workarounds. (#47209)"
This reverts commit 8eb5909.
1 parent 513e007 commit 7a64505

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

lib/ui/painting/image_decoder_impeller.cc

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
#include "flutter/fml/make_copyable.h"
1111
#include "flutter/fml/trace_event.h"
1212
#include "flutter/impeller/core/allocator.h"
13+
#include "flutter/impeller/core/texture.h"
1314
#include "flutter/impeller/display_list/dl_image_impeller.h"
1415
#include "flutter/impeller/renderer/command_buffer.h"
1516
#include "flutter/impeller/renderer/context.h"
17+
#include "flutter/lib/ui/painting/image_decoder_skia.h"
1618
#include "impeller/base/strings.h"
1719
#include "impeller/display_list/skia_conversions.h"
1820
#include "impeller/geometry/size.h"
19-
2021
#include "third_party/skia/include/core/SkAlphaType.h"
2122
#include "third_party/skia/include/core/SkBitmap.h"
2223
#include "third_party/skia/include/core/SkColorSpace.h"
@@ -31,6 +32,42 @@
3132

3233
namespace flutter {
3334

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+
3471
namespace {
3572
/**
3673
* Loads the gamut as a set of three points (triangle).
@@ -485,7 +522,8 @@ void ImageDecoderImpeller::Decode(fml::RefPtr<ImageDescriptor> descriptor,
485522
gpu_disabled_switch]() {
486523
sk_sp<DlImage> image;
487524
std::string decode_error;
488-
if (context->GetCapabilities()->SupportsBufferToTextureBlits()) {
525+
if (!kShouldUseMallocDeviceBuffer &&
526+
context->GetCapabilities()->SupportsBufferToTextureBlits()) {
489527
std::tie(image, decode_error) = UploadTextureToPrivate(
490528
context, bitmap_result.device_buffer, bitmap_result.image_info,
491529
bitmap_result.sk_bitmap, gpu_disabled_switch);
@@ -529,7 +567,9 @@ bool ImpellerAllocator::allocPixelRef(SkBitmap* bitmap) {
529567
(bitmap->width() * bitmap->bytesPerPixel());
530568

531569
std::shared_ptr<impeller::DeviceBuffer> device_buffer =
532-
allocator_->CreateBuffer(descriptor);
570+
kShouldUseMallocDeviceBuffer
571+
? std::make_shared<MallocDeviceBuffer>(descriptor)
572+
: allocator_->CreateBuffer(descriptor);
533573

534574
struct ImpellerPixelRef final : public SkPixelRef {
535575
ImpellerPixelRef(int w, int h, void* s, size_t r)

0 commit comments

Comments
 (0)