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 @@
#include "third_party/skia/include/core/SkData.h"
#include "third_party/skia/include/core/SkImageInfo.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 {
......@@ -44,21 +45,25 @@ class CC_PAINT_EXPORT PaintImageGenerator : public SkRefCnt {
// Returns true if the generator supports YUV decoding, providing the output
// information in |info| and |color_space|.
virtual bool QueryYUV8(SkYUVSizeInfo* info,
SkYUVColorSpace* color_space) const = 0;
virtual bool QueryYUVA8(SkYUVASizeInfo* info,
SkYUVAIndex indices[SkYUVAIndex::kIndexCount],
SkYUVColorSpace* color_space) const = 0;
// 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
// QueryYUV8 returns true.
// |info| needs to exactly match the values returned by the query, except the
// WidthBytes may be larger than the recommendation (but not smaller).
// QueryYUVA8 returns true.
// |info| and |indices| need to exactly match the values returned by the
// query, except the info.fWidthBytes may be larger than the recommendation
// (but not smaller).
//
// TODO(khushalsagar): |lazy_pixel_ref| is only present for
// DecodingImageGenerator tracing needs. Remove it.
virtual bool GetYUV8Planes(const SkYUVSizeInfo& info,
void* planes[3],
size_t frame_index,
uint32_t lazy_pixel_ref) = 0;
virtual bool GetYUVA8Planes(
const SkYUVASizeInfo& info,
const SkYUVAIndex indices[SkYUVAIndex::kIndexCount],
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,
// such that we can decode to exactly that scale.
......
......@@ -31,15 +31,19 @@ bool SkiaPaintImageGenerator::onGetPixels(const SkImageInfo& info,
info, pixels, row_bytes, frame_index_, client_id_, uniqueID());
}
bool SkiaPaintImageGenerator::onQueryYUV8(SkYUVSizeInfo* size_info,
SkYUVColorSpace* color_space) const {
return paint_image_generator_->QueryYUV8(size_info, color_space);
bool SkiaPaintImageGenerator::onQueryYUVA8(
SkYUVASizeInfo* size_info,
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,
void* planes[3]) {
return paint_image_generator_->GetYUV8Planes(size_info, planes, frame_index_,
uniqueID());
bool SkiaPaintImageGenerator::onGetYUVA8Planes(
const SkYUVASizeInfo& size_info,
const SkYUVAIndex indices[SkYUVAIndex::kIndexCount],
void* planes[4]) {
return paint_image_generator_->GetYUVA8Planes(size_info, indices, planes,
frame_index_, uniqueID());
}
} // namespace cc
......@@ -25,10 +25,12 @@ class CC_PAINT_EXPORT SkiaPaintImageGenerator final : public SkImageGenerator {
void* pixels,
size_t row_bytes,
const Options& options) override;
bool onQueryYUV8(SkYUVSizeInfo* size_info,
SkYUVColorSpace* color_space) const override;
bool onGetYUV8Planes(const SkYUVSizeInfo& size_info,
void* planes[3]) override;
bool onQueryYUVA8(SkYUVASizeInfo* size_info,
SkYUVAIndex indices[SkYUVAIndex::kIndexCount],
SkYUVColorSpace* color_space) const override;
bool onGetYUVA8Planes(const SkYUVASizeInfo& size_info,
const SkYUVAIndex indices[SkYUVAIndex::kIndexCount],
void* planes[3]) override;
private:
sk_sp<PaintImageGenerator> paint_image_generator_;
......
......@@ -42,15 +42,17 @@ bool FakePaintImageGenerator::GetPixels(const SkImageInfo& info,
return true;
}
bool FakePaintImageGenerator::QueryYUV8(SkYUVSizeInfo* info,
SkYUVColorSpace* color_space) const {
bool FakePaintImageGenerator::QueryYUVA8(SkYUVASizeInfo* info,
SkYUVAIndex indices[],
SkYUVColorSpace* color_space) const {
return false;
}
bool FakePaintImageGenerator::GetYUV8Planes(const SkYUVSizeInfo& info,
void* planes[3],
size_t frame_index,
uint32_t lazy_pixel_ref) {
bool FakePaintImageGenerator::GetYUVA8Planes(const SkYUVASizeInfo& info,
const SkYUVAIndex indices[],
void* planes[4],
size_t frame_index,
uint32_t lazy_pixel_ref) {
NOTREACHED();
return false;
}
......
......@@ -26,12 +26,14 @@ class FakePaintImageGenerator : public PaintImageGenerator {
size_t frame_index,
PaintImage::GeneratorClientId client_id,
uint32_t lazy_pixel_ref) override;
bool QueryYUV8(SkYUVSizeInfo* info,
SkYUVColorSpace* color_space) const override;
bool GetYUV8Planes(const SkYUVSizeInfo& info,
void* planes[3],
size_t frame_index,
uint32_t lazy_pixel_ref) override;
bool QueryYUVA8(SkYUVASizeInfo* info,
SkYUVAIndex indices[],
SkYUVColorSpace* color_space) const override;
bool GetYUVA8Planes(const SkYUVASizeInfo& info,
const SkYUVAIndex indices[],
void* planes[4],
size_t frame_index,
uint32_t lazy_pixel_ref) override;
SkISize GetSupportedDecodeSize(const SkISize& requested_size) const override;
const base::flat_map<size_t, int>& frames_decoded() const {
......
......@@ -336,8 +336,9 @@ class VideoImageGenerator : public cc::PaintImageGenerator {
return true;
}
bool QueryYUV8(SkYUVSizeInfo* sizeInfo,
SkYUVColorSpace* color_space) const override {
bool QueryYUVA8(SkYUVASizeInfo* sizeInfo,
SkYUVAIndex indices[SkYUVAIndex::kIndexCount],
SkYUVColorSpace* color_space) const override {
if (!media::IsYuvPlanar(frame_->format()) ||
// 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
......@@ -363,19 +364,41 @@ class VideoImageGenerator : public cc::PaintImageGenerator {
sizeInfo->fSizes[plane].set(size.width(), size.height());
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;
}
bool GetYUV8Planes(const SkYUVSizeInfo& sizeInfo,
void* planes[3],
size_t frame_index,
uint32_t lazy_pixel_ref) override {
bool GetYUVA8Planes(const SkYUVASizeInfo& sizeInfo,
const SkYUVAIndex indices[SkYUVAIndex::kIndexCount],
void* planes[4],
size_t frame_index,
uint32_t lazy_pixel_ref) override {
DCHECK_EQ(frame_index, 0u);
media::VideoPixelFormat format = frame_->format();
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;
++plane) {
const gfx::Size size =
......
......@@ -192,33 +192,57 @@ bool DecodingImageGenerator::GetPixels(const SkImageInfo& dst_info,
return decoded;
}
bool DecodingImageGenerator::QueryYUV8(SkYUVSizeInfo* size_info,
SkYUVColorSpace* color_space) const {
bool DecodingImageGenerator::QueryYUVA8(
SkYUVASizeInfo* size_info,
SkYUVAIndex indices[SkYUVAIndex::kIndexCount],
SkYUVColorSpace* color_space) const {
// YUV decoding does not currently support progressive decoding. See comment
// in ImageFrameGenerator.h.
if (!can_yuv_decode_ || !all_data_received_)
return false;
TRACE_EVENT0("blink", "DecodingImageGenerator::queryYUV8");
TRACE_EVENT0("blink", "DecodingImageGenerator::queryYUVA8");
if (color_space)
*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);
}
bool DecodingImageGenerator::GetYUV8Planes(const SkYUVSizeInfo& size_info,
void* planes[3],
size_t frame_index,
uint32_t lazy_pixel_ref) {
bool DecodingImageGenerator::GetYUVA8Planes(const SkYUVASizeInfo& size_info,
const SkYUVAIndex indices[4],
void* planes[3],
size_t frame_index,
uint32_t lazy_pixel_ref) {
// YUV decoding does not currently support progressive decoding. See comment
// in ImageFrameGenerator.h.
DCHECK(can_yuv_decode_);
DCHECK(all_data_received_);
TRACE_EVENT0("blink", "DecodingImageGenerator::getYUV8Planes");
TRACE_EVENT0("blink", "DecodingImageGenerator::getYUVA8Planes");
TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"),
"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 =
frame_generator_->DecodeToYUV(data_.get(), frame_index, size_info.fSizes,
planes, size_info.fWidthBytes);
......
......@@ -33,6 +33,7 @@
#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/allocator.h"
#include "third_party/skia/include/core/SkImageInfo.h"
#include "third_party/skia/include/core/SkYUVAIndex.h"
class SkData;
......@@ -74,11 +75,14 @@ class PLATFORM_EXPORT DecodingImageGenerator final
size_t frame_index,
PaintImage::GeneratorClientId client_id,
uint32_t lazy_pixel_ref) override;
bool QueryYUV8(SkYUVSizeInfo*, SkYUVColorSpace*) const override;
bool GetYUV8Planes(const SkYUVSizeInfo&,
void* planes[3],
size_t frame_index,
uint32_t lazy_pixel_ref) override;
bool QueryYUVA8(SkYUVASizeInfo*,
SkYUVAIndex[SkYUVAIndex::kIndexCount],
SkYUVColorSpace*) const override;
bool GetYUVA8Planes(const SkYUVASizeInfo&,
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;
PaintImage::ContentId GetContentIdForFrame(size_t frame_index) const override;
......
......@@ -34,13 +34,13 @@
#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/instrumentation/tracing/trace_event.h"
#include "third_party/skia/include/core/SkYUVSizeInfo.h"
#include "third_party/skia/include/core/SkYUVASizeInfo.h"
namespace blink {
static bool UpdateYUVComponentSizes(ImageDecoder* decoder,
SkISize component_sizes[3],
size_t component_width_bytes[3]) {
SkISize component_sizes[4],
size_t component_width_bytes[4]) {
if (!decoder->CanDecodeToYUV())
return false;
......@@ -49,6 +49,8 @@ static bool UpdateYUVComponentSizes(ImageDecoder* decoder,
component_sizes[yuv_index].set(size.Width(), size.Height());
component_width_bytes[yuv_index] = decoder->DecodedYUVWidthBytes(yuv_index);
}
component_sizes[3] = SkISize::MakeEmpty();
component_width_bytes[3] = 0;
return true;
}
......@@ -209,7 +211,7 @@ bool ImageFrameGenerator::HasAlpha(size_t index) {
}
bool ImageFrameGenerator::GetYUVComponentSizes(SegmentReader* data,
SkYUVSizeInfo* size_info) {
SkYUVASizeInfo* size_info) {
TRACE_EVENT2("blink", "ImageFrameGenerator::getYUVComponentSizes", "width",
full_size_.width(), "height", full_size_.height());
......
......@@ -42,8 +42,7 @@
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkSize.h"
#include "third_party/skia/include/core/SkTypes.h"
struct SkYUVSizeInfo;
#include "third_party/skia/include/core/SkYUVASizeInfo.h"
namespace blink {
......@@ -112,7 +111,7 @@ class PLATFORM_EXPORT ImageFrameGenerator final
// Must not be called unless the SkROBuffer has all the data. YUV decoding
// does not currently support progressive decoding. See comment above on
// decodeToYUV().
bool GetYUVComponentSizes(SegmentReader*, SkYUVSizeInfo*);
bool GetYUVComponentSizes(SegmentReader*, SkYUVASizeInfo*);
private:
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