Commit 566d92a3 authored by Jim Van Verth's avatar Jim Van Verth Committed by Commit Bot

Update to new YUV interface from Skia.

Skia has revised the SkImageGenerator interface. SkYUVSizeInfo
has been expanded to support alpha and renamed to SkYUVASizeInfo.
In addition, the API adds the struct SkYUVAIndex to represent the
mapping from a YUVA channel to the texture index and RGBA channel
that represents it. This allows interleaved formats (e.g. NV12) to
be represented.

This CL updates Chromium to use the new interface.

Bug: skia:7903
Change-Id: I64a7056e535a114b4cfc0f86c93f5e6cd2c91bd3
Reviewed-on: https://chromium-review.googlesource.com/c/1297254Reviewed-by: default avatarFernando Serboncini <fserb@chromium.org>
Reviewed-by: default avatarKhushal <khushalsagar@chromium.org>
Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Reviewed-by: default avatarDan Sanders <sandersd@chromium.org>
Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Commit-Queue: Jim Van Verth <jvanverth@chromium.org>
Cr-Commit-Position: refs/heads/master@{#603554}
parent aa213a01
...@@ -14,7 +14,8 @@ ...@@ -14,7 +14,8 @@
#include "third_party/skia/include/core/SkData.h" #include "third_party/skia/include/core/SkData.h"
#include "third_party/skia/include/core/SkImageInfo.h" #include "third_party/skia/include/core/SkImageInfo.h"
#include "third_party/skia/include/core/SkSize.h" #include "third_party/skia/include/core/SkSize.h"
#include "third_party/skia/include/core/SkYUVSizeInfo.h" #include "third_party/skia/include/core/SkYUVAIndex.h"
#include "third_party/skia/include/core/SkYUVASizeInfo.h"
namespace cc { namespace cc {
...@@ -44,21 +45,25 @@ class CC_PAINT_EXPORT PaintImageGenerator : public SkRefCnt { ...@@ -44,21 +45,25 @@ class CC_PAINT_EXPORT PaintImageGenerator : public SkRefCnt {
// Returns true if the generator supports YUV decoding, providing the output // Returns true if the generator supports YUV decoding, providing the output
// information in |info| and |color_space|. // information in |info| and |color_space|.
virtual bool QueryYUV8(SkYUVSizeInfo* info, virtual bool QueryYUVA8(SkYUVASizeInfo* info,
SkYUVColorSpace* color_space) const = 0; SkYUVAIndex indices[SkYUVAIndex::kIndexCount],
SkYUVColorSpace* color_space) const = 0;
// Decodes to YUV into the provided |planes| for each of the Y, U, and V // Decodes to YUV into the provided |planes| for each of the Y, U, and V
// planes, and returns true on success. The method should only be used if // planes, and returns true on success. The method should only be used if
// QueryYUV8 returns true. // QueryYUVA8 returns true.
// |info| needs to exactly match the values returned by the query, except the // |info| and |indices| need to exactly match the values returned by the
// WidthBytes may be larger than the recommendation (but not smaller). // query, except the info.fWidthBytes may be larger than the recommendation
// (but not smaller).
// //
// TODO(khushalsagar): |lazy_pixel_ref| is only present for // TODO(khushalsagar): |lazy_pixel_ref| is only present for
// DecodingImageGenerator tracing needs. Remove it. // DecodingImageGenerator tracing needs. Remove it.
virtual bool GetYUV8Planes(const SkYUVSizeInfo& info, virtual bool GetYUVA8Planes(
void* planes[3], const SkYUVASizeInfo& info,
size_t frame_index, const SkYUVAIndex indices[SkYUVAIndex::kIndexCount],
uint32_t lazy_pixel_ref) = 0; void* planes[3],
size_t frame_index,
uint32_t lazy_pixel_ref) = 0;
// Returns the smallest size that is at least as big as the requested size, // Returns the smallest size that is at least as big as the requested size,
// such that we can decode to exactly that scale. // such that we can decode to exactly that scale.
......
...@@ -31,15 +31,19 @@ bool SkiaPaintImageGenerator::onGetPixels(const SkImageInfo& info, ...@@ -31,15 +31,19 @@ bool SkiaPaintImageGenerator::onGetPixels(const SkImageInfo& info,
info, pixels, row_bytes, frame_index_, client_id_, uniqueID()); info, pixels, row_bytes, frame_index_, client_id_, uniqueID());
} }
bool SkiaPaintImageGenerator::onQueryYUV8(SkYUVSizeInfo* size_info, bool SkiaPaintImageGenerator::onQueryYUVA8(
SkYUVColorSpace* color_space) const { SkYUVASizeInfo* size_info,
return paint_image_generator_->QueryYUV8(size_info, color_space); SkYUVAIndex indices[SkYUVAIndex::kIndexCount],
SkYUVColorSpace* color_space) const {
return paint_image_generator_->QueryYUVA8(size_info, indices, color_space);
} }
bool SkiaPaintImageGenerator::onGetYUV8Planes(const SkYUVSizeInfo& size_info, bool SkiaPaintImageGenerator::onGetYUVA8Planes(
void* planes[3]) { const SkYUVASizeInfo& size_info,
return paint_image_generator_->GetYUV8Planes(size_info, planes, frame_index_, const SkYUVAIndex indices[SkYUVAIndex::kIndexCount],
uniqueID()); void* planes[4]) {
return paint_image_generator_->GetYUVA8Planes(size_info, indices, planes,
frame_index_, uniqueID());
} }
} // namespace cc } // namespace cc
...@@ -25,10 +25,12 @@ class CC_PAINT_EXPORT SkiaPaintImageGenerator final : public SkImageGenerator { ...@@ -25,10 +25,12 @@ class CC_PAINT_EXPORT SkiaPaintImageGenerator final : public SkImageGenerator {
void* pixels, void* pixels,
size_t row_bytes, size_t row_bytes,
const Options& options) override; const Options& options) override;
bool onQueryYUV8(SkYUVSizeInfo* size_info, bool onQueryYUVA8(SkYUVASizeInfo* size_info,
SkYUVColorSpace* color_space) const override; SkYUVAIndex indices[SkYUVAIndex::kIndexCount],
bool onGetYUV8Planes(const SkYUVSizeInfo& size_info, SkYUVColorSpace* color_space) const override;
void* planes[3]) override; bool onGetYUVA8Planes(const SkYUVASizeInfo& size_info,
const SkYUVAIndex indices[SkYUVAIndex::kIndexCount],
void* planes[3]) override;
private: private:
sk_sp<PaintImageGenerator> paint_image_generator_; sk_sp<PaintImageGenerator> paint_image_generator_;
......
...@@ -42,15 +42,17 @@ bool FakePaintImageGenerator::GetPixels(const SkImageInfo& info, ...@@ -42,15 +42,17 @@ bool FakePaintImageGenerator::GetPixels(const SkImageInfo& info,
return true; return true;
} }
bool FakePaintImageGenerator::QueryYUV8(SkYUVSizeInfo* info, bool FakePaintImageGenerator::QueryYUVA8(SkYUVASizeInfo* info,
SkYUVColorSpace* color_space) const { SkYUVAIndex indices[],
SkYUVColorSpace* color_space) const {
return false; return false;
} }
bool FakePaintImageGenerator::GetYUV8Planes(const SkYUVSizeInfo& info, bool FakePaintImageGenerator::GetYUVA8Planes(const SkYUVASizeInfo& info,
void* planes[3], const SkYUVAIndex indices[],
size_t frame_index, void* planes[4],
uint32_t lazy_pixel_ref) { size_t frame_index,
uint32_t lazy_pixel_ref) {
NOTREACHED(); NOTREACHED();
return false; return false;
} }
......
...@@ -26,12 +26,14 @@ class FakePaintImageGenerator : public PaintImageGenerator { ...@@ -26,12 +26,14 @@ class FakePaintImageGenerator : public PaintImageGenerator {
size_t frame_index, size_t frame_index,
PaintImage::GeneratorClientId client_id, PaintImage::GeneratorClientId client_id,
uint32_t lazy_pixel_ref) override; uint32_t lazy_pixel_ref) override;
bool QueryYUV8(SkYUVSizeInfo* info, bool QueryYUVA8(SkYUVASizeInfo* info,
SkYUVColorSpace* color_space) const override; SkYUVAIndex indices[],
bool GetYUV8Planes(const SkYUVSizeInfo& info, SkYUVColorSpace* color_space) const override;
void* planes[3], bool GetYUVA8Planes(const SkYUVASizeInfo& info,
size_t frame_index, const SkYUVAIndex indices[],
uint32_t lazy_pixel_ref) override; void* planes[4],
size_t frame_index,
uint32_t lazy_pixel_ref) override;
SkISize GetSupportedDecodeSize(const SkISize& requested_size) const override; SkISize GetSupportedDecodeSize(const SkISize& requested_size) const override;
const base::flat_map<size_t, int>& frames_decoded() const { const base::flat_map<size_t, int>& frames_decoded() const {
......
...@@ -336,8 +336,9 @@ class VideoImageGenerator : public cc::PaintImageGenerator { ...@@ -336,8 +336,9 @@ class VideoImageGenerator : public cc::PaintImageGenerator {
return true; return true;
} }
bool QueryYUV8(SkYUVSizeInfo* sizeInfo, bool QueryYUVA8(SkYUVASizeInfo* sizeInfo,
SkYUVColorSpace* color_space) const override { SkYUVAIndex indices[SkYUVAIndex::kIndexCount],
SkYUVColorSpace* color_space) const override {
if (!media::IsYuvPlanar(frame_->format()) || if (!media::IsYuvPlanar(frame_->format()) ||
// TODO(rileya): Skia currently doesn't support YUVA conversion. Remove // TODO(rileya): Skia currently doesn't support YUVA conversion. Remove
// this case once it does. As-is we will fall back on the pure-software // this case once it does. As-is we will fall back on the pure-software
...@@ -363,19 +364,41 @@ class VideoImageGenerator : public cc::PaintImageGenerator { ...@@ -363,19 +364,41 @@ class VideoImageGenerator : public cc::PaintImageGenerator {
sizeInfo->fSizes[plane].set(size.width(), size.height()); sizeInfo->fSizes[plane].set(size.width(), size.height());
sizeInfo->fWidthBytes[plane] = size.width(); sizeInfo->fWidthBytes[plane] = size.width();
} }
sizeInfo->fSizes[VideoFrame::kAPlane] = SkISize::MakeEmpty();
sizeInfo->fWidthBytes[VideoFrame::kAPlane] = 0;
indices[SkYUVAIndex::kY_Index] = {VideoFrame::kYPlane, SkColorChannel::kR};
indices[SkYUVAIndex::kU_Index] = {VideoFrame::kUPlane, SkColorChannel::kR};
indices[SkYUVAIndex::kV_Index] = {VideoFrame::kVPlane, SkColorChannel::kR};
indices[SkYUVAIndex::kA_Index] = {-1, SkColorChannel::kR};
return true; return true;
} }
bool GetYUV8Planes(const SkYUVSizeInfo& sizeInfo, bool GetYUVA8Planes(const SkYUVASizeInfo& sizeInfo,
void* planes[3], const SkYUVAIndex indices[SkYUVAIndex::kIndexCount],
size_t frame_index, void* planes[4],
uint32_t lazy_pixel_ref) override { size_t frame_index,
uint32_t lazy_pixel_ref) override {
DCHECK_EQ(frame_index, 0u); DCHECK_EQ(frame_index, 0u);
media::VideoPixelFormat format = frame_->format(); media::VideoPixelFormat format = frame_->format();
DCHECK(media::IsYuvPlanar(format) && format != PIXEL_FORMAT_I420A); DCHECK(media::IsYuvPlanar(format) && format != PIXEL_FORMAT_I420A);
for (int i = 0; i <= VideoFrame::kVPlane; ++i) {
if (sizeInfo.fSizes[i].isEmpty() || !sizeInfo.fWidthBytes[i]) {
return false;
}
}
if (!sizeInfo.fSizes[VideoFrame::kAPlane].isEmpty() ||
sizeInfo.fWidthBytes[VideoFrame::kAPlane]) {
return false;
}
int numPlanes;
if (!SkYUVAIndex::AreValidIndices(indices, &numPlanes) || numPlanes != 3) {
return false;
}
for (int plane = VideoFrame::kYPlane; plane <= VideoFrame::kVPlane; for (int plane = VideoFrame::kYPlane; plane <= VideoFrame::kVPlane;
++plane) { ++plane) {
const gfx::Size size = const gfx::Size size =
......
...@@ -192,33 +192,57 @@ bool DecodingImageGenerator::GetPixels(const SkImageInfo& dst_info, ...@@ -192,33 +192,57 @@ bool DecodingImageGenerator::GetPixels(const SkImageInfo& dst_info,
return decoded; return decoded;
} }
bool DecodingImageGenerator::QueryYUV8(SkYUVSizeInfo* size_info, bool DecodingImageGenerator::QueryYUVA8(
SkYUVColorSpace* color_space) const { SkYUVASizeInfo* size_info,
SkYUVAIndex indices[SkYUVAIndex::kIndexCount],
SkYUVColorSpace* color_space) const {
// YUV decoding does not currently support progressive decoding. See comment // YUV decoding does not currently support progressive decoding. See comment
// in ImageFrameGenerator.h. // in ImageFrameGenerator.h.
if (!can_yuv_decode_ || !all_data_received_) if (!can_yuv_decode_ || !all_data_received_)
return false; return false;
TRACE_EVENT0("blink", "DecodingImageGenerator::queryYUV8"); TRACE_EVENT0("blink", "DecodingImageGenerator::queryYUVA8");
if (color_space) if (color_space)
*color_space = kJPEG_SkYUVColorSpace; *color_space = kJPEG_SkYUVColorSpace;
// Indicate that we have three separate planes
indices[SkYUVAIndex::kY_Index] = {0, SkColorChannel::kR};
indices[SkYUVAIndex::kU_Index] = {1, SkColorChannel::kR};
indices[SkYUVAIndex::kV_Index] = {2, SkColorChannel::kR};
indices[SkYUVAIndex::kA_Index] = {-1, SkColorChannel::kR};
return frame_generator_->GetYUVComponentSizes(data_.get(), size_info); return frame_generator_->GetYUVComponentSizes(data_.get(), size_info);
} }
bool DecodingImageGenerator::GetYUV8Planes(const SkYUVSizeInfo& size_info, bool DecodingImageGenerator::GetYUVA8Planes(const SkYUVASizeInfo& size_info,
void* planes[3], const SkYUVAIndex indices[4],
size_t frame_index, void* planes[3],
uint32_t lazy_pixel_ref) { size_t frame_index,
uint32_t lazy_pixel_ref) {
// YUV decoding does not currently support progressive decoding. See comment // YUV decoding does not currently support progressive decoding. See comment
// in ImageFrameGenerator.h. // in ImageFrameGenerator.h.
DCHECK(can_yuv_decode_); DCHECK(can_yuv_decode_);
DCHECK(all_data_received_); DCHECK(all_data_received_);
TRACE_EVENT0("blink", "DecodingImageGenerator::getYUV8Planes"); TRACE_EVENT0("blink", "DecodingImageGenerator::getYUVA8Planes");
TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"),
"Decode LazyPixelRef", "LazyPixelRef", lazy_pixel_ref); "Decode LazyPixelRef", "LazyPixelRef", lazy_pixel_ref);
// Verify sizes and indices
for (int i = 0; i < 3; ++i) {
if (size_info.fSizes[i].isEmpty() || !size_info.fWidthBytes[i]) {
return false;
}
}
if (!size_info.fSizes[3].isEmpty() || size_info.fWidthBytes[3]) {
return false;
}
int numPlanes;
if (!SkYUVAIndex::AreValidIndices(indices, &numPlanes) || numPlanes != 3) {
return false;
}
bool decoded = bool decoded =
frame_generator_->DecodeToYUV(data_.get(), frame_index, size_info.fSizes, frame_generator_->DecodeToYUV(data_.get(), frame_index, size_info.fSizes,
planes, size_info.fWidthBytes); planes, size_info.fWidthBytes);
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "third_party/blink/renderer/platform/platform_export.h" #include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/allocator.h" #include "third_party/blink/renderer/platform/wtf/allocator.h"
#include "third_party/skia/include/core/SkImageInfo.h" #include "third_party/skia/include/core/SkImageInfo.h"
#include "third_party/skia/include/core/SkYUVAIndex.h"
class SkData; class SkData;
...@@ -74,11 +75,14 @@ class PLATFORM_EXPORT DecodingImageGenerator final ...@@ -74,11 +75,14 @@ class PLATFORM_EXPORT DecodingImageGenerator final
size_t frame_index, size_t frame_index,
PaintImage::GeneratorClientId client_id, PaintImage::GeneratorClientId client_id,
uint32_t lazy_pixel_ref) override; uint32_t lazy_pixel_ref) override;
bool QueryYUV8(SkYUVSizeInfo*, SkYUVColorSpace*) const override; bool QueryYUVA8(SkYUVASizeInfo*,
bool GetYUV8Planes(const SkYUVSizeInfo&, SkYUVAIndex[SkYUVAIndex::kIndexCount],
void* planes[3], SkYUVColorSpace*) const override;
size_t frame_index, bool GetYUVA8Planes(const SkYUVASizeInfo&,
uint32_t lazy_pixel_ref) override; const SkYUVAIndex[SkYUVAIndex::kIndexCount],
void* planes[4],
size_t frame_index,
uint32_t lazy_pixel_ref) override;
SkISize GetSupportedDecodeSize(const SkISize& requested_size) const override; SkISize GetSupportedDecodeSize(const SkISize& requested_size) const override;
PaintImage::ContentId GetContentIdForFrame(size_t frame_index) const override; PaintImage::ContentId GetContentIdForFrame(size_t frame_index) const override;
......
...@@ -34,13 +34,13 @@ ...@@ -34,13 +34,13 @@
#include "third_party/blink/renderer/platform/graphics/image_decoding_store.h" #include "third_party/blink/renderer/platform/graphics/image_decoding_store.h"
#include "third_party/blink/renderer/platform/image-decoders/image_decoder.h" #include "third_party/blink/renderer/platform/image-decoders/image_decoder.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h" #include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h"
#include "third_party/skia/include/core/SkYUVSizeInfo.h" #include "third_party/skia/include/core/SkYUVASizeInfo.h"
namespace blink { namespace blink {
static bool UpdateYUVComponentSizes(ImageDecoder* decoder, static bool UpdateYUVComponentSizes(ImageDecoder* decoder,
SkISize component_sizes[3], SkISize component_sizes[4],
size_t component_width_bytes[3]) { size_t component_width_bytes[4]) {
if (!decoder->CanDecodeToYUV()) if (!decoder->CanDecodeToYUV())
return false; return false;
...@@ -49,6 +49,8 @@ static bool UpdateYUVComponentSizes(ImageDecoder* decoder, ...@@ -49,6 +49,8 @@ static bool UpdateYUVComponentSizes(ImageDecoder* decoder,
component_sizes[yuv_index].set(size.Width(), size.Height()); component_sizes[yuv_index].set(size.Width(), size.Height());
component_width_bytes[yuv_index] = decoder->DecodedYUVWidthBytes(yuv_index); component_width_bytes[yuv_index] = decoder->DecodedYUVWidthBytes(yuv_index);
} }
component_sizes[3] = SkISize::MakeEmpty();
component_width_bytes[3] = 0;
return true; return true;
} }
...@@ -209,7 +211,7 @@ bool ImageFrameGenerator::HasAlpha(size_t index) { ...@@ -209,7 +211,7 @@ bool ImageFrameGenerator::HasAlpha(size_t index) {
} }
bool ImageFrameGenerator::GetYUVComponentSizes(SegmentReader* data, bool ImageFrameGenerator::GetYUVComponentSizes(SegmentReader* data,
SkYUVSizeInfo* size_info) { SkYUVASizeInfo* size_info) {
TRACE_EVENT2("blink", "ImageFrameGenerator::getYUVComponentSizes", "width", TRACE_EVENT2("blink", "ImageFrameGenerator::getYUVComponentSizes", "width",
full_size_.width(), "height", full_size_.height()); full_size_.width(), "height", full_size_.height());
......
...@@ -42,8 +42,7 @@ ...@@ -42,8 +42,7 @@
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkSize.h" #include "third_party/skia/include/core/SkSize.h"
#include "third_party/skia/include/core/SkTypes.h" #include "third_party/skia/include/core/SkTypes.h"
#include "third_party/skia/include/core/SkYUVASizeInfo.h"
struct SkYUVSizeInfo;
namespace blink { namespace blink {
...@@ -112,7 +111,7 @@ class PLATFORM_EXPORT ImageFrameGenerator final ...@@ -112,7 +111,7 @@ class PLATFORM_EXPORT ImageFrameGenerator final
// Must not be called unless the SkROBuffer has all the data. YUV decoding // Must not be called unless the SkROBuffer has all the data. YUV decoding
// does not currently support progressive decoding. See comment above on // does not currently support progressive decoding. See comment above on
// decodeToYUV(). // decodeToYUV().
bool GetYUVComponentSizes(SegmentReader*, SkYUVSizeInfo*); bool GetYUVComponentSizes(SegmentReader*, SkYUVASizeInfo*);
private: private:
class ClientMutexLocker { class ClientMutexLocker {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment