#include "third_party/blink/renderer/modules/canvas/imagebitmap/image_bitmap_factories.h"
#include <memory>
#include <utility>
#include "base/location.h"
#include "base/task/single_thread_task_runner.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_image_bitmap_options.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_throw_dom_exception.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_union_blob_htmlcanvaselement_htmlimageelement_htmlvideoelement_imagebitmap_imagedata_offscreencanvas_svgimageelement_videoframe.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/fileapi/blob.h"
#include "third_party/blink/renderer/core/frame/deprecation/deprecation.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/html/canvas/html_canvas_element.h"
#include "third_party/blink/renderer/core/html/canvas/image_data.h"
#include "third_party/blink/renderer/core/html/html_image_element.h"
#include "third_party/blink/renderer/core/html/media/html_video_element.h"
#include "third_party/blink/renderer/core/imagebitmap/image_bitmap.h"
#include "third_party/blink/renderer/core/offscreencanvas/offscreen_canvas.h"
#include "third_party/blink/renderer/core/svg/svg_image_element.h"
#include "third_party/blink/renderer/core/workers/worker_global_scope.h"
#include "third_party/blink/renderer/modules/webcodecs/video_frame.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/graphics/unaccelerated_static_bitmap_image.h"
#include "third_party/blink/renderer/platform/heap/cross_thread_handle.h"
#include "third_party/blink/renderer/platform/instrumentation/histogram.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread.h"
#include "third_party/blink/renderer/platform/scheduler/public/worker_pool.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier_base.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier_skia.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/wtf/shared_buffer.h"
#include "v8/include/v8.h"
namespace blink {
namespace {
enum CreateImageBitmapSource { … };
constexpr const char* kImageBitmapOptionNone = …;
gfx::Rect NormalizedCropRect(int x, int y, int width, int height) { … }
}
inline ImageBitmapSource* ToImageBitmapSourceInternal(
const V8ImageBitmapSource* value,
const ImageBitmapOptions* options,
bool has_crop_rect) { … }
ScriptPromise<ImageBitmap> ImageBitmapFactories::CreateImageBitmapFromBlob(
ScriptState* script_state,
ImageBitmapSource* bitmap_source,
std::optional<gfx::Rect> crop_rect,
const ImageBitmapOptions* options) { … }
ScriptPromise<ImageBitmap> ImageBitmapFactories::CreateImageBitmap(
ScriptState* script_state,
const V8ImageBitmapSource* bitmap_source,
const ImageBitmapOptions* options,
ExceptionState& exception_state) { … }
ScriptPromise<ImageBitmap> ImageBitmapFactories::CreateImageBitmap(
ScriptState* script_state,
const V8ImageBitmapSource* bitmap_source,
int sx,
int sy,
int sw,
int sh,
const ImageBitmapOptions* options,
ExceptionState& exception_state) { … }
ScriptPromise<ImageBitmap> ImageBitmapFactories::CreateImageBitmap(
ScriptState* script_state,
ImageBitmapSource* bitmap_source,
std::optional<gfx::Rect> crop_rect,
const ImageBitmapOptions* options,
ExceptionState& exception_state) { … }
const char ImageBitmapFactories::kSupplementName[] = …;
ImageBitmapFactories& ImageBitmapFactories::From(ExecutionContext& context) { … }
ImageBitmapFactories::ImageBitmapFactories(ExecutionContext& context)
: … { … }
void ImageBitmapFactories::AddLoader(ImageBitmapLoader* loader) { … }
void ImageBitmapFactories::DidFinishLoading(ImageBitmapLoader* loader) { … }
void ImageBitmapFactories::Trace(Visitor* visitor) const { … }
ImageBitmapFactories::ImageBitmapLoader::ImageBitmapLoader(
ImageBitmapFactories& factory,
std::optional<gfx::Rect> crop_rect,
ScriptState* script_state,
const ImageBitmapOptions* options)
: … { … }
void ImageBitmapFactories::ImageBitmapLoader::LoadBlobAsync(Blob* blob) { … }
ImageBitmapFactories::ImageBitmapLoader::~ImageBitmapLoader() { … }
void ImageBitmapFactories::ImageBitmapLoader::RejectPromise(
ImageBitmapRejectionReason reason) { … }
void ImageBitmapFactories::ImageBitmapLoader::ContextDestroyed() { … }
void ImageBitmapFactories::ImageBitmapLoader::DidFinishLoading(
FileReaderData data) { … }
void ImageBitmapFactories::ImageBitmapLoader::DidFail(
FileErrorCode error_code) { … }
namespace {
void DecodeImageOnDecoderThread(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
ArrayBufferContents contents,
ImageDecoder::AlphaOption alpha_option,
ColorBehavior color_behavior,
WTF::CrossThreadOnceFunction<
void(sk_sp<SkImage>, const ImageOrientationEnum)> result_callback) { … }
}
void ImageBitmapFactories::ImageBitmapLoader::ScheduleAsyncImageBitmapDecoding(
ArrayBufferContents contents) { … }
void ImageBitmapFactories::ImageBitmapLoader::ResolvePromiseOnOriginalThread(
sk_sp<SkImage> frame,
const ImageOrientationEnum orientation) { … }
void ImageBitmapFactories::ImageBitmapLoader::Trace(Visitor* visitor) const { … }
}