| 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 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 #include "sky/engine/platform/SharedBuffer.h" | 28 #include "sky/engine/platform/SharedBuffer.h" |
| 29 #include "sky/engine/platform/TraceEvent.h" | 29 #include "sky/engine/platform/TraceEvent.h" |
| 30 #include "sky/engine/platform/graphics/ImageFrameGenerator.h" | 30 #include "sky/engine/platform/graphics/ImageFrameGenerator.h" |
| 31 #include "third_party/skia/include/core/SkData.h" | 31 #include "third_party/skia/include/core/SkData.h" |
| 32 #include "third_party/skia/include/core/SkImageInfo.h" | 32 #include "third_party/skia/include/core/SkImageInfo.h" |
| 33 | 33 |
| 34 namespace blink { | 34 namespace blink { |
| 35 | 35 |
| 36 DecodingImageGenerator::DecodingImageGenerator(PassRefPtr<ImageFrameGenerator> f
rameGenerator, const SkImageInfo& info, size_t index) | 36 DecodingImageGenerator::DecodingImageGenerator(PassRefPtr<ImageFrameGenerator> f
rameGenerator, const SkImageInfo& info, size_t index) |
| 37 : m_frameGenerator(frameGenerator) | 37 : SkImageGenerator(info) |
| 38 , m_imageInfo(info) | 38 , m_frameGenerator(frameGenerator) |
| 39 , m_frameIndex(index) | 39 , m_frameIndex(index) |
| 40 , m_generationId(0) | 40 , m_generationId(0) |
| 41 { | 41 { |
| 42 } | 42 } |
| 43 | 43 |
| 44 DecodingImageGenerator::~DecodingImageGenerator() | 44 DecodingImageGenerator::~DecodingImageGenerator() |
| 45 { | 45 { |
| 46 } | 46 } |
| 47 | 47 |
| 48 SkData* DecodingImageGenerator::onRefEncodedData() | 48 SkData* DecodingImageGenerator::onRefEncodedData() |
| 49 { | 49 { |
| 50 // FIXME: If the image has been clipped or scaled, do not return the origina
l | 50 // FIXME: If the image has been clipped or scaled, do not return the origina
l |
| 51 // encoded data, since on playback it will not be known how the clipping/sca
ling | 51 // encoded data, since on playback it will not be known how the clipping/sca
ling |
| 52 // was done. | 52 // was done. |
| 53 RefPtr<SharedBuffer> buffer = nullptr; | 53 RefPtr<SharedBuffer> buffer = nullptr; |
| 54 bool allDataReceived = false; | 54 bool allDataReceived = false; |
| 55 m_frameGenerator->copyData(&buffer, &allDataReceived); | 55 m_frameGenerator->copyData(&buffer, &allDataReceived); |
| 56 if (buffer && allDataReceived) | 56 if (buffer && allDataReceived) |
| 57 return SkData::NewWithCopy(buffer->data(), buffer->size()); | 57 return SkData::NewWithCopy(buffer->data(), buffer->size()); |
| 58 return 0; | 58 return 0; |
| 59 } | 59 } |
| 60 | 60 |
| 61 bool DecodingImageGenerator::onGetInfo(SkImageInfo* info) | 61 SkImageGenerator::Result DecodingImageGenerator::onGetPixels(const SkImageInfo&
info, void* pixels, size_t rowBytes, const Options& options, SkPMColor ctable[],
int* ctableCount) |
| 62 { | |
| 63 *info = m_imageInfo; | |
| 64 return true; | |
| 65 } | |
| 66 | |
| 67 SkImageGenerator::Result DecodingImageGenerator::onGetPixels(const SkImageInfo&
info, void* pixels, size_t rowBytes, SkPMColor ctable[], int* ctableCount) | |
| 68 { | 62 { |
| 69 TRACE_EVENT1("blink", "DecodingImageGenerator::getPixels", "index", static_c
ast<int>(m_frameIndex)); | 63 TRACE_EVENT1("blink", "DecodingImageGenerator::getPixels", "index", static_c
ast<int>(m_frameIndex)); |
| 70 | 64 |
| 71 // Implementation doesn't support scaling yet so make sure we're not given a
different size. | 65 // Implementation doesn't support scaling yet so make sure we're not given a
different size. |
| 72 if (info.width() != m_imageInfo.width() || info.height() != m_imageInfo.heig
ht() || info.colorType() != m_imageInfo.colorType()) { | 66 if (info.width() != info.width() || info.height() != info.height() || info.c
olorType() != info.colorType()) { |
| 73 // ImageFrame may have changed the owning SkBitmap to kOpaque_SkAlphaTyp
e after sniffing the encoded data, so if we see a request | 67 // ImageFrame may have changed the owning SkBitmap to kOpaque_SkAlphaTyp
e after sniffing the encoded data, so if we see a request |
| 74 // for opaque, that is ok even if our initial alphatype was not opaque. | 68 // for opaque, that is ok even if our initial alphatype was not opaque. |
| 75 return Result::kInvalidScale; | 69 return Result::kInvalidScale; |
| 76 } | 70 } |
| 77 | 71 |
| 78 bool decoded = m_frameGenerator->decodeAndScale(m_imageInfo, m_frameIndex, p
ixels, rowBytes); | 72 bool decoded = m_frameGenerator->decodeAndScale(info, m_frameIndex, pixels,
rowBytes); |
| 79 return decoded ? Result::kSuccess : Result::kInvalidInput; | 73 return decoded ? Result::kSuccess : Result::kInvalidInput; |
| 80 } | 74 } |
| 81 | 75 |
| 82 bool DecodingImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3],
size_t rowBytes[3]) | 76 bool DecodingImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3],
size_t rowBytes[3]) |
| 83 { | 77 { |
| 84 if (!planes || !planes[0]) { | 78 if (!planes || !planes[0]) { |
| 85 return m_frameGenerator->getYUVComponentSizes(sizes); | 79 return m_frameGenerator->getYUVComponentSizes(sizes); |
| 86 } | 80 } |
| 87 | 81 |
| 88 TRACE_EVENT0("blink", "DecodingImageGenerator::onGetYUV8Planes"); | 82 TRACE_EVENT0("blink", "DecodingImageGenerator::onGetYUV8Planes"); |
| 89 bool decoded = m_frameGenerator->decodeToYUV(planes, rowBytes); | 83 bool decoded = m_frameGenerator->decodeToYUV(planes, rowBytes); |
| 90 return decoded; | 84 return decoded; |
| 91 } | 85 } |
| 92 | 86 |
| 93 } // namespace blink | 87 } // namespace blink |
| OLD | NEW |