Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(701)

Unified Diff: third_party/WebKit/Source/platform/testing/ImageDecodeBench.cpp

Issue 2893023003: Add raster timing to ImageDecodeBench
Patch Set: Rebase Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/testing/ImageDecodeBench.cpp
diff --git a/third_party/WebKit/Source/platform/testing/ImageDecodeBench.cpp b/third_party/WebKit/Source/platform/testing/ImageDecodeBench.cpp
index 42654f1aaaf5cc9c6a0f787e080575f25854d006..11e0a7ea7fb1db0862386aabe109c445331fd304 100644
--- a/third_party/WebKit/Source/platform/testing/ImageDecodeBench.cpp
+++ b/third_party/WebKit/Source/platform/testing/ImageDecodeBench.cpp
@@ -2,10 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Provides a minimal wrapping of the Blink image decoders. Used to perform
-// a non-threaded, memory-to-memory image decode using micro second accuracy
-// clocks to measure image decode time. Optionally applies color correction
-// during image decoding on supported platforms (default off). Usage:
+// Provides a minimal wrapping of the Blink image decoders & Skia raster.
+// Used to perform a non-threaded, memory-to-memory image decode/raster using
+// micro second accuracy clocks to measure image decode time. Optionally
+// applies color correction during image decoding on supported platforms
+// (default off). Usage:
//
// % ninja -C out/Release image_decode_bench &&
// ./out/Release/image_decode_bench file [iterations]
@@ -19,6 +20,7 @@
// Iteration 1: (frame 0, frame 1, frame 2...)
//
// This means non-animated images will show up as one column.
+// Raster timing also shows up as one column.
//
// This .csv-formatted output is a common format for spreadsheet and data
// visualization programs. A user can take timings before and after a change,
@@ -49,6 +51,8 @@
#include "platform/wtf/PassRefPtr.h"
#include "platform/wtf/PtrUtil.h"
#include "public/platform/Platform.h"
+#include "third_party/skia/include/core/SkCanvas.h"
+#include "third_party/skia/include/core/SkSurface.h"
#include "ui/gfx/test/icc_profiles.h"
#if defined(_WIN32)
@@ -307,7 +311,7 @@ IterationsOfFrameTimings TimeDecode(PassRefPtr<SharedBuffer> data,
data.Get(), true, ImageDecoder::kAlphaPremultiplied,
apply_color_correction ? ColorBehavior::TransformToTargetForTesting()
: ColorBehavior::Ignore());
- constexpr bool all_data_received = true;
+ bool all_data_received = true;
decoder->SetData(data.Get(), all_data_received);
for (size_t frame_index = 0; frame_index < frame_count; ++frame_index) {
double start_time = GetCurrentTime();
@@ -336,7 +340,7 @@ IterationsOfFrameTimings TimePacketedDecode(PassRefPtr<SharedBuffer> data,
ImageDecoder::Create(data.Get(), true, ImageDecoder::kAlphaPremultiplied,
ColorBehavior::Ignore());
- constexpr bool total_all_data_received = true;
+ bool total_all_data_received = true;
frame_count_decoder->SetData(data.Get(), total_all_data_received);
size_t total_frame_count = frame_count_decoder->FrameCount();
@@ -385,6 +389,45 @@ IterationsOfFrameTimings TimePacketedDecode(PassRefPtr<SharedBuffer> data,
return timings;
}
+IterationsOfFrameTimings TimeRaster(PassRefPtr<SharedBuffer> data,
+ size_t iterations) {
+ std::unique_ptr<ImageDecoder> decoder =
+ ImageDecoder::Create(data.Get(), true, ImageDecoder::kAlphaPremultiplied,
+ ColorBehavior::Ignore());
+
+ bool all_data_received = true;
+ decoder->SetData(data.Get(), all_data_received);
+
+ if (!decoder->IsSizeAvailable()) {
+ fprintf(stderr, "failed to decode size\n");
+ exit(3);
+ }
+
+ size_t frame_count = decoder->FrameCount();
+
+ auto size = decoder->Size();
+ auto surface = SkSurface::MakeRasterN32Premul(size.Width(), size.Height());
+ auto canvas = surface->getCanvas();
+
+ IterationsOfFrameTimings timings(iterations, FrameTimings(frame_count, 0.0));
+ for (size_t i = 0; i < iterations; ++i) {
+ for (size_t frame_index = 0; frame_index < frame_count; ++frame_index) {
+ ImageFrame* frame = decoder->FrameBufferAtIndex(frame_index);
+ if (frame->GetStatus() != ImageFrame::kFrameComplete) {
+ fprintf(stderr, "failed to decode frame\n");
+ exit(3);
+ }
+
+ double start_time = GetCurrentTime();
+ canvas->drawBitmap(frame->Bitmap(), 0, 0, nullptr);
+ double elapsed_time = GetCurrentTime() - start_time;
+ timings[i][frame_index] = elapsed_time;
+ }
+ }
+
+ return timings;
+}
+
} // namespace
int Main(int argc, char* argv[]) {
@@ -401,6 +444,13 @@ int Main(int argc, char* argv[]) {
ColorBehavior::SetGlobalTargetColorProfile(profile);
}
+ bool time_raster = false;
+ if (argc >= 2 && strcmp(argv[1], "--raster") == 0) {
+ --argc;
+ ++argv;
+ time_raster = true;
+ }
+
const char* raw_output_file = nullptr;
if (argc >= 2 && strcmp(argv[1], "--raw-output") == 0) {
if (argc < 3) {
@@ -416,8 +466,8 @@ int Main(int argc, char* argv[]) {
if (argc < 2) {
fprintf(stderr,
- "Usage: %s [--color-correct] [--raw-output output_file] file "
- "[iterations] [packetSize]\n",
+ "Usage: %s [--color-correct] [--raw-output output_file] [--raster] "
+ "file [iterations] [packetSize]\n",
argv[0]);
exit(1);
}
@@ -451,6 +501,13 @@ int Main(int argc, char* argv[]) {
}
}
+ if (time_raster && packet_size) {
+ fprintf(stderr,
+ "It does not make sense to specify a packet size when "
+ "timing raster\n");
+ exit(1);
+ }
+
// Create a web platform. blink::Platform can't be used directly because its
// constructor is protected.
@@ -470,11 +527,15 @@ int Main(int argc, char* argv[]) {
data->Data();
IterationsOfFrameTimings timings;
- if (packet_size) {
- timings = TimePacketedDecode(data.Get(), apply_color_correction,
- packet_size, iterations);
+ if (time_raster) {
+ timings = TimeRaster(data.Get(), iterations);
} else {
- timings = TimeDecode(data.Get(), apply_color_correction, iterations);
+ if (packet_size) {
+ timings = TimePacketedDecode(data.Get(), apply_color_correction,
+ packet_size, iterations);
+ } else {
+ timings = TimeDecode(data.Get(), apply_color_correction, iterations);
+ }
}
if (raw_output_file)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698