Skip to content

Commit

Permalink
Update to Skia m122 API
Browse files Browse the repository at this point in the history
  • Loading branch information
dacap committed Jan 26, 2024
1 parent 157533d commit 73144a2
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 43 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2018-2023 Igara Studio S.A.
Copyright (c) 2018-2024 Igara Studio S.A.
Copyright (c) 2016-2018 David Capello

Permission is hereby granted, free of charge, to any person obtaining
Expand Down
3 changes: 2 additions & 1 deletion os/skia/paint.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// LAF OS Library
// Copyright (c) 2022 Igara Studio S.A.
// Copyright (c) 2022-2024 Igara Studio S.A.
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
Expand All @@ -10,6 +10,7 @@

#include "gfx/color.h"

#include "include/core/SkBlendMode.h"
#include "include/core/SkPaint.h"

namespace os {
Expand Down
10 changes: 4 additions & 6 deletions os/skia/skia_color_space.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// LAF OS Library
// Copyright (C) 2018-2021 Igara Studio S.A.
// Copyright (C) 2018-2024 Igara Studio S.A.
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
Expand All @@ -14,15 +14,11 @@

#include "include/core/SkImageInfo.h"
#include "include/core/SkString.h"
#include "include/third_party/skcms/skcms.h"
#include "modules/skcms/src/skcms_public.h"
#include "src/core/SkConvertPixels.h"

#include <algorithm>

// Defined in skia/src/core/SkICC.cpp
const char* get_color_profile_description(const skcms_TransferFunction& fn,
const skcms_Matrix3x3& toXYZD50);

namespace os {

// Copied from skia/src/core/SkColorSpacePriv.h
Expand Down Expand Up @@ -113,9 +109,11 @@ SkiaColorSpace::SkiaColorSpace(const gfx::ColorSpaceRef& gfxcs)
skcms_Matrix3x3 toXYZD50;
if (m_skcs->isNumericalTransferFn(&fn) &&
m_skcs->toXYZD50(&toXYZD50)) {
#if 0 // TODO create a description for the color profile
const char* desc = get_color_profile_description(fn, toXYZD50);
if (desc)
m_gfxcs->setName(desc);
#endif
}
}

Expand Down
5 changes: 2 additions & 3 deletions os/skia/skia_draw_text_with_shaper.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// LAF OS Library
// Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2019-2024 Igara Studio S.A.
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
Expand Down Expand Up @@ -31,8 +31,7 @@ void draw_text_with_shaper(
const TextAlign textAlign,
DrawTextDelegate* delegate)
{
// SkFont skFont(SkTypeface::MakeFromFile("/Library/Fonts/Arial Unicode.ttf"), SkIntToScalar(24));
SkFont skFont(SkTypeface::MakeDefault(), SkIntToScalar(24));
SkFont skFont;
sk_sp<SkTextBlob> textBlob;
auto shaper = SkShaper::Make();
if (shaper) {
Expand Down
8 changes: 4 additions & 4 deletions os/skia/skia_font_manager.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// LAF OS Library
// Copyright (c) 2019-2020 Igara Studio S.A.
// Copyright (c) 2019-2024 Igara Studio S.A.
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
Expand All @@ -20,7 +20,7 @@ namespace os {

class SkiaTypeface : public Typeface {
public:
SkiaTypeface(SkTypeface* skTypeface)
SkiaTypeface(sk_sp<SkTypeface> skTypeface)
: m_skTypeface(skTypeface) {
}

Expand All @@ -37,7 +37,7 @@ class SkiaTypeface : public Typeface {

class SkiaFontStyleSet : public FontStyleSet {
public:
SkiaFontStyleSet(SkFontStyleSet* set)
SkiaFontStyleSet(sk_sp<SkFontStyleSet> set)
: m_skSet(set) {
}

Expand Down Expand Up @@ -75,7 +75,7 @@ class SkiaFontStyleSet : public FontStyleSet {
class SkiaFontManager : public FontManager {
public:
SkiaFontManager()
: m_skFontMgr(SkFontMgr::RefDefault()) {
: m_skFontMgr(SkFontMgr::RefEmpty()) {
}

~SkiaFontManager() {
Expand Down
27 changes: 15 additions & 12 deletions os/skia/skia_gl.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// LAF OS Library
// Copyright (C) 2022 Igara Studio S.A.
// Copyright (C) 2022-2024 Igara Studio S.A.
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
Expand All @@ -14,8 +14,11 @@
#if SK_SUPPORT_GPU

#include "include/core/SkSurface.h"
#include "include/core/SkSurfaceCharacterization.h"
#include "src/gpu/gl/GrGLDefines.h"
#include "include/gpu/GrBackendSurface.h"
#include "include/gpu/ganesh/SkSurfaceGanesh.h"
#include "include/gpu/ganesh/gl/GrGLBackendSurface.h"
#include "include/gpu/ganesh/gl/GrGLDirectContext.h"
#include "src/gpu/ganesh/gl/GrGLDefines.h"

namespace os {

Expand All @@ -36,7 +39,7 @@ bool SkiaGL::attachGL()
return false;
}

m_grCtx = GrDirectContext::MakeGL(m_glInterfaces);
m_grCtx = GrDirectContexts::MakeGL(m_glInterfaces);
if (!m_grCtx) {
LOG(ERROR, "OS: Cannot create GrContext\n");
detachGL();
Expand Down Expand Up @@ -75,15 +78,18 @@ bool SkiaGL::createRenderTarget(const gfx::Size& size,
GrGLFramebufferInfo info;
info.fFBOID = (GrGLuint)buffer;
info.fFormat = GR_GL_RGBA8;
//SK_API bool GrBackendRenderTargets::GetGLFramebufferInfo(const GrBackendRenderTarget&, GrGLFramebufferInfo*);

GrGLint stencil = 0;
m_glInterfaces->fFunctions.fGetIntegerv(GR_GL_STENCIL_BITS, &stencil);

GrBackendRenderTarget target(size.w, size.h, 0, stencil, info);
// GrBackendRenderTarget target(size.w, size.h, 0, stencil, info);
GrBackendRenderTarget target =
GrBackendRenderTargets::MakeGL(size.w, size.h, 0, stencil, info);

m_surface.reset(nullptr);
m_backbufferSurface =
SkSurface::MakeFromBackendRenderTarget(
SkSurfaces::WrapBackendRenderTarget(
m_grCtx.get(), target,
kBottomLeft_GrSurfaceOrigin,
kRGBA_8888_SkColorType,
Expand All @@ -104,13 +110,10 @@ bool SkiaGL::createRenderTarget(const gfx::Size& size,
kOpaque_SkAlphaType,
colorSpace);

SkSurfaceCharacterization ch;
m_backbufferSurface->characterize(&ch);

m_surface =
SkSurface::MakeRenderTarget(
m_grCtx.get(), SkBudgeted::kNo,
info, ch.sampleCount(), nullptr);
SkSurfaces::RenderTarget(
m_grCtx.get(), skgpu::Budgeted::kNo,
info, 0, nullptr);
}

return true;
Expand Down
32 changes: 18 additions & 14 deletions os/skia/skia_surface.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// LAF OS Library
// Copyright (c) 2018-2022 Igara Studio S.A.
// Copyright (c) 2018-2024 Igara Studio S.A.
// Copyright (c) 2016-2018 David Capello
//
// This file is released under the terms of the MIT license.
Expand All @@ -24,8 +24,10 @@
#include "include/private/SkColorData.h"

#if SK_SUPPORT_GPU
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/ganesh/SkImageGanesh.h"
#include "include/gpu/ganesh/gl/GrGLBackendSurface.h"
#endif

#include <memory>
Expand Down Expand Up @@ -105,14 +107,16 @@ void SkiaSurface::destroy()

void SkiaSurface::flush() const
{
if (m_canvas)
m_canvas->flush();
// TODO replace with GrDirectContext::flush()
// if (m_canvas)
// m_canvas->flush();
}

void SkiaSurface::flushAndSubmit() const
{
if (m_surface)
m_surface->flushAndSubmit();
// TODO replace with GrDirectContext::flushAndSubmit()
// if (m_surface)
// m_surface->flushAndSubmit();
}

int SkiaSurface::width() const
Expand Down Expand Up @@ -246,7 +250,7 @@ void SkiaSurface::applyScale(int scaleFactor)
SkCanvas canvas(result);
SkRect srcRect = SkRect::Make(SkIRect::MakeXYWH(0, 0, width(), height()));
SkRect dstRect = SkRect::Make(SkIRect::MakeXYWH(0, 0, result.width(), result.height()));
canvas.drawImageRect(SkImage::MakeFromRaster(m_bitmap.pixmap(), nullptr, nullptr),
canvas.drawImageRect(SkImages::RasterFromPixmap(m_bitmap.pixmap(), nullptr, nullptr),
srcRect, dstRect, SkSamplingOptions(),
&paint, SkCanvas::kStrict_SrcRectConstraint);

Expand Down Expand Up @@ -368,7 +372,6 @@ void SkiaSurface::putPixel(gfx::Color color, int x, int y)
auto r = SkIRect::MakeXYWH(x, y, 1, 1);
const_cast<SkPixmap&>(m_bitmap.pixmap()).erase(
to_skia4f(color),
skColorSpace().get(),
&r);
#else
// Doesn't work as SkBitmap::erase() expects an sRGB color (and
Expand Down Expand Up @@ -435,7 +438,7 @@ void SkiaSurface::blitTo(Surface* _dst, int srcx, int srcy, int dstx, int dsty,

if (!m_bitmap.empty()) {
dst->m_canvas->drawImageRect(
SkImage::MakeFromRaster(m_bitmap.pixmap(), nullptr, nullptr),
SkImages::RasterFromPixmap(m_bitmap.pixmap(), nullptr, nullptr),
srcRect, dstRect,
SkSamplingOptions(),
&paint, SkCanvas::kStrict_SrcRectConstraint);
Expand Down Expand Up @@ -671,8 +674,9 @@ void SkiaSurface::drawSurfaceNine(os::Surface* surface,
}
#endif

auto image = SkImages::RasterFromPixmap(((SkiaSurface*)surface)->m_bitmap.pixmap(), nullptr, nullptr);
m_canvas->drawImageLattice(
SkImage::MakeFromRaster(((SkiaSurface*)surface)->m_bitmap.pixmap(), nullptr, nullptr).get(),
image.get(),
lattice, dstRect,
SkFilterMode::kNearest,
&skPaint);
Expand Down Expand Up @@ -764,7 +768,7 @@ void SkiaSurface::skDrawSurface(
#endif

m_canvas->drawImageRect(
SkImage::MakeFromRaster(src->m_bitmap.pixmap(), nullptr, nullptr),
SkImages::RasterFromPixmap(src->m_bitmap.pixmap(), nullptr, nullptr),
srcRect,
dstRect,
sampling,
Expand Down Expand Up @@ -798,14 +802,14 @@ bool SkiaSurface::uploadBitmapAsTexture() const
Window* win = os::instance()->defaultWindow();

GrBackendTexture texture;
SkImage::BackendTextureReleaseProc proc;
SkImage::MakeBackendTextureFromSkImage(
SkImages::BackendTextureReleaseProc proc;
SkImages::GetBackendTextureFromImage(
win->sk_grCtx(),
image,
&texture,
&proc);

m_image = SkImage::MakeFromTexture(
m_image = SkImages::BorrowTextureFrom(
win->sk_grCtx(),
texture,
kTopLeft_GrSurfaceOrigin,
Expand Down
2 changes: 1 addition & 1 deletion os/skia/skia_window_osx.mm
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@
bitmap.eraseColor(0);

SkCanvas canvas(bitmap);
canvas.drawImageRect(SkImage::MakeFromRaster(origBitmap.pixmap(), nullptr, nullptr),
canvas.drawImageRect(SkImages::RasterFromPixmap(origBitmap.pixmap(), nullptr, nullptr),
SkRect::MakeXYWH(rect.x/scale,
(viewBounds.size.height-(rect.y+rect.h))/scale,
rect.w/scale,
Expand Down
2 changes: 1 addition & 1 deletion os/skia/skia_window_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void SkiaWindowX11::onPaint(const gfx::Rect& rc)
SkCanvas canvas(scaled);
SkRect srcRect = SkRect::Make(SkIRect::MakeXYWH(rc.x/scale, rc.y/scale, rc.w/scale, rc.h/scale));
SkRect dstRect = SkRect::Make(SkIRect::MakeXYWH(0, 0, rc.w, rc.h));
canvas.drawImageRect(SkImage::MakeFromRaster(bitmap.pixmap(), nullptr, nullptr),
canvas.drawImageRect(SkImages::RasterFromPixmap(bitmap.pixmap(), nullptr, nullptr),
srcRect, dstRect, SkSamplingOptions(),
&paint, SkCanvas::kStrict_SrcRectConstraint);

Expand Down

0 comments on commit 73144a2

Please sign in to comment.