OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "services/image_decoder/image_decoder_impl.h" | 5 #include "services/data_decoder/image_decoder_impl.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "content/public/child/image_decoder_utils.h" | |
13 #include "mojo/public/cpp/bindings/strong_binding.h" | 12 #include "mojo/public/cpp/bindings/strong_binding.h" |
14 #include "skia/ext/image_operations.h" | 13 #include "skia/ext/image_operations.h" |
| 14 #include "third_party/WebKit/public/platform/WebData.h" |
| 15 #include "third_party/WebKit/public/platform/WebImage.h" |
| 16 #include "third_party/WebKit/public/platform/WebSize.h" |
15 #include "third_party/skia/include/core/SkBitmap.h" | 17 #include "third_party/skia/include/core/SkBitmap.h" |
16 | 18 |
17 #if defined(OS_CHROMEOS) | 19 #if defined(OS_CHROMEOS) |
18 #include "ui/gfx/codec/chromeos/jpeg_codec_robust_slow.h" | 20 #include "ui/gfx/codec/chromeos/jpeg_codec_robust_slow.h" |
19 #include "ui/gfx/codec/png_codec.h" | 21 #include "ui/gfx/codec/png_codec.h" |
20 #endif | 22 #endif |
21 | 23 |
22 namespace image_decoder { | 24 namespace data_decoder { |
23 | 25 |
24 namespace { | 26 namespace { |
25 | 27 |
26 int64_t kPadding = 64; | 28 int64_t kPadding = 64; |
27 | 29 |
28 } // namespace | 30 } // namespace |
29 | 31 |
30 ImageDecoderImpl::ImageDecoderImpl( | 32 ImageDecoderImpl::ImageDecoderImpl( |
31 std::unique_ptr<service_manager::ServiceContextRef> service_ref) | 33 std::unique_ptr<service_manager::ServiceContextRef> service_ref) |
32 : service_ref_(std::move(service_ref)) {} | 34 : service_ref_(std::move(service_ref)) {} |
(...skipping 18 matching lines...) Expand all Loading... |
51 if (encoded_data.size()) { | 53 if (encoded_data.size()) { |
52 std::unique_ptr<SkBitmap> decoded_jpeg(gfx::JPEGCodecRobustSlow::Decode( | 54 std::unique_ptr<SkBitmap> decoded_jpeg(gfx::JPEGCodecRobustSlow::Decode( |
53 encoded_data.data(), encoded_data.size())); | 55 encoded_data.data(), encoded_data.size())); |
54 if (decoded_jpeg.get() && !decoded_jpeg->empty()) | 56 if (decoded_jpeg.get() && !decoded_jpeg->empty()) |
55 decoded_image = *decoded_jpeg; | 57 decoded_image = *decoded_jpeg; |
56 } | 58 } |
57 } else if (codec == mojom::ImageCodec::ROBUST_PNG) { | 59 } else if (codec == mojom::ImageCodec::ROBUST_PNG) { |
58 // Our robust PNG decoding is using libpng. | 60 // Our robust PNG decoding is using libpng. |
59 if (encoded_data.size()) { | 61 if (encoded_data.size()) { |
60 SkBitmap decoded_png; | 62 SkBitmap decoded_png; |
61 if (gfx::PNGCodec::Decode( | 63 if (gfx::PNGCodec::Decode(encoded_data.data(), encoded_data.size(), |
62 encoded_data.data(), encoded_data.size(), &decoded_png)) { | 64 &decoded_png)) { |
63 decoded_image = decoded_png; | 65 decoded_image = decoded_png; |
64 } | 66 } |
65 } | 67 } |
66 } | 68 } |
67 #endif // defined(OS_CHROMEOS) | 69 #endif // defined(OS_CHROMEOS) |
68 if (codec == mojom::ImageCodec::DEFAULT) { | 70 if (codec == mojom::ImageCodec::DEFAULT) { |
69 decoded_image = content::DecodeImage( | 71 decoded_image = |
70 encoded_data.data(), desired_image_frame_size, encoded_data.size()); | 72 blink::WebImage::fromData( |
| 73 blink::WebData(reinterpret_cast<const char*>(encoded_data.data()), |
| 74 encoded_data.size()), |
| 75 desired_image_frame_size) |
| 76 .getSkBitmap(); |
71 } | 77 } |
72 | 78 |
73 if (!decoded_image.isNull()) { | 79 if (!decoded_image.isNull()) { |
74 // When serialized, the space taken up by a skia::mojom::Bitmap excluding | 80 // When serialized, the space taken up by a skia::mojom::Bitmap excluding |
75 // the pixel data payload should be: | 81 // the pixel data payload should be: |
76 // sizeof(skia::mojom::Bitmap::Data_) + pixel data array header (8 bytes) | 82 // sizeof(skia::mojom::Bitmap::Data_) + pixel data array header (8 bytes) |
77 // Use a bigger number in case we need padding at the end. | 83 // Use a bigger number in case we need padding at the end. |
78 int64_t struct_size = sizeof(skia::mojom::Bitmap::Data_) + kPadding; | 84 int64_t struct_size = sizeof(skia::mojom::Bitmap::Data_) + kPadding; |
79 int64_t image_size = decoded_image.computeSize64(); | 85 int64_t image_size = decoded_image.computeSize64(); |
80 int halves = 0; | 86 int halves = 0; |
(...skipping 12 matching lines...) Expand all Loading... |
93 decoded_image.width() >> halves, decoded_image.height() >> halves); | 99 decoded_image.width() >> halves, decoded_image.height() >> halves); |
94 } else { | 100 } else { |
95 decoded_image.reset(); | 101 decoded_image.reset(); |
96 } | 102 } |
97 } | 103 } |
98 } | 104 } |
99 | 105 |
100 callback.Run(decoded_image); | 106 callback.Run(decoded_image); |
101 } | 107 } |
102 | 108 |
103 } // namespace image_decoder | 109 } // namespace data_decoder |
OLD | NEW |