Commit bf490fd1 authored by danakj's avatar danakj Committed by Commit Bot

Convert images sent back from the renderer on image decode requests

We assumed that giving an image to decode would result in an N32 pixel
format reply, but it seems not. So convert to N32 on receipt of the
reply from the renderer.

R=rsesek@chromium.org

Bug: 1148012, 1144462
Change-Id: I7ae2924f6450cb4d0261d6780861f85bf5ed15a0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2533519Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Commit-Queue: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826576}
parent 01d00908
...@@ -41,11 +41,12 @@ source_set("cpp") { ...@@ -41,11 +41,12 @@ source_set("cpp") {
"//base", "//base",
"//services/data_decoder/public/mojom", "//services/data_decoder/public/mojom",
] ]
deps = []
if (is_android) { if (is_android) {
sources += [ "json_sanitizer_android.cc" ] sources += [ "json_sanitizer_android.cc" ]
deps = deps +=
[ "//services/data_decoder/public/cpp/android:safe_json_jni_headers" ] [ "//services/data_decoder/public/cpp/android:safe_json_jni_headers" ]
} else { } else {
sources += [ "json_sanitizer_non_android.cc" ] sources += [ "json_sanitizer_non_android.cc" ]
...@@ -65,6 +66,7 @@ source_set("cpp") { ...@@ -65,6 +66,7 @@ source_set("cpp") {
"decode_image.cc", "decode_image.cc",
"safe_web_bundle_parser.cc", "safe_web_bundle_parser.cc",
] ]
deps += [ "//skia" ]
} }
defines = [ "IS_DATA_DECODER_PUBLIC_IMPL" ] defines = [ "IS_DATA_DECODER_PUBLIC_IMPL" ]
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/debug/dump_without_crashing.h" #include "base/debug/dump_without_crashing.h"
#include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/remote.h"
#include "services/data_decoder/public/cpp/data_decoder.h" #include "services/data_decoder/public/cpp/data_decoder.h"
#include "skia/ext/skia_utils_base.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
namespace data_decoder { namespace data_decoder {
...@@ -22,11 +23,13 @@ namespace { ...@@ -22,11 +23,13 @@ namespace {
// which point the reply is forwarded to the wrapped |callback|. // which point the reply is forwarded to the wrapped |callback|.
void OnDecodeImage(mojo::Remote<mojom::ImageDecoder> decoder, void OnDecodeImage(mojo::Remote<mojom::ImageDecoder> decoder,
mojom::ImageDecoder::DecodeImageCallback callback, mojom::ImageDecoder::DecodeImageCallback callback,
const SkBitmap& bitmap) { const SkBitmap& unsafe_bitmap) {
if (bitmap.colorType() != kN32_SkColorType) { // On receipt of an arbitrary bitmap from the renderer, we convert to an N32
// The renderer should be sending us N32 32bpp bitmaps in reply, otherwise // 32bpp bitmap. Other pixel sizes can lead to out-of-bounds mistakes when
// this can lead to out-of-bounds mistakes when transferring the pixels out // transferring the pixels out of the bitmap into other buffers.
// of the bitmap into other buffers. SkBitmap bitmap;
if (!skia::SkBitmapToN32OpaqueOrPremul(unsafe_bitmap, &bitmap)) {
NOTREACHED() << "Unable to convert bitmap for decode image";
base::debug::DumpWithoutCrashing(); base::debug::DumpWithoutCrashing();
std::move(callback).Run(SkBitmap()); std::move(callback).Run(SkBitmap());
return; return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment