Add SkSurfaceProps parameter to several APIs

In general, SkSurfaceProps is only needed when rendering text.  However,
there are several existing APIs that don't allow SkSurfaceProps to be
passed in by the user.

This change adds new SkSurfaceProps parameters to several public-facing
APIs:
  1. SkRasterHandleAllocator::MakeCanvas
  -- The props are used by the canvas whenever text is rendered.

  2. SkImage::MakeFromPicture and SkImageGenerator::MakeFromPicture
  -- The props are used to render any text in the SkPicture object.

Change-Id: Ic48e8a30bb12b3170415c644de1a007b5eefb818
Bug: skia:13369
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/545396
Reviewed-by: Ben Wagner <bungeman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
Ian Prest 2022-06-01 14:06:10 -07:00 committed by SkCQ
parent 455addeff6
commit 18fdfe83a5
8 changed files with 36 additions and 21 deletions

View File

@ -5,6 +5,9 @@ This file includes a list of high level updates for each milestone release.
Milestone 104
-------------
* SkRuntimeEffect takes and returns a const SkData.
* SkRasterHandleAllocator::MakeCanvas now takes optional SkSurfaceProps.
* SkImage::MakeFromPicture and SkImageGenerator::MakeFromPicture now take an optional
SkSurfaceProps to use when rasterizing the picture.
* * *

View File

@ -2418,7 +2418,7 @@ protected:
SkCanvas(const SkIRect& bounds);
private:
SkCanvas(const SkBitmap&, std::unique_ptr<SkRasterHandleAllocator>,
SkRasterHandleAllocator::Handle);
SkRasterHandleAllocator::Handle, const SkSurfaceProps* props);
SkCanvas(SkCanvas&&) = delete;
SkCanvas(const SkCanvas&) = delete;

View File

@ -13,6 +13,7 @@
#include "include/core/SkSamplingOptions.h"
#include "include/core/SkScalar.h"
#include "include/core/SkShader.h"
#include "include/core/SkSurfaceProps.h"
#include "include/core/SkTileMode.h"
#if SK_SUPPORT_GPU
#include "include/gpu/GrTypes.h"
@ -253,12 +254,13 @@ public:
@param paint SkPaint to apply transparency, filtering, and so on; may be nullptr
@param bitDepth 8-bit integer or 16-bit float: per component
@param colorSpace range of colors; may be nullptr
@param props props to use when rasterizing the picture
@return created SkImage, or nullptr
*/
static sk_sp<SkImage> MakeFromPicture(sk_sp<SkPicture> picture, const SkISize& dimensions,
const SkMatrix* matrix, const SkPaint* paint,
BitDepth bitDepth,
sk_sp<SkColorSpace> colorSpace);
BitDepth bitDepth, sk_sp<SkColorSpace> colorSpace,
SkSurfaceProps props = {});
#if SK_SUPPORT_GPU
/** Creates a GPU-backed SkImage from compressed data.

View File

@ -12,6 +12,7 @@
#include "include/core/SkColor.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkSurfaceProps.h"
#include "include/core/SkYUVAPixmaps.h"
#include <optional>
@ -169,7 +170,8 @@ public:
static std::unique_ptr<SkImageGenerator> MakeFromPicture(const SkISize&, sk_sp<SkPicture>,
const SkMatrix*, const SkPaint*,
SkImage::BitDepth,
sk_sp<SkColorSpace>);
sk_sp<SkColorSpace>,
SkSurfaceProps props = {});
protected:
static constexpr int kNeedNewImageUniqueID = 0;

View File

@ -13,6 +13,7 @@
class SkBitmap;
class SkCanvas;
class SkMatrix;
class SkSurfaceProps;
/**
* If a client wants to control the allocation of raster layers in a canvas, it should subclass
@ -76,7 +77,8 @@ public:
* If rec is null, then the allocator will be called for the base-layer as well.
*/
static std::unique_ptr<SkCanvas> MakeCanvas(std::unique_ptr<SkRasterHandleAllocator>,
const SkImageInfo&, const Rec* rec = nullptr);
const SkImageInfo&, const Rec* rec = nullptr,
const SkSurfaceProps* props = nullptr);
protected:
SkRasterHandleAllocator() = default;

View File

