OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "blimp/client/feature/compositor/decoding_image_generator.h" | |
6 | |
7 #include "base/numerics/safe_conversions.h" | |
8 #include "blimp/client/feature/compositor/blimp_image_decoder.h" | |
9 #include "blimp/client/feature/compositor/blob_image_serialization_processor.h" | |
10 #include "blimp/common/proto/blob_cache.pb.h" | |
11 #include "third_party/libwebp/webp/decode.h" | |
12 #include "third_party/libwebp/webp/demux.h" | |
13 #include "third_party/skia/include/core/SkData.h" | |
14 | |
15 namespace blimp { | |
16 namespace client { | |
17 | |
18 SkImageGenerator* DecodingImageGenerator::create(SkData* data) { | |
19 BlobCacheImageMetadata parsed_metadata; | |
20 int signed_size = base::checked_cast<int>(data->size()); | |
21 if (!parsed_metadata.ParseFromArray(data->data(), signed_size)) { | |
22 // Failed to parse proto, so will fail to decode later as well. Inform | |
23 // Skia by giving back an empty SkImageInfo. | |
24 return new DecodingImageGenerator(SkImageInfo::MakeN32Premul(0, 0), | |
25 data->data(), data->size()); | |
26 } | |
27 | |
28 return new DecodingImageGenerator( | |
29 SkImageInfo::MakeN32Premul(parsed_metadata.width(), | |
30 parsed_metadata.height()), | |
31 data->data(), data->size()); | |
32 } | |
33 | |
34 DecodingImageGenerator::DecodingImageGenerator(const SkImageInfo info, | |
35 const void* data, | |
36 size_t size) | |
37 : SkImageGenerator(info) { | |
38 if (!BlobImageSerializationProcessor::current()->GetAndDecodeBlob( | |
39 data, size, &decoded_bitmap_)) { | |
40 DLOG(FATAL) << "GetAndDecodeBlob() failed."; | |
41 } | |
42 } | |
43 | |
44 DecodingImageGenerator::~DecodingImageGenerator() {} | |
45 | |
46 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, | |
47 void* pixels, | |
48 size_t rowBytes, | |
49 SkPMColor table[], | |
50 int* tableCount) { | |
51 SkAutoLockPixels bitmapLock(decoded_bitmap_); | |
52 if (decoded_bitmap_.getPixels() != pixels) { | |
53 return decoded_bitmap_.copyPixelsTo(pixels, rowBytes * info.height(), | |
54 rowBytes); | |
55 } | |
56 return true; | |
57 } | |
58 | |
59 bool DecodingImageGenerator::onQueryYUV8(SkYUVSizeInfo* sizeInfo, | |
60 SkYUVColorSpace* colorSpace) const { | |
61 return false; | |
62 } | |
63 | |
64 bool DecodingImageGenerator::onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, | |
65 void* planes[3]) { | |
66 return false; | |
67 } | |
68 | |
69 } // namespace client | |
70 } // namespace blimp | |
OLD | NEW |