Remove SkColorSpaceXformCanvas, use color-managed SkSurfaces instead (flutter/engine#7548)

Behavior (visual) changes should be very minor. Things that are to be expected:
* A few things were not color managed correctly by the transform canvas (color emoji, some color filters). Those will be handled correctly with the tagged surfaces (although we're always transforming to sRGB, so nothing should change until we target a wider gamut).
* Image filtering will happen in the source color space, rather than the destination. Very minor.
* The transform canvas did caching of images in the destination color space. Now, the conversion happens at draw time. If there are performance issues, images can be pre-converted to the destination with makeColorSpace().
This commit is contained in:
Brian Osman
2019-01-22 15:34:51 -05:00
committed by GitHub
parent 01da26e047
commit 3dd1198f0d
10 changed files with 23 additions and 36 deletions

View File

@@ -11,7 +11,6 @@
#include "flutter/fml/logging.h"
#include "flutter/fml/trace_event.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkColorSpaceXformCanvas.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkPicture.h"
#include "third_party/skia/include/core/SkSurface.h"
@@ -97,8 +96,8 @@ static RasterCacheResult Rasterize(
std::function<void(SkCanvas*)> draw_function) {
SkIRect cache_rect = RasterCache::GetDeviceBounds(logical_rect, ctm);
const SkImageInfo image_info =
SkImageInfo::MakeN32Premul(cache_rect.width(), cache_rect.height());
const SkImageInfo image_info = SkImageInfo::MakeN32Premul(
cache_rect.width(), cache_rect.height(), sk_ref_sp(dst_color_space));
sk_sp<SkSurface> surface =
context
@@ -110,15 +109,6 @@ static RasterCacheResult Rasterize(
}
SkCanvas* canvas = surface->getCanvas();
std::unique_ptr<SkCanvas> xformCanvas;
if (dst_color_space) {
xformCanvas = SkCreateColorSpaceXformCanvas(surface->getCanvas(),
sk_ref_sp(dst_color_space));
if (xformCanvas) {
canvas = xformCanvas.get();
}
}
canvas->clear(SK_ColorTRANSPARENT);
canvas->translate(-cache_rect.left(), -cache_rect.top());
canvas->concat(ctm);

View File

@@ -98,10 +98,12 @@ sk_sp<SkImage> Rasterizer::MakeRasterSnapshot(sk_sp<SkPicture> picture,
TRACE_EVENT0("flutter", __FUNCTION__);
sk_sp<SkSurface> surface;
SkImageInfo image_info = SkImageInfo::MakeN32Premul(
picture_size.width(), picture_size.height(), SkColorSpace::MakeSRGB());
if (surface_ == nullptr || surface_->GetContext() == nullptr) {
// Raster surface is fine if there is no on screen surface. This might
// happen in case of software rendering.
surface = SkSurface::MakeRaster(SkImageInfo::MakeN32Premul(picture_size));
surface = SkSurface::MakeRaster(image_info);
} else {
if (!surface_->MakeRenderContextCurrent()) {
return nullptr;
@@ -109,10 +111,9 @@ sk_sp<SkImage> Rasterizer::MakeRasterSnapshot(sk_sp<SkPicture> picture,
// When there is an on screen surface, we need a render target SkSurface
// because we want to access texture backed images.
surface = SkSurface::MakeRenderTarget(
surface_->GetContext(), // context
SkBudgeted::kNo, // budgeted
SkImageInfo::MakeN32Premul(picture_size) // image info
surface = SkSurface::MakeRenderTarget(surface_->GetContext(), // context
SkBudgeted::kNo, // budgeted
image_info // image info
);
}
@@ -231,7 +232,8 @@ static sk_sp<SkData> ScreenshotLayerTreeAsPicture(
static sk_sp<SkSurface> CreateSnapshotSurface(GrContext* surface_context,
const SkISize& size) {
const auto image_info = SkImageInfo::MakeN32Premul(size);
const auto image_info = SkImageInfo::MakeN32Premul(
size.width(), size.height(), SkColorSpace::MakeSRGB());
if (surface_context) {
// There is a rendering surface that may contain textures that are going to
// be referenced in the layer tree about to be drawn.

View File

@@ -39,7 +39,9 @@ class TestPlatformView : public PlatformView,
// |GPUSurfaceSoftwareDelegate|
virtual sk_sp<SkSurface> AcquireBackingStore(const SkISize& size) override {
return SkSurface::MakeRasterN32Premul(size.width(), size.height());
SkImageInfo image_info = SkImageInfo::MakeN32Premul(
size.width(), size.height(), SkColorSpace::MakeSRGB());
return SkSurface::MakeRaster(image_info);
}
// |GPUSurfaceSoftwareDelegate|

View File

@@ -5,7 +5,6 @@
#include "flutter/shell/common/surface.h"
#include "flutter/fml/logging.h"
#include "third_party/skia/include/core/SkColorSpaceXformCanvas.h"
#include "third_party/skia/include/core/SkSurface.h"
namespace shell {
@@ -14,10 +13,6 @@ SurfaceFrame::SurfaceFrame(sk_sp<SkSurface> surface,
SubmitCallback submit_callback)
: submitted_(false), surface_(surface), submit_callback_(submit_callback) {
FML_DCHECK(submit_callback_);
if (surface_) {
xform_canvas_ = SkCreateColorSpaceXformCanvas(surface_->getCanvas(),
SkColorSpace::MakeSRGB());
}
}
SurfaceFrame::~SurfaceFrame() {
@@ -38,9 +33,6 @@ bool SurfaceFrame::Submit() {
}
SkCanvas* SurfaceFrame::SkiaCanvas() {
if (xform_canvas_) {
return xform_canvas_.get();
}
return surface_ != nullptr ? surface_->getCanvas() : nullptr;
}

View File

@@ -34,7 +34,6 @@ class SurfaceFrame {
private:
bool submitted_;
sk_sp<SkSurface> surface_;
std::unique_ptr<SkCanvas> xform_canvas_;
SubmitCallback submit_callback_;
bool PerformSubmit();

View File

@@ -182,7 +182,7 @@ static sk_sp<SkSurface> WrapOnscreenSurface(GrContext* context,
framebuffer_info // framebuffer info
);
sk_sp<SkColorSpace> colorspace = nullptr;
sk_sp<SkColorSpace> colorspace = SkColorSpace::MakeSRGB();
SkSurfaceProps surface_props(
SkSurfaceProps::InitType::kLegacyFontHost_InitType);
@@ -199,8 +199,8 @@ static sk_sp<SkSurface> WrapOnscreenSurface(GrContext* context,
static sk_sp<SkSurface> CreateOffscreenSurface(GrContext* context,
const SkISize& size) {
const SkImageInfo image_info =
SkImageInfo::MakeN32(size.fWidth, size.fHeight, kOpaque_SkAlphaType);
const SkImageInfo image_info = SkImageInfo::MakeN32(
size.fWidth, size.fHeight, kOpaque_SkAlphaType, SkColorSpace::MakeSRGB());
const SkSurfaceProps surface_props(
SkSurfaceProps::InitType::kLegacyFontHost_InitType);

View File

@@ -83,8 +83,9 @@ sk_sp<SkSurface> AndroidSurfaceSoftware::AcquireBackingStore(
return sk_surface_;
}
SkImageInfo image_info = SkImageInfo::Make(
size.fWidth, size.fHeight, target_color_type_, target_alpha_type_);
SkImageInfo image_info =
SkImageInfo::Make(size.fWidth, size.fHeight, target_color_type_,
target_alpha_type_, SkColorSpace::MakeSRGB());
sk_surface_ = SkSurface::MakeRaster(image_info);

View File

@@ -64,7 +64,8 @@ sk_sp<SkSurface> IOSSurfaceSoftware::AcquireBackingStore(const SkISize& size) {
return sk_surface_;
}
SkImageInfo info = SkImageInfo::MakeN32(size.fWidth, size.fHeight, kPremul_SkAlphaType);
SkImageInfo info = SkImageInfo::MakeN32(size.fWidth, size.fHeight, kPremul_SkAlphaType,
SkColorSpace::MakeSRGB());
sk_surface_ = SkSurface::MakeRaster(info, nullptr);
return sk_surface_;
}

View File

@@ -61,8 +61,8 @@ sk_sp<SkSurface> EmbedderSurfaceSoftware::AcquireBackingStore(
return sk_surface_;
}
SkImageInfo info =
SkImageInfo::MakeN32(size.fWidth, size.fHeight, kPremul_SkAlphaType);
SkImageInfo info = SkImageInfo::MakeN32(
size.fWidth, size.fHeight, kPremul_SkAlphaType, SkColorSpace::MakeSRGB());
sk_surface_ = SkSurface::MakeRaster(info, nullptr);
if (sk_surface_ == nullptr) {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 112 B

After

Width:  |  Height:  |  Size: 125 B