| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 88 |
| 89 return dst->installPixels(info, pixels_, row_bytes_); | 89 return dst->installPixels(info, pixels_, row_bytes_); |
| 90 } | 90 } |
| 91 | 91 |
| 92 private: | 92 private: |
| 93 SkImageInfo info_; | 93 SkImageInfo info_; |
| 94 void* pixels_; | 94 void* pixels_; |
| 95 size_t row_bytes_; | 95 size_t row_bytes_; |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 static bool UpdateYUVComponentSizes(ImageDecoder* decoder, | 98 static void UpdateYUVComponentSizes(ImageDecoder* decoder, |
| 99 SkISize component_sizes[3], | 99 SkISize component_sizes[3], |
| 100 size_t component_width_bytes[3]) { | 100 size_t component_width_bytes[3]) { |
| 101 if (!decoder->CanDecodeToYUV()) | 101 if (!decoder->CanDecodeToYUV()) |
| 102 return false; | 102 return false; |
| 103 | 103 |
| 104 for (int yuv_index = 0; yuv_index < 3; ++yuv_index) { | 104 for (int yuv_index = 0; yuv_index < 3; ++yuv_index) { |
| 105 IntSize size = decoder->DecodedYUVSize(yuv_index); | 105 IntSize size = decoder->DecodedYUVSize(yuv_index); |
| 106 component_sizes[yuv_index].set(size.Width(), size.Height()); | 106 component_sizes[yuv_index].set(size.Width(), size.Height()); |
| 107 component_width_bytes[yuv_index] = decoder->DecodedYUVWidthBytes(yuv_index); | 107 component_width_bytes[yuv_index] = decoder->DecodedYUVWidthBytes(yuv_index); |
| 108 } | 108 } |
| 109 | |
| 110 return true; | |
| 111 } | 109 } |
| 112 | 110 |
| 113 ImageFrameGenerator::ImageFrameGenerator(const SkISize& full_size, | 111 ImageFrameGenerator::ImageFrameGenerator(const SkISize& full_size, |
| 114 bool is_multi_frame, | 112 bool is_multi_frame, |
| 115 const ColorBehavior& color_behavior) | 113 const ColorBehavior& color_behavior) |
| 116 : full_size_(full_size), | 114 : full_size_(full_size), |
| 117 decoder_color_behavior_(color_behavior), | 115 decoder_color_behavior_(color_behavior), |
| 118 is_multi_frame_(is_multi_frame), | 116 is_multi_frame_(is_multi_frame), |
| 119 decode_failed_(false), | 117 decode_failed_(false), |
| 120 yuv_decoding_failed_(false), | |
| 121 frame_count_(0) {} | 118 frame_count_(0) {} |
| 122 | 119 |
| 123 ImageFrameGenerator::~ImageFrameGenerator() { | 120 ImageFrameGenerator::~ImageFrameGenerator() { |
| 124 ImageDecodingStore::Instance().RemoveCacheIndexedByGenerator(this); | 121 ImageDecodingStore::Instance().RemoveCacheIndexedByGenerator(this); |
| 125 } | 122 } |
| 126 | 123 |
| 127 bool ImageFrameGenerator::DecodeAndScale( | 124 bool ImageFrameGenerator::DecodeAndScale( |
| 128 SegmentReader* data, | 125 SegmentReader* data, |
| 129 bool all_data_received, | 126 bool all_data_received, |
| 130 size_t index, | 127 size_t index, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 decoder->SetImagePlanes(std::move(image_planes)); | 191 decoder->SetImagePlanes(std::move(image_planes)); |
| 195 | 192 |
| 196 DCHECK(decoder->CanDecodeToYUV()); | 193 DCHECK(decoder->CanDecodeToYUV()); |
| 197 | 194 |
| 198 if (decoder->DecodeToYUV()) { | 195 if (decoder->DecodeToYUV()) { |
| 199 SetHasAlpha(0, false); // YUV is always opaque | 196 SetHasAlpha(0, false); // YUV is always opaque |
| 200 return true; | 197 return true; |
| 201 } | 198 } |
| 202 | 199 |
| 203 DCHECK(decoder->Failed()); | 200 DCHECK(decoder->Failed()); |
| 204 yuv_decoding_failed_ = true; | |
| 205 return false; | 201 return false; |
| 206 } | 202 } |
| 207 | 203 |
| 208 SkBitmap ImageFrameGenerator::TryToResumeDecode( | 204 SkBitmap ImageFrameGenerator::TryToResumeDecode( |
| 209 SegmentReader* data, | 205 SegmentReader* data, |
| 210 bool all_data_received, | 206 bool all_data_received, |
| 211 size_t index, | 207 size_t index, |
| 212 const SkISize& scaled_size, | 208 const SkISize& scaled_size, |
| 213 SkBitmap::Allocator* allocator, | 209 SkBitmap::Allocator* allocator, |
| 214 ImageDecoder::AlphaOption alpha_option) { | 210 ImageDecoder::AlphaOption alpha_option) { |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 if (index < has_alpha_.size()) | 371 if (index < has_alpha_.size()) |
| 376 return has_alpha_[index]; | 372 return has_alpha_[index]; |
| 377 return true; | 373 return true; |
| 378 } | 374 } |
| 379 | 375 |
| 380 bool ImageFrameGenerator::GetYUVComponentSizes(SegmentReader* data, | 376 bool ImageFrameGenerator::GetYUVComponentSizes(SegmentReader* data, |
| 381 SkYUVSizeInfo* size_info) { | 377 SkYUVSizeInfo* size_info) { |
| 382 TRACE_EVENT2("blink", "ImageFrameGenerator::getYUVComponentSizes", "width", | 378 TRACE_EVENT2("blink", "ImageFrameGenerator::getYUVComponentSizes", "width", |
| 383 full_size_.width(), "height", full_size_.height()); | 379 full_size_.width(), "height", full_size_.height()); |
| 384 | 380 |
| 385 if (yuv_decoding_failed_) | |
| 386 return false; | |
| 387 | |
| 388 std::unique_ptr<ImageDecoder> decoder = ImageDecoder::Create( | 381 std::unique_ptr<ImageDecoder> decoder = ImageDecoder::Create( |
| 389 data, true, ImageDecoder::kAlphaPremultiplied, decoder_color_behavior_); | 382 data, true, ImageDecoder::kAlphaPremultiplied, decoder_color_behavior_); |
| 390 if (!decoder) | 383 if (!decoder) |
| 391 return false; | 384 return false; |
| 392 | 385 |
| 393 // Setting a dummy ImagePlanes object signals to the decoder that we want to | 386 // Setting a dummy ImagePlanes object signals to the decoder that we want to |
| 394 // do YUV decoding. | 387 // do YUV decoding. |
| 395 std::unique_ptr<ImagePlanes> dummy_image_planes = | 388 std::unique_ptr<ImagePlanes> dummy_image_planes = |
| 396 WTF::WrapUnique(new ImagePlanes); | 389 WTF::WrapUnique(new ImagePlanes); |
| 397 decoder->SetImagePlanes(std::move(dummy_image_planes)); | 390 decoder->SetImagePlanes(std::move(dummy_image_planes)); |
| 398 | 391 |
| 399 return UpdateYUVComponentSizes(decoder.get(), size_info->fSizes, | 392 UpdateYUVComponentSizes(decoder.get(), size_info->fSizes, |
| 400 size_info->fWidthBytes); | 393 size_info->fWidthBytes); |
| 394 |
| 395 return true; |
| 401 } | 396 } |
| 402 | 397 |
| 403 } // namespace blink | 398 } // namespace blink |
| OLD | NEW |