flutter_flutter/lib/ui/painting/single_frame_codec.h
Dan Field 5281322421
Refactor instantiateImageCodec/decodeImageFromPixels to provide an ImageDescriptor (#19537)
Refactors instantiateImageCodec and decodeImageFromPixels to provide intermediate data about the image width, height, and bytes per pixel. This allows for more fine grained control from Dart, particularly when trying to reason about how or whether to maintain aspect ratio in the targetWidth/targetHeight parameters.

This leaves the existing methods functional by re-implementing them to use the new ImmutableBuffer/ImageDescriptor class.

The ImmutableBuffer class is provided so that callers can avoid copying the image data multiple times if they wish to re-recreate the image descriptor.

Related Issues
2020-07-21 14:59:18 -07:00

52 lines
1.4 KiB
C++

// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_LIB_UI_PAINTING_SINGLE_FRAME_CODEC_H_
#define FLUTTER_LIB_UI_PAINTING_SINGLE_FRAME_CODEC_H_
#include "flutter/fml/macros.h"
#include "flutter/lib/ui/painting/codec.h"
#include "flutter/lib/ui/painting/frame_info.h"
#include "flutter/lib/ui/painting/image_decoder.h"
#include "flutter/lib/ui/painting/image_descriptor.h"
namespace flutter {
class SingleFrameCodec : public Codec {
public:
SingleFrameCodec(fml::RefPtr<ImageDescriptor> descriptor,
uint32_t target_width,
uint32_t target_height);
~SingleFrameCodec() override;
// |Codec|
int frameCount() const override;
// |Codec|
int repetitionCount() const override;
// |Codec|
Dart_Handle getNextFrame(Dart_Handle args) override;
// |DartWrappable|
size_t GetAllocationSize() const override;
private:
enum class Status { kNew, kInProgress, kComplete };
Status status_;
fml::RefPtr<ImageDescriptor> descriptor_;
uint32_t target_width_;
uint32_t target_height_;
fml::RefPtr<FrameInfo> cached_frame_;
std::vector<DartPersistentValue> pending_callbacks_;
FML_FRIEND_MAKE_REF_COUNTED(SingleFrameCodec);
FML_FRIEND_REF_COUNTED_THREAD_SAFE(SingleFrameCodec);
};
} // namespace flutter
#endif // FLUTTER_LIB_UI_PAINTING_SINGLE_FRAME_CODEC_H_