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 "blimp/engine/renderer/engine_image_serialization_processor.h" | 5 #include "blimp/engine/renderer/engine_image_serialization_processor.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "third_party/libwebp/webp/encode.h" | 22 #include "third_party/libwebp/webp/encode.h" |
23 #include "third_party/skia/include/core/SkData.h" | 23 #include "third_party/skia/include/core/SkData.h" |
24 #include "third_party/skia/include/core/SkPicture.h" | 24 #include "third_party/skia/include/core/SkPicture.h" |
25 #include "third_party/skia/include/core/SkPixelSerializer.h" | 25 #include "third_party/skia/include/core/SkPixelSerializer.h" |
26 #include "third_party/skia/include/core/SkUnPreMultiply.h" | 26 #include "third_party/skia/include/core/SkUnPreMultiply.h" |
27 | 27 |
28 namespace blimp { | 28 namespace blimp { |
29 namespace engine { | 29 namespace engine { |
30 namespace { | 30 namespace { |
31 | 31 |
32 SkData* BlobCacheImageMetadataProtoAsSkData( | 32 sk_sp<SkData> BlobCacheImageMetadataProtoAsSkData( |
33 const BlobCacheImageMetadata& proto) { | 33 const BlobCacheImageMetadata& proto) { |
34 int signed_size = proto.ByteSize(); | 34 int signed_size = proto.ByteSize(); |
35 size_t unsigned_size = base::checked_cast<size_t>(signed_size); | 35 size_t unsigned_size = base::checked_cast<size_t>(signed_size); |
36 std::vector<uint8_t> serialized(unsigned_size); | 36 std::vector<uint8_t> serialized(unsigned_size); |
37 proto.SerializeWithCachedSizesToArray(serialized.data()); | 37 proto.SerializeWithCachedSizesToArray(serialized.data()); |
38 return SkData::NewWithCopy(serialized.data(), serialized.size()); | 38 return SkData::MakeWithCopy(serialized.data(), serialized.size()); |
39 } | 39 } |
40 | 40 |
41 // For each pixel, un-premultiplies the alpha-channel for each of the RGB | 41 // For each pixel, un-premultiplies the alpha-channel for each of the RGB |
42 // channels. As an example, for a channel value that before multiplication was | 42 // channels. As an example, for a channel value that before multiplication was |
43 // 255, and after applying an alpha of 128, the premultiplied pixel would be | 43 // 255, and after applying an alpha of 128, the premultiplied pixel would be |
44 // 128. The un-premultiply step uses the alpha-channel to get back to 255. The | 44 // 128. The un-premultiply step uses the alpha-channel to get back to 255. The |
45 // alpha channel is kept unchanged. | 45 // alpha channel is kept unchanged. |
46 void UnPremultiply(const unsigned char* in_pixels, | 46 void UnPremultiply(const unsigned char* in_pixels, |
47 unsigned char* out_pixels, | 47 unsigned char* out_pixels, |
48 size_t pixel_count) { | 48 size_t pixel_count) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 if (!blob_channel_->IsInClientCache(blob_id)) { | 138 if (!blob_channel_->IsInClientCache(blob_id)) { |
139 blob_channel_->DeliverBlob(blob_id); | 139 blob_channel_->DeliverBlob(blob_id); |
140 } | 140 } |
141 | 141 |
142 // Construct a proto with the image metadata. | 142 // Construct a proto with the image metadata. |
143 BlobCacheImageMetadata proto; | 143 BlobCacheImageMetadata proto; |
144 proto.set_id(blob_id); | 144 proto.set_id(blob_id); |
145 proto.set_width(pixmap.width()); | 145 proto.set_width(pixmap.width()); |
146 proto.set_height(pixmap.height()); | 146 proto.set_height(pixmap.height()); |
147 | 147 |
148 SkData* sk_data = BlobCacheImageMetadataProtoAsSkData(proto); | 148 sk_sp<SkData> sk_data = BlobCacheImageMetadataProtoAsSkData(proto); |
149 DVLOG(3) << "Returning image ID " << BlobIdToString(blob_id); | 149 DVLOG(3) << "Returning image ID " << BlobIdToString(blob_id); |
150 return sk_data; | 150 return sk_data.release(); |
151 } | 151 } |
152 | 152 |
153 scoped_refptr<BlobData> EngineImageSerializationProcessor::EncodeImageAsBlob( | 153 scoped_refptr<BlobData> EngineImageSerializationProcessor::EncodeImageAsBlob( |
154 const SkPixmap& pixmap) { | 154 const SkPixmap& pixmap) { |
155 DVLOG(2) << "Encoding image color_type=" << pixmap.colorType() | 155 DVLOG(2) << "Encoding image color_type=" << pixmap.colorType() |
156 << ", alpha_type=" << pixmap.alphaType() << " " << pixmap.width() | 156 << ", alpha_type=" << pixmap.alphaType() << " " << pixmap.width() |
157 << "x" << pixmap.height(); | 157 << "x" << pixmap.height(); |
158 | 158 |
159 WebPConfig config; | 159 WebPConfig config; |
160 CHECK(WebPConfigInit(&config)); | 160 CHECK(WebPConfigInit(&config)); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 } | 201 } |
202 | 202 |
203 scoped_refptr<BlobData> blob_data(new BlobData); | 203 scoped_refptr<BlobData> blob_data(new BlobData); |
204 blob_data->data.assign(reinterpret_cast<const char*>(writer_state_.mem), | 204 blob_data->data.assign(reinterpret_cast<const char*>(writer_state_.mem), |
205 writer_state_.size); | 205 writer_state_.size); |
206 return blob_data; | 206 return blob_data; |
207 } | 207 } |
208 | 208 |
209 } // namespace engine | 209 } // namespace engine |
210 } // namespace blimp | 210 } // namespace blimp |
OLD | NEW |