Chromium Code Reviews| 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/client/feature/compositor/client_image_serialization_processor.h " | 5 #include "blimp/client/feature/compositor/client_image_serialization_processor.h " |
| 6 | 6 |
| 7 #include <stddef.h> | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/logging.h" | |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/sha1.h" | |
| 14 #include "base/strings/string_number_conversions.h" | |
| 7 #include "blimp/client/feature/compositor/blimp_image_decoder.h" | 15 #include "blimp/client/feature/compositor/blimp_image_decoder.h" |
| 8 #include "third_party/skia/include/core/SkPicture.h" | 16 #include "blimp/common/blob_cache/blob_cache.h" |
| 9 | 17 #include "blimp/common/blob_cache/id_util.h" |
| 10 class SkPixelSerializer; | 18 #include "blimp/common/proto/blob_cache.pb.h" |
| 19 #include "blimp/net/blob_channel/blob_channel_receiver.h" | |
| 11 | 20 |
| 12 namespace blimp { | 21 namespace blimp { |
| 13 namespace client { | 22 namespace client { |
| 14 | 23 |
| 15 ClientImageSerializationProcessor::ClientImageSerializationProcessor() { | 24 ClientImageSerializationProcessor::ClientImageSerializationProcessor() {} |
| 16 pixel_deserializer_ = &BlimpImageDecoder; | |
| 17 } | |
| 18 | 25 |
| 19 ClientImageSerializationProcessor::~ClientImageSerializationProcessor() {} | 26 ClientImageSerializationProcessor::~ClientImageSerializationProcessor() {} |
| 20 | 27 |
| 28 ClientImageSerializationProcessor* | |
| 29 ClientImageSerializationProcessor::GetInstance() { | |
| 30 return base::Singleton<ClientImageSerializationProcessor>::get(); | |
| 31 } | |
| 32 | |
| 33 // static | |
| 34 bool ClientImageSerializationProcessor::InstallPixelRefProc(const void* input, | |
| 35 size_t input_size, | |
| 36 SkBitmap* bitmap) { | |
| 37 DCHECK(input); | |
| 38 DCHECK(bitmap); | |
| 39 | |
| 40 return ClientImageSerializationProcessor::GetInstance()->GetAndDecodeBlob( | |
| 41 input, input_size, bitmap); | |
| 42 } | |
| 43 | |
| 44 bool ClientImageSerializationProcessor::GetAndDecodeBlob(const void* input, | |
| 45 size_t input_size, | |
| 46 SkBitmap* bitmap) { | |
| 47 BlobCacheImageMetadata parsed_metadata; | |
| 48 if (!parsed_metadata.ParseFromArray(input, input_size)) { | |
| 49 LOG(WARNING) << "Couldn't parse blob metadata structure."; | |
|
Wez
2016/05/21 01:08:03
This seems like an error, not a warning? Presumabl
Kevin M
2016/05/27 22:35:29
Done.
| |
| 50 return false; | |
| 51 } | |
| 52 if (!IsValidBlobId(parsed_metadata.id())) { | |
| 53 DLOG(ERROR) << "Image payload is not a valid blob ID."; | |
|
Wez
2016/05/21 01:08:03
Why only DLOG(ERROR) - you are LOG(WARNING)ing abo
Kevin M
2016/05/27 22:35:29
Done.
| |
| 54 return false; | |
| 55 } | |
| 56 | |
| 57 // Get the image blob synchronously. | |
| 58 // TODO(kmarshall): Add support for asynchronous Get() completion after Skia | |
| 59 // supports image replacement. | |
| 60 BlobDataPtr blob = blob_receiver_->Get(parsed_metadata.id()); | |
| 61 if (!blob) { | |
| 62 DLOG(WARNING) << "No blob found with ID: " | |
| 63 << BlobIdToString(parsed_metadata.id()); | |
|
Wez
2016/05/21 01:08:03
While we have synchronous fetch isn't this also a
Kevin M
2016/05/27 22:35:29
Done.
| |
| 64 return false; | |
| 65 } | |
| 66 | |
| 67 DVLOG(1) << "GetAndDecodeBlob(" << BlobIdToString(parsed_metadata.id()) | |
| 68 << ")"; | |
| 69 | |
| 70 return BlimpImageDecoder(reinterpret_cast<const void*>(&blob->data[0]), | |
| 71 blob->data.size(), bitmap); | |
| 72 } | |
| 73 | |
| 21 SkPixelSerializer* ClientImageSerializationProcessor::GetPixelSerializer() { | 74 SkPixelSerializer* ClientImageSerializationProcessor::GetPixelSerializer() { |
| 75 NOTREACHED(); | |
| 22 return nullptr; | 76 return nullptr; |
| 23 } | 77 } |
| 24 | 78 |
| 25 SkPicture::InstallPixelRefProc | 79 SkPicture::InstallPixelRefProc |
| 26 ClientImageSerializationProcessor::GetPixelDeserializer() { | 80 ClientImageSerializationProcessor::GetPixelDeserializer() { |
| 27 return pixel_deserializer_; | 81 return &ClientImageSerializationProcessor::InstallPixelRefProc; |
| 28 } | 82 } |
| 29 | 83 |
| 30 } // namespace client | 84 } // namespace client |
| 31 } // namespace blimp | 85 } // namespace blimp |
| OLD | NEW |