Skip to content

Commit

Permalink
Migrate uses of SkSurface factories (flutter#41978)
Browse files Browse the repository at this point in the history
In http://review.skia.org/687639, many SkSurface static methods were moved and one was deleted (SkSurface::MakeRasterN32Premul). (SkSurface::MakeNull was omitted accidentally and http://review.skia.org/696537glesource.com/c/skia/+/696537 has not rolled into Flutter yet)

This changes the calls in Flutter to match those moved functions. There should be no functional difference and everything was done pretty mechanically (e.g. find and replace)

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
  • Loading branch information
kjlubick authored May 15, 2023
1 parent f074fd3 commit 1738c1f
Show file tree
Hide file tree
Showing 42 changed files with 168 additions and 141 deletions.
9 changes: 6 additions & 3 deletions display_list/display_list_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,8 @@ TEST_F(DisplayListTest, DisplayListFullPerspectiveTransformHandling) {
// clang-format on
);
sk_sp<DisplayList> display_list = builder.Build();
sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(10, 10);
sk_sp<SkSurface> surface =
SkSurfaces::Raster(SkImageInfo::MakeN32Premul(10, 10));
SkCanvas* canvas = surface->getCanvas();
// We can't use DlSkCanvas.DrawDisplayList as that method protects
// the canvas against mutations from the display list being drawn.
Expand All @@ -606,7 +607,8 @@ TEST_F(DisplayListTest, DisplayListFullPerspectiveTransformHandling) {
// clang-format on
);
sk_sp<DisplayList> display_list = builder.Build();
sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(10, 10);
sk_sp<SkSurface> surface =
SkSurfaces::Raster(SkImageInfo::MakeN32Premul(10, 10));
SkCanvas* canvas = surface->getCanvas();
// We can't use DlSkCanvas.DrawDisplayList as that method protects
// the canvas against mutations from the display list being drawn.
Expand All @@ -624,7 +626,8 @@ TEST_F(DisplayListTest, DisplayListTransformResetHandling) {
receiver.transformReset();
auto display_list = builder.Build();
ASSERT_NE(display_list, nullptr);
sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(10, 10);
sk_sp<SkSurface> surface =
SkSurfaces::Raster(SkImageInfo::MakeN32Premul(10, 10));
SkCanvas* canvas = surface->getCanvas();
// We can't use DlSkCanvas.DrawDisplayList as that method protects
// the canvas against mutations from the display list being drawn.
Expand Down
4 changes: 2 additions & 2 deletions display_list/effects/dl_color_source_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ namespace testing {
static sk_sp<DlImage> MakeTestImage(int w, int h, SkColor color) {
sk_sp<SkSurface> surface;
if (SkColorGetA(color) < 255) {
surface = SkSurface::MakeRasterN32Premul(w, h);
surface = SkSurfaces::Raster(SkImageInfo::MakeN32Premul(w, h));
} else {
SkImageInfo info =
SkImageInfo::MakeN32(w, h, SkAlphaType::kOpaque_SkAlphaType);
surface = SkSurface::MakeRaster(info);
surface = SkSurfaces::Raster(info);
}
SkCanvas* canvas = surface->getCanvas();
canvas->drawColor(color);
Expand Down
4 changes: 2 additions & 2 deletions display_list/testing/dl_rendering_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2388,8 +2388,8 @@ class CanvasCompareTester {

static const sk_sp<SkImage> kTestImage;
static const sk_sp<SkImage> makeTestImage() {
sk_sp<SkSurface> surface =
SkSurface::MakeRasterN32Premul(kRenderWidth, kRenderHeight);
sk_sp<SkSurface> surface = SkSurfaces::Raster(
SkImageInfo::MakeN32Premul(kRenderWidth, kRenderHeight));
SkCanvas* canvas = surface->getCanvas();
SkPaint p0, p1;
p0.setStyle(SkPaint::kFill_Style);
Expand Down
3 changes: 2 additions & 1 deletion display_list/testing/dl_test_snippets.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ static DlImageSampling kNearestSampling = DlImageSampling::kNearestNeighbor;
static DlImageSampling kLinearSampling = DlImageSampling::kLinear;

static sk_sp<DlImage> MakeTestImage(int w, int h, int checker_size) {
sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(w, h);
sk_sp<SkSurface> surface =
SkSurfaces::Raster(SkImageInfo::MakeN32Premul(w, h));
SkCanvas* canvas = surface->getCanvas();
SkPaint p0, p1;
p0.setStyle(SkPaint::kFill_Style);
Expand Down
3 changes: 2 additions & 1 deletion display_list/testing/dl_test_surface_gl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h"

namespace flutter {
namespace testing {
Expand Down Expand Up @@ -34,7 +35,7 @@ std::shared_ptr<DlSurfaceInstance>
DlOpenGLSurfaceProvider::MakeOffscreenSurface(size_t width,
size_t height,
PixelFormat format) const {
auto offscreen_surface = SkSurface::MakeRenderTarget(
auto offscreen_surface = SkSurfaces::RenderTarget(
(GrRecordingContext*)gl_surface_->GetGrContext().get(),
skgpu::Budgeted::kNo, MakeInfo(format, width, height), 1,
kTopLeft_GrSurfaceOrigin, nullptr, false);
Expand Down
2 changes: 1 addition & 1 deletion display_list/testing/dl_test_surface_software.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ std::shared_ptr<DlSurfaceInstance>
DlSoftwareSurfaceProvider::MakeOffscreenSurface(size_t width,
size_t height,
PixelFormat format) const {
auto surface = SkSurface::MakeRaster(MakeInfo(format, width, height));
auto surface = SkSurfaces::Raster(MakeInfo(format, width, height));
surface->getCanvas()->clear(SK_ColorTRANSPARENT);
return std::make_shared<DlSurfaceInstanceBase>(surface);
}
Expand Down
2 changes: 1 addition & 1 deletion flow/instrumentation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void Stopwatch::InitVisualizeSurface(SkISize size) const {

// TODO(garyq): Use a GPU surface instead of a CPU surface.
visualize_cache_surface_ =
SkSurface::MakeRasterN32Premul(size.width(), size.height());
SkSurfaces::Raster(SkImageInfo::MakeN32Premul(size));

SkCanvas* cache_canvas = visualize_cache_surface_->getCanvas();

Expand Down
5 changes: 3 additions & 2 deletions flow/layers/offscreen_surface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "third_party/skia/include/core/SkSerialProcs.h"
#include "third_party/skia/include/core/SkSurfaceCharacterization.h"
#include "third_party/skia/include/encode/SkPngEncoder.h"
#include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h"
#include "third_party/skia/include/utils/SkBase64.h"

namespace flutter {
Expand All @@ -23,14 +24,14 @@ static sk_sp<SkSurface> CreateSnapshotSurface(GrDirectContext* surface_context,
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.
return SkSurface::MakeRenderTarget(
return SkSurfaces::RenderTarget(
reinterpret_cast<GrRecordingContext*>(surface_context),
skgpu::Budgeted::kNo, image_info);
}

// There is no rendering surface, assume no GPU textures are present and
// create a raster surface.
return SkSurface::MakeRaster(image_info);
return SkSurfaces::Raster(image_info);
}

/// Returns a buffer containing a snapshot of the surface.
Expand Down
2 changes: 1 addition & 1 deletion flow/layers/performance_overlay_layer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static void TestPerformanceOverlayLayerGold(int refresh_rate) {
}

const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000);
sk_sp<SkSurface> surface = SkSurface::MakeRaster(image_info);
sk_sp<SkSurface> surface = SkSurfaces::Raster(image_info);
DlSkCanvasAdapter canvas(surface->getCanvas());

ASSERT_TRUE(surface != nullptr);
Expand Down
7 changes: 4 additions & 3 deletions flow/raster_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "third_party/skia/include/core/SkPicture.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"
#include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h"

namespace flutter {

Expand Down Expand Up @@ -64,9 +65,9 @@ std::unique_ptr<RasterCacheResult> RasterCache::Rasterize(

sk_sp<SkSurface> surface =
context.gr_context
? SkSurface::MakeRenderTarget(context.gr_context,
skgpu::Budgeted::kYes, image_info)
: SkSurface::MakeRaster(image_info);
? SkSurfaces::RenderTarget(context.gr_context, skgpu::Budgeted::kYes,
image_info)
: SkSurfaces::Raster(image_info);

if (!surface) {
return nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ static bool UpdateAtlasBitmap(const GlyphAtlas& atlas,
TRACE_EVENT0("impeller", __FUNCTION__);
FML_DCHECK(bitmap != nullptr);

auto surface = SkSurface::MakeRasterDirect(bitmap->pixmap());
auto surface = SkSurfaces::WrapPixels(bitmap->pixmap());
if (!surface) {
return false;
}
Expand Down Expand Up @@ -252,7 +252,7 @@ static std::shared_ptr<SkBitmap> CreateAtlasBitmap(const GlyphAtlas& atlas,
return nullptr;
}

auto surface = SkSurface::MakeRasterDirect(bitmap->pixmap());
auto surface = SkSurfaces::WrapPixels(bitmap->pixmap());
if (!surface) {
return nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/painting/image_encoding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ sk_sp<SkData> CopyImageByteData(const sk_sp<SkImage>& raster_image,
}

// Perform swizzle if the type doesnt match the specification.
auto surface = SkSurface::MakeRaster(
auto surface = SkSurfaces::Raster(
SkImageInfo::Make(raster_image->width(), raster_image->height(),
color_type, alpha_type, nullptr));

Expand Down
7 changes: 4 additions & 3 deletions lib/ui/painting/image_encoding_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h"

namespace flutter {

Expand All @@ -23,14 +24,14 @@ sk_sp<SkImage> ConvertToRasterUsingResourceContext(
is_gpu_disabled_sync_switch->Execute(
typename SyncSwitch::Handlers()
.SetIfTrue([&surface, &surface_info] {
surface = SkSurface::MakeRaster(surface_info);
surface = SkSurfaces::Raster(surface_info);
})
.SetIfFalse([&surface, &surface_info, resource_context] {
if (resource_context) {
surface = SkSurface::MakeRenderTarget(
surface = SkSurfaces::RenderTarget(
resource_context.get(), skgpu::Budgeted::kNo, surface_info);
} else {
surface = SkSurface::MakeRaster(surface_info);
surface = SkSurfaces::Raster(surface_info);
}
}));

Expand Down
3 changes: 2 additions & 1 deletion lib/web_ui/skwasm/surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "third_party/skia/include/core/SkPicture.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"
#include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h"
#include "third_party/skia/include/gpu/gl/GrGLInterface.h"
#include "third_party/skia/include/gpu/gl/GrGLTypes.h"
#include "wrappers.h"
Expand Down Expand Up @@ -158,7 +159,7 @@ class Surface {
makeCurrent(_glContext);
GrBackendRenderTarget target(_canvasWidth, _canvasHeight, _sampleCount,
_stencil, _fbInfo);
_surface = SkSurface::MakeFromBackendRenderTarget(
_surface = SkSurfaces::WrapBackendRenderTarget(
_grContext.get(), target, kBottomLeft_GrSurfaceOrigin,
kRGBA_8888_SkColorType, SkColorSpace::MakeSRGB(), nullptr);
}
Expand Down
4 changes: 2 additions & 2 deletions shell/common/canvas_spy_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ TEST(CanvasSpyTest, DrawingIsTracked) {

TEST(CanvasSpyTest, SpiedCanvasIsDrawing) {
auto actual_surface =
SkSurface::MakeRaster(SkImageInfo::MakeN32Premul(100, 100));
SkSurfaces::Raster(SkImageInfo::MakeN32Premul(100, 100));
SkCanvas* actual_canvas = actual_surface->getCanvas();

auto expected_surface =
SkSurface::MakeRaster(SkImageInfo::MakeN32Premul(100, 100));
SkSurfaces::Raster(SkImageInfo::MakeN32Premul(100, 100));
SkCanvas* expected_canvas = expected_surface->getCanvas();

CanvasSpy canvas_spy = CanvasSpy(actual_canvas);
Expand Down
5 changes: 3 additions & 2 deletions shell/common/rasterizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "third_party/skia/include/core/SkSize.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/core/SkSurfaceCharacterization.h"
#include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h"
#include "third_party/skia/include/utils/SkBase64.h"

namespace flutter {
Expand Down Expand Up @@ -280,7 +281,7 @@ std::unique_ptr<SnapshotDelegate::GpuImageResult> MakeBitmapImage(
std::to_string(image_info.height()));
};

sk_sp<SkSurface> surface = SkSurface::MakeRaster(image_info);
sk_sp<SkSurface> surface = SkSurfaces::Raster(image_info);
auto canvas = DlSkCanvasAdapter(surface->getCanvas());
canvas.Clear(DlColor::kTransparent());
canvas.DrawDisplayList(display_list);
Expand Down Expand Up @@ -341,7 +342,7 @@ std::unique_ptr<Rasterizer::GpuImageResult> Rasterizer::MakeSkiaGpuImage(
return;
}

sk_sp<SkSurface> sk_surface = SkSurface::MakeFromBackendTexture(
sk_sp<SkSurface> sk_surface = SkSurfaces::WrapBackendTexture(
context, texture, kTopLeft_GrSurfaceOrigin, /*sampleCnt=*/0,
image_info.colorType(), image_info.refColorSpace(), nullptr);
if (!sk_surface) {
Expand Down
5 changes: 3 additions & 2 deletions shell/common/rasterizer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "flutter/testing/testing.h"

#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h"

#include "gmock/gmock.h"

Expand Down Expand Up @@ -981,8 +982,8 @@ TEST(RasterizerTest, TeardownFreesResourceCache) {

auto image_info =
SkImageInfo::MakeN32Premul(500, 500, SkColorSpace::MakeSRGB());
auto sk_surface = SkSurface::MakeRenderTarget(
context.get(), skgpu::Budgeted::kYes, image_info);
auto sk_surface = SkSurfaces::RenderTarget(context.get(),
skgpu::Budgeted::kYes, image_info);
EXPECT_TRUE(sk_surface);

SkPaint paint;
Expand Down
5 changes: 3 additions & 2 deletions shell/common/shell_test_platform_view_vulkan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "flutter/vulkan/vulkan_utilities.h"

#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h"

#if OS_FUCHSIA
#define VULKAN_SO_PATH "libvulkan.so"
Expand Down Expand Up @@ -196,8 +197,8 @@ ShellTestPlatformViewVulkan::OffScreenSurface::AcquireFrame(
const SkISize& size) {
auto image_info = SkImageInfo::Make(size, SkColorType::kRGBA_8888_SkColorType,
SkAlphaType::kOpaque_SkAlphaType);
auto surface = SkSurface::MakeRenderTarget(
context_.get(), skgpu::Budgeted::kNo, image_info, 0, nullptr);
auto surface = SkSurfaces::RenderTarget(context_.get(), skgpu::Budgeted::kNo,
image_info, 0, nullptr);
SurfaceFrame::SubmitCallback callback = [](const SurfaceFrame&,
DlCanvas* canvas) -> bool {
canvas->Flush();
Expand Down
11 changes: 6 additions & 5 deletions shell/common/snapshot_controller_skia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "flutter/shell/common/snapshot_controller.h"
#include "third_party/skia/include/core/SkColorSpace.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h"

namespace flutter {

Expand Down Expand Up @@ -69,13 +70,13 @@ sk_sp<DlImage> SnapshotControllerSkia::DoMakeRasterSnapshot(
if (!snapshot_surface) {
// Raster surface is fine if there is no on screen surface. This might
// happen in case of software rendering.
sk_sp<SkSurface> sk_surface = SkSurface::MakeRaster(image_info);
sk_sp<SkSurface> sk_surface = SkSurfaces::Raster(image_info);
result = DrawSnapshot(sk_surface, draw_callback);
} else {
delegate.GetIsGpuDisabledSyncSwitch()->Execute(
fml::SyncSwitch::Handlers()
.SetIfTrue([&] {
sk_sp<SkSurface> surface = SkSurface::MakeRaster(image_info);
sk_sp<SkSurface> surface = SkSurfaces::Raster(image_info);
result = DrawSnapshot(surface, draw_callback);
})
.SetIfFalse([&] {
Expand Down Expand Up @@ -105,9 +106,9 @@ sk_sp<DlImage> SnapshotControllerSkia::DoMakeRasterSnapshot(
// When there is an on screen surface, we need a render target
// SkSurface because we want to access texture backed images.
sk_sp<SkSurface> sk_surface =
SkSurface::MakeRenderTarget(context, // context
skgpu::Budgeted::kNo, // budgeted
image_info // image info
SkSurfaces::RenderTarget(context, // context
skgpu::Budgeted::kNo, // budgeted
image_info // image info
);
if (!sk_surface) {
FML_LOG(ERROR)
Expand Down
3 changes: 2 additions & 1 deletion shell/gpu/gpu_surface_gl_skia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/gpu/GrBackendSurface.h"
#include "third_party/skia/include/gpu/GrContextOptions.h"
#include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h"

// These are common defines present on all OpenGL headers. However, we don't
// want to perform GL header reasolution on each platform we support. So just
Expand Down Expand Up @@ -147,7 +148,7 @@ static sk_sp<SkSurface> WrapOnscreenSurface(GrDirectContext* context,
sk_sp<SkColorSpace> colorspace = SkColorSpace::MakeSRGB();
SkSurfaceProps surface_props(0, kUnknown_SkPixelGeometry);

return SkSurface::MakeFromBackendRenderTarget(
return SkSurfaces::WrapBackendRenderTarget(
context, // Gr context
render_target, // render target
GrSurfaceOrigin::kBottomLeft_GrSurfaceOrigin, // origin
Expand Down
7 changes: 4 additions & 3 deletions shell/gpu/gpu_surface_metal_skia.mm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/core/SkSurfaceProps.h"
#include "third_party/skia/include/gpu/GrBackendSurface.h"
#include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h"
#include "third_party/skia/include/ports/SkCFObject.h"

static_assert(!__has_feature(objc_arc), "ARC must be disabled.");
Expand All @@ -39,12 +40,12 @@
SkColorType color_type,
sk_sp<SkColorSpace> color_space,
const SkSurfaceProps* props,
SkSurface::TextureReleaseProc release_proc,
SkSurfaces::TextureReleaseProc release_proc,
SkSurface::ReleaseContext release_context) {
GrMtlTextureInfo info;
info.fTexture.reset([texture retain]);
GrBackendTexture backend_texture(texture.width, texture.height, GrMipmapped::kNo, info);
return SkSurface::MakeFromBackendTexture(
return SkSurfaces::WrapBackendTexture(
context, backend_texture, origin, static_cast<int>(sample_cnt), color_type,
std::move(color_space), props, release_proc, release_context);
}
Expand Down Expand Up @@ -209,7 +210,7 @@

sk_sp<SkSurface> surface = CreateSurfaceFromMetalTexture(
context_.get(), mtl_texture, kTopLeft_GrSurfaceOrigin, msaa_samples_, kBGRA_8888_SkColorType,
nullptr, nullptr, static_cast<SkSurface::TextureReleaseProc>(texture.destruction_callback),
nullptr, nullptr, static_cast<SkSurfaces::TextureReleaseProc>(texture.destruction_callback),
texture.destruction_context);

if (!surface) {
Expand Down
Loading

0 comments on commit 1738c1f

Please sign in to comment.