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 "chrome/utility/image_decoder_impl.h" | 5 #include "chrome/utility/image_decoder_impl.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 } | 68 } |
69 } | 69 } |
70 } | 70 } |
71 #endif // defined(OS_CHROMEOS) | 71 #endif // defined(OS_CHROMEOS) |
72 if (codec == mojom::ImageCodec::DEFAULT) { | 72 if (codec == mojom::ImageCodec::DEFAULT) { |
73 decoded_image = content::DecodeImage(encoded_data.storage().data(), | 73 decoded_image = content::DecodeImage(encoded_data.storage().data(), |
74 gfx::Size(), encoded_data.size()); | 74 gfx::Size(), encoded_data.size()); |
75 } | 75 } |
76 | 76 |
77 if (!decoded_image.isNull()) { | 77 if (!decoded_image.isNull()) { |
78 skia::mojom::BitmapPtr dummy_image = skia::mojom::Bitmap::New(); | 78 // When serialized, the space taken up by a skia::mojom::Bitmap excluding |
79 int64_t struct_size = | 79 // the pixel data payload should be: |
80 skia::mojom::GetSerializedSize_(dummy_image, nullptr) + kPadding; | 80 // sizeof(skia::mojom::Bitmap::Data_) + pixel data array header (8 bytes) |
| 81 // Use a bigger number in case we need padding at the end. |
| 82 int64_t struct_size = sizeof(skia::mojom::Bitmap::Data_) + kPadding; |
81 int64_t image_size = decoded_image.computeSize64(); | 83 int64_t image_size = decoded_image.computeSize64(); |
82 int halves = 0; | 84 int halves = 0; |
83 while (struct_size + (image_size >> 2 * halves) > max_message_size_) | 85 while (struct_size + (image_size >> 2 * halves) > max_message_size_) |
84 halves++; | 86 halves++; |
85 if (halves) { | 87 if (halves) { |
86 if (shrink_to_fit) { | 88 if (shrink_to_fit) { |
87 // If decoded image is too large for IPC message, shrink it by halves. | 89 // If decoded image is too large for IPC message, shrink it by halves. |
88 // This prevents quality loss, and should never overshrink on displays | 90 // This prevents quality loss, and should never overshrink on displays |
89 // smaller than 3600x2400. | 91 // smaller than 3600x2400. |
90 // TODO (Issue 416916): Instead of shrinking, return via shared memory | 92 // TODO (Issue 416916): Instead of shrinking, return via shared memory |
91 decoded_image = skia::ImageOperations::Resize( | 93 decoded_image = skia::ImageOperations::Resize( |
92 decoded_image, skia::ImageOperations::RESIZE_LANCZOS3, | 94 decoded_image, skia::ImageOperations::RESIZE_LANCZOS3, |
93 decoded_image.width() >> halves, decoded_image.height() >> halves); | 95 decoded_image.width() >> halves, decoded_image.height() >> halves); |
94 } else { | 96 } else { |
95 decoded_image.reset(); | 97 decoded_image.reset(); |
96 } | 98 } |
97 } | 99 } |
98 } | 100 } |
99 | 101 |
100 if (decoded_image.isNull()) | 102 if (decoded_image.isNull()) |
101 callback.Run(nullptr); | 103 callback.Run(nullptr); |
102 else | 104 else |
103 callback.Run(skia::mojom::Bitmap::From(decoded_image)); | 105 callback.Run(skia::mojom::Bitmap::From(decoded_image)); |
104 } | 106 } |
OLD | NEW |