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 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 if (buffer && allDataReceived) | 60 if (buffer && allDataReceived) |
61 return SkData::NewWithCopy(buffer->data(), buffer->size()); | 61 return SkData::NewWithCopy(buffer->data(), buffer->size()); |
62 return 0; | 62 return 0; |
63 } | 63 } |
64 | 64 |
65 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels,
size_t rowBytes, | 65 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels,
size_t rowBytes, |
66 SkPMColor ctable[], int* ctableCount) | 66 SkPMColor ctable[], int* ctableCount) |
67 { | 67 { |
68 TRACE_EVENT1("blink", "DecodingImageGenerator::getPixels", "index", static_c
ast<int>(m_frameIndex)); | 68 TRACE_EVENT1("blink", "DecodingImageGenerator::getPixels", "index", static_c
ast<int>(m_frameIndex)); |
69 | 69 |
70 // Implementation doesn't support scaling yet so make sure we're not given a
different size. | |
71 if (info.width() != getInfo().width() || info.height() != getInfo().height()
) | |
72 return false; | |
73 | |
74 if (info.colorType() != getInfo().colorType()) { | 70 if (info.colorType() != getInfo().colorType()) { |
75 // ImageFrame may have changed the owning SkBitmap to kOpaque_SkAlphaTyp
e after sniffing the encoded data, so if we see a request | 71 // So far, only one implemented is RGB565 |
76 // for opaque, that is ok even if our initial alphatype was not opaque. | 72 if (info.colorType() != kRGB_565_SkColorType) |
77 return false; | 73 return false; |
78 } | 74 } |
79 | 75 |
80 PlatformInstrumentation::willDecodeLazyPixelRef(m_generationId); | 76 PlatformInstrumentation::willDecodeLazyPixelRef(m_generationId); |
81 bool decoded = m_frameGenerator->decodeAndScale(getInfo(), m_frameIndex, pix
els, rowBytes); | 77 bool decoded = m_frameGenerator->decodeAndScale(info, m_frameIndex, pixels,
rowBytes); |
82 PlatformInstrumentation::didDecodeLazyPixelRef(); | 78 PlatformInstrumentation::didDecodeLazyPixelRef(); |
83 | 79 |
84 return decoded; | 80 return decoded; |
85 } | 81 } |
86 | 82 |
87 bool DecodingImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3],
size_t rowBytes[3], SkYUVColorSpace* colorSpace) | 83 bool DecodingImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3],
size_t rowBytes[3], SkYUVColorSpace* colorSpace) |
88 { | 84 { |
89 if (!RuntimeEnabledFeatures::decodeToYUVEnabled()) | 85 if (!RuntimeEnabledFeatures::decodeToYUVEnabled()) |
90 return false; | 86 return false; |
91 | 87 |
(...skipping 26 matching lines...) Expand all Loading... |
118 const IntSize size = decoder->size(); | 114 const IntSize size = decoder->size(); |
119 const SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.heigh
t()); | 115 const SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.heigh
t()); |
120 | 116 |
121 RefPtr<ImageFrameGenerator> frame = ImageFrameGenerator::create(SkISize::Mak
e(size.width(), size.height()), buffer, true, false); | 117 RefPtr<ImageFrameGenerator> frame = ImageFrameGenerator::create(SkISize::Mak
e(size.width(), size.height()), buffer, true, false); |
122 if (!frame) | 118 if (!frame) |
123 return 0; | 119 return 0; |
124 | 120 |
125 return new DecodingImageGenerator(frame, info, 0); | 121 return new DecodingImageGenerator(frame, info, 0); |
126 } | 122 } |
127 | 123 |
| 124 SkImageGenerator::Result DecodingImageGenerator::onCanDecodeAndScale(const SkCol
orType targetType, |
| 125 const SkScalar scale, SkISize* availableSize, SkISize* lowerSize) |
| 126 { |
| 127 SkColorType readC = targetType; |
| 128 float desired = SkScalarToFloat(scale); |
| 129 float read = desired; |
| 130 float lower = 0; |
| 131 m_frameGenerator->getAvailableDecodeAndScale(&readC, &read, &lower); |
| 132 if (availableSize) |
| 133 availableSize->set(static_cast<int>(ceil(getInfo().width() * read)), sta
tic_cast<int>(ceil(getInfo().height() * read))); |
| 134 if (lowerSize) |
| 135 lowerSize->set(static_cast<int>(ceil(getInfo().width() * lower)), static
_cast<int>(ceil(getInfo().height() * lower))); |
| 136 |
| 137 return static_cast<SkImageGenerator::Result>(((desired != 1.0f && read != 1.
0f) ? SkImageGenerator::kScale : SkImageGenerator::kNotAvailable) |
| 138 | ((readC == targetType) ? SkImageGenerator::kDecode : SkImageGenerator:
:kNotAvailable)); |
| 139 } |
| 140 |
128 } // namespace blink | 141 } // namespace blink |
129 | 142 |
OLD | NEW |