@@ -4271,10 +4271,10 @@ index 6c75829502336b0806db2531e78186d2c559e44c..1ad6b8e863c56fd572910db6c6fb524d
4271
4271
} // namespace WebCore
4272
4272
diff --git a/Source/WebCore/inspector/agents/InspectorScreencastAgent.cpp b/Source/WebCore/inspector/agents/InspectorScreencastAgent.cpp
4273
4273
new file mode 100644
4274
- index 0000000000000000000000000000000000000000..e7f4a5b8b23771f8d81dd4c61c642923399ca757
4274
+ index 0000000000000000000000000000000000000000..13ca5202e8e3ee5add01634037c2111798c58936
4275
4275
--- /dev/null
4276
4276
+++ b/Source/WebCore/inspector/agents/InspectorScreencastAgent.cpp
4277
- @@ -0,0 +1,158 @@
4277
+ @@ -0,0 +1,150 @@
4278
4278
+/*
4279
4279
+ * Copyright (C) 2020 Microsoft Corporation.
4280
4280
+ *
@@ -4342,14 +4342,6 @@ index 0000000000000000000000000000000000000000..e7f4a5b8b23771f8d81dd4c61c642923
4342
4342
+ if (isEnabled())
4343
4343
+ return;
4344
4344
+
4345
- +#if !PLATFORM(GTK)
4346
- + // TODO: make ImageBufferUtilitiesCairo produce jpeg on WPE and Windows.
4347
- + if (format != "png") {
4348
- + errorString = "Only png format is supported on WPE."_s;
4349
- + return;
4350
- + }
4351
- +#endif
4352
- +
4353
4345
+ if (format == "jpeg") {
4354
4346
+ m_format = "image/jpeg";
4355
4347
+ } else if (format == "png") {
@@ -5306,6 +5298,98 @@ index 892d8de6d345d91fda80cfa5334c4aa68b757da3..a22497d801a349487be10b15139e9c76
5306
5298
#endif
5307
5299
5308
5300
#if PLATFORM(IOS_FAMILY)
5301
+ diff --git a/Source/WebCore/platform/graphics/cairo/ImageBufferUtilitiesCairo.cpp b/Source/WebCore/platform/graphics/cairo/ImageBufferUtilitiesCairo.cpp
5302
+ index d79728555b7db9b59cb615c55a7a7a6851cb57c8..6a6bfcd87074be69790a9d4b7993d427953129f5 100644
5303
+ --- a/Source/WebCore/platform/graphics/cairo/ImageBufferUtilitiesCairo.cpp
5304
+ +++ b/Source/WebCore/platform/graphics/cairo/ImageBufferUtilitiesCairo.cpp
5305
+ @@ -48,6 +48,14 @@
5306
+ #include <wtf/glib/GUniquePtr.h>
5307
+ #endif
5308
+
5309
+ +#if PLATFORM(WPE)
5310
+ +#include <wtf/glib/GUniquePtr.h>
5311
+ +#include <stdio.h> // Needed by jpeglib.h for FILE.
5312
+ +extern "C" {
5313
+ +#include "jpeglib.h"
5314
+ +}
5315
+ +#endif
5316
+ +
5317
+ namespace WebCore {
5318
+
5319
+ #if !PLATFORM(GTK)
5320
+ @@ -65,8 +73,71 @@ static bool encodeImage(cairo_surface_t* image, const String& mimeType, Vector<u
5321
+ return cairo_surface_write_to_png_stream(image, writeFunction, output) == CAIRO_STATUS_SUCCESS;
5322
+ }
5323
+
5324
+ -Vector<uint8_t> data(cairo_surface_t* image, const String& mimeType, Optional<double>)
5325
+ +static Vector<uint8_t> encodeJpeg(cairo_surface_t* image, int quality)
5326
+ {
5327
+ + struct jpeg_compress_struct info;
5328
+ + struct jpeg_error_mgr error;
5329
+ + info.err = jpeg_std_error(&error);
5330
+ + jpeg_create_compress(&info);
5331
+ +
5332
+ + GUniqueOutPtr<guchar> buffer;
5333
+ + gsize bufferSize;
5334
+ + jpeg_mem_dest(&info, &buffer.outPtr(), &bufferSize);
5335
+ + info.image_width = cairo_image_surface_get_width(image);
5336
+ + info.image_height = cairo_image_surface_get_height(image);
5337
+ +
5338
+ + if (cairo_surface_get_type(image) != CAIRO_SURFACE_TYPE_IMAGE) {
5339
+ + fprintf(stderr, "Unexpected cairo surface type: %d\n", cairo_surface_get_type(image));
5340
+ + return { };
5341
+ + }
5342
+ +
5343
+ + if (cairo_image_surface_get_format(image) != CAIRO_FORMAT_ARGB32) {
5344
+ + fprintf(stderr, "Unexpected surface image format: %d\n", cairo_image_surface_get_format(image));
5345
+ + return { };
5346
+ + }
5347
+ +#ifndef LIBJPEG_TURBO_VERSION
5348
+ + COMPILE_ASSERT(false, only_libjpeg_turbo_is_supported);
5349
+ +#endif
5350
+ +
5351
+ +#if CPU(LITTLE_ENDIAN)
5352
+ + info.in_color_space = JCS_EXT_BGRA;
5353
+ +#else
5354
+ + info.in_color_space = JCS_EXT_ARGB;
5355
+ +#endif
5356
+ + // # of color components in input image
5357
+ + info.input_components = 4;
5358
+ +
5359
+ + jpeg_set_defaults(&info);
5360
+ + jpeg_set_quality(&info, quality, true);
5361
+ +
5362
+ + jpeg_start_compress(&info, true);
5363
+ +
5364
+ + while (info.next_scanline < info.image_height)
5365
+ + {
5366
+ + JSAMPROW row = cairo_image_surface_get_data(image) + (info.next_scanline * cairo_image_surface_get_stride(image));
5367
+ + if (jpeg_write_scanlines(&info, &row, 1) != 1) {
5368
+ + fprintf(stderr, "JPEG library failed to encode line\n");
5369
+ + return { };
5370
+ + }
5371
+ + }
5372
+ +
5373
+ + jpeg_finish_compress(&info);
5374
+ + jpeg_destroy_compress(&info);
5375
+ +
5376
+ + Vector<uint8_t> output;
5377
+ + output.append(buffer.get(), bufferSize);
5378
+ + return output;
5379
+ +}
5380
+ +
5381
+ +Vector<uint8_t> data(cairo_surface_t* image, const String& mimeType, Optional<double> quality)
5382
+ +{
5383
+ + if (mimeType == "image/jpeg") {
5384
+ + int qualityPercent = 100;
5385
+ + if (quality)
5386
+ + qualityPercent = static_cast<int>(*quality * 100.0 + 0.5);
5387
+ + return encodeJpeg(image, qualityPercent);
5388
+ + }
5389
+ +
5390
+ Vector<uint8_t> encodedImage;
5391
+ if (!image || !encodeImage(image, mimeType, &encodedImage))
5392
+ return { };
5309
5393
diff --git a/Source/WebCore/platform/graphics/cg/ImageBufferUtilitiesCG.h b/Source/WebCore/platform/graphics/cg/ImageBufferUtilitiesCG.h
5310
5394
index bc87758878d5163a938af8242c7a6800ea9bd13c..3d0751f8dfe1124bbe054daa2fa0c7552fecab32 100644
5311
5395
--- a/Source/WebCore/platform/graphics/cg/ImageBufferUtilitiesCG.h
0 commit comments