@ -465,8 +465,10 @@ SkCanvas::SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props)
SkCanvas::SkCanvas(const SkBitmap& bitmap,
std::unique_ptr<SkRasterHandleAllocator> alloc,
SkRasterHandleAllocator::Handle hndl)
SkRasterHandleAllocator::Handle hndl,
const SkSurfaceProps* props)
: fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
, fProps(SkSurfacePropsCopyOrDefault(props))
, fAllocator(std::move(alloc)) {
inc_canvas();
@ -474,7 +476,7 @@ SkCanvas::SkCanvas(const SkBitmap& bitmap,
this->init(device);
}
SkCanvas::SkCanvas(const SkBitmap& bitmap) : SkCanvas(bitmap, nullptr, nullptr) {}
SkCanvas::SkCanvas(const SkBitmap& bitmap) : SkCanvas(bitmap, nullptr, nullptr, nullptr) {}
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
SkCanvas::SkCanvas(const SkBitmap& bitmap, ColorBehavior)
@ -2868,7 +2870,8 @@ SkRasterHandleAllocator::Handle SkRasterHandleAllocator::allocBitmap(const SkIma
std::unique_ptr<SkCanvas>
SkRasterHandleAllocator::MakeCanvas(std::unique_ptr<SkRasterHandleAllocator> alloc,
const SkImageInfo& info, const Rec* rec) {
const SkImageInfo& info, const Rec* rec,
const SkSurfaceProps* props) {
if (!alloc || !SkSurfaceValidateRasterInfo(info, rec ? rec->fRowBytes : kIgnoreRowBytesValue)) {
return nullptr;
}
@ -2881,7 +2884,8 @@ SkRasterHandleAllocator::MakeCanvas(std::unique_ptr<SkRasterHandleAllocator> all
} else {
hndl = alloc->allocBitmap(info, &bm);
}
return hndl ? std::unique_ptr<SkCanvas>(new SkCanvas(bm, std::move(alloc), hndl)) : nullptr;
return hndl ? std::unique_ptr<SkCanvas>(new SkCanvas(bm, std::move(alloc), hndl, props))
: nullptr;
}
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -18,7 +18,7 @@
class SkPictureImageGenerator : public SkImageGenerator {
public:
SkPictureImageGenerator(const SkImageInfo& info, sk_sp<SkPicture>, const SkMatrix*,
const SkPaint*);
const SkPaint*, const SkSurfaceProps& props);
protected:
bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, const Options& opts)
@ -33,6 +33,7 @@ private:
sk_sp<SkPicture> fPicture;
SkMatrix fMatrix;
SkTLazy<SkPaint> fPaint;
SkSurfaceProps fProps;
using INHERITED = SkImageGenerator;
};
@ -42,7 +43,8 @@ private:
std::unique_ptr<SkImageGenerator>
SkImageGenerator::MakeFromPicture(const SkISize& size, sk_sp<SkPicture> picture,
const SkMatrix* matrix, const SkPaint* paint,
SkImage::BitDepth bitDepth, sk_sp<SkColorSpace> colorSpace) {
SkImage::BitDepth bitDepth, sk_sp<SkColorSpace> colorSpace,
SkSurfaceProps props) {
if (!picture || !colorSpace || size.isEmpty()) {
return nullptr;
}
@ -55,15 +57,17 @@ SkImageGenerator::MakeFromPicture(const SkISize& size, sk_sp<SkPicture> picture,
SkImageInfo info =
SkImageInfo::Make(size, colorType, kPremul_SkAlphaType, std::move(colorSpace));
return std::unique_ptr<SkImageGenerator>(
new SkPictureImageGenerator(info, std::move(picture), matrix, paint));
new SkPictureImageGenerator(info, std::move(picture), matrix, paint, props));
}
///////////////////////////////////////////////////////////////////////////////////////////////////
SkPictureImageGenerator::SkPictureImageGenerator(const SkImageInfo& info, sk_sp<SkPicture> picture,
const SkMatrix* matrix, const SkPaint* paint)
const SkMatrix* matrix, const SkPaint* paint,
const SkSurfaceProps& props)
: INHERITED(info)
, fPicture(std::move(picture)) {
, fPicture(std::move(picture))
, fProps(props) {
if (matrix) {
fMatrix = *matrix;
@ -78,8 +82,7 @@ SkPictureImageGenerator::SkPictureImageGenerator(const SkImageInfo& info, sk_sp<
bool SkPictureImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
const Options& opts) {
SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
std::unique_ptr<SkCanvas> canvas = SkCanvas::MakeRasterDirect(info, pixels, rowBytes, &props);
std::unique_ptr<SkCanvas> canvas = SkCanvas::MakeRasterDirect(info, pixels, rowBytes, &fProps);
if (!canvas) {
return false;
}
@ -102,13 +105,11 @@ GrSurfaceProxyView SkPictureImageGenerator::onGenerateTexture(GrRecordingContext
GrImageTexGenPolicy texGenPolicy) {
SkASSERT(ctx);
SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
SkBudgeted budgeted = texGenPolicy == GrImageTexGenPolicy::kNew_Uncached_Unbudgeted
? SkBudgeted::kNo
: SkBudgeted::kYes;
auto surface = SkSurface::MakeRenderTarget(ctx, budgeted, info, 0, kTopLeft_GrSurfaceOrigin,
&props, mipmapped == GrMipmapped::kYes);
&fProps, mipmapped == GrMipmapped::kYes);
if (!surface) {
return {};
}

View File

@ -536,10 +536,11 @@ bool SkImage_Base::onAsLegacyBitmap(GrDirectContext* dContext, SkBitmap* bitmap)
sk_sp<SkImage> SkImage::MakeFromPicture(sk_sp<SkPicture> picture, const SkISize& dimensions,
const SkMatrix* matrix, const SkPaint* paint,
BitDepth bitDepth, sk_sp<SkColorSpace> colorSpace) {
BitDepth bitDepth, sk_sp<SkColorSpace> colorSpace,
SkSurfaceProps props) {
return MakeFromGenerator(SkImageGenerator::MakeFromPicture(dimensions, std::move(picture),
matrix, paint, bitDepth,
std::move(colorSpace)));
std::move(colorSpace), props));
}
sk_sp<SkImage> SkImage::makeWithFilter(GrRecordingContext* rContext, const SkImageFilter* filter,