Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Paint::SrcEdges to enable mipmaps #97

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion os/paint.h
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 @@ -54,6 +54,18 @@ namespace os {
Stroke,
StrokeAndFill,
};

// Same as SkCanvas::SrcRectConstraint
enum SrcEdges {
Strict, // Sample only inside bounds, is slower (don't use mipmaps)
Fast, // Sample outside bounds, is faster (use mipmaps)
};

SrcEdges srcEdges() const { return m_srcEdges; }
void srcEdges(const SrcEdges srcEdges) { m_srcEdges = srcEdges; }

private:
SrcEdges m_srcEdges = SrcEdges::Strict;
};

};
Expand Down
50 changes: 35 additions & 15 deletions os/skia/skia_surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ static PixelAlpha from_skia(const SkAlphaType at)
}
}

static SkCanvas::SrcRectConstraint to_constraint(const Paint* paint)
{
if (paint && paint->srcEdges() == Paint::SrcEdges::Fast)
return SkCanvas::kFast_SrcRectConstraint;
return SkCanvas::kStrict_SrcRectConstraint;
}

SkiaSurface::SkiaSurface()
: m_surface(nullptr)
, m_colorSpace(nullptr)
Expand Down Expand Up @@ -444,7 +451,8 @@ void SkiaSurface::blitTo(Surface* _dst, int srcx, int srcy, int dstx, int dsty,
srcImage,
srcRect, dstRect,
SkSamplingOptions(),
&paint, SkCanvas::kStrict_SrcRectConstraint);
&paint,
SkCanvas::kStrict_SrcRectConstraint);
return;
}
#endif
Expand All @@ -454,15 +462,17 @@ void SkiaSurface::blitTo(Surface* _dst, int srcx, int srcy, int dstx, int dsty,
SkImage::MakeFromRaster(m_bitmap.pixmap(), nullptr, nullptr),
srcRect, dstRect,
SkSamplingOptions(),
&paint, SkCanvas::kStrict_SrcRectConstraint);
&paint,
SkCanvas::kStrict_SrcRectConstraint);
}
else {
sk_sp<SkImage> snapshot = m_surface->makeImageSnapshot(srcRect.round());
srcRect.offsetTo(0, 0);
dst->m_canvas->drawImageRect(
snapshot, srcRect, dstRect,
SkSamplingOptions(),
&paint, SkCanvas::kStrict_SrcRectConstraint);
&paint,
SkCanvas::kStrict_SrcRectConstraint);
}
}

Expand Down Expand Up @@ -521,7 +531,8 @@ void SkiaSurface::drawSurface(const Surface* src, int dstx, int dsty)
src,
clip,
SkSamplingOptions(),
paint);
paint,
SkCanvas::kStrict_SrcRectConstraint);
}

void SkiaSurface::drawSurface(const Surface* src,
Expand All @@ -541,7 +552,8 @@ void SkiaSurface::drawSurface(const Surface* src,
srcRect,
dstRect,
skSampling,
(paint ? paint->skPaint(): skSrcPaint));
(paint ? paint->skPaint(): skSrcPaint),
to_constraint(paint));
}

void SkiaSurface::drawRgbaSurface(const Surface* src, int dstx, int dsty)
Expand All @@ -554,7 +566,8 @@ void SkiaSurface::drawRgbaSurface(const Surface* src, int dstx, int dsty)
src,
clip,
SkSamplingOptions(),
paint);
paint,
SkCanvas::kStrict_SrcRectConstraint);
}

void SkiaSurface::drawRgbaSurface(const Surface* src, int srcx, int srcy, int dstx, int dsty, int w, int h)
Expand All @@ -567,7 +580,8 @@ void SkiaSurface::drawRgbaSurface(const Surface* src, int srcx, int srcy, int ds
src,
clip,
SkSamplingOptions(),
paint);
paint,
SkCanvas::kStrict_SrcRectConstraint);
}

void SkiaSurface::drawColoredRgbaSurface(const Surface* src, gfx::Color fg, gfx::Color bg, const gfx::Clip& clipbase)
Expand Down Expand Up @@ -596,7 +610,8 @@ void SkiaSurface::drawColoredRgbaSurface(const Surface* src, gfx::Color fg, gfx:
srcRect,
dstRect,
SkSamplingOptions(),
paint);
paint,
SkCanvas::kStrict_SrcRectConstraint);
}

void SkiaSurface::drawSurfaceNine(os::Surface* surface,
Expand Down Expand Up @@ -735,35 +750,40 @@ void SkiaSurface::skDrawSurface(
const Surface* src,
const gfx::Clip& clip,
const SkSamplingOptions& sampling,
const SkPaint& paint)
const SkPaint& paint,
const SkCanvas::SrcRectConstraint constraint)
{
skDrawSurface(static_cast<const SkiaSurface*>(src),
SkRect::MakeXYWH(clip.src.x, clip.src.y, clip.size.w, clip.size.h),
SkRect::MakeXYWH(clip.dst.x, clip.dst.y, clip.size.w, clip.size.h),
sampling,
paint);
paint,
constraint);
}

void SkiaSurface::skDrawSurface(
const Surface* src,
const gfx::Rect& srcRect,
const gfx::Rect& dstRect,
const SkSamplingOptions& sampling,
const SkPaint& paint)
const SkPaint& paint,
const SkCanvas::SrcRectConstraint constraint)
{
skDrawSurface(static_cast<const SkiaSurface*>(src),
SkRect::MakeXYWH(srcRect.x, srcRect.y, srcRect.w, srcRect.h),
SkRect::MakeXYWH(dstRect.x, dstRect.y, dstRect.w, dstRect.h),
sampling,
paint);
paint,
constraint);
}

void SkiaSurface::skDrawSurface(
const SkiaSurface* src,
const SkRect& srcRect,
const SkRect& dstRect,
const SkSamplingOptions& sampling,
const SkPaint& paint)
const SkPaint& paint,
const SkCanvas::SrcRectConstraint constraint)
{
#if SK_SUPPORT_GPU
src->flush();
Expand All @@ -774,7 +794,7 @@ void SkiaSurface::skDrawSurface(
dstRect,
sampling,
&paint,
SkCanvas::kStrict_SrcRectConstraint);
constraint);
return;
}
#endif
Expand All @@ -785,7 +805,7 @@ void SkiaSurface::skDrawSurface(
dstRect,
sampling,
&paint,
SkCanvas::kStrict_SrcRectConstraint);
constraint);
}

#if SK_SUPPORT_GPU
Expand Down
10 changes: 7 additions & 3 deletions os/skia/skia_surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "os/surface_format.h"

#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColorType.h"
#include "include/core/SkPaint.h"
#include "include/core/SkSurface.h"
Expand Down Expand Up @@ -121,19 +122,22 @@ class SkiaSurface final : public Surface {
const Surface* src,
const gfx::Clip& clip,
const SkSamplingOptions& sampling,
const SkPaint& paint);
const SkPaint& paint,
SkCanvas::SrcRectConstraint constraint);
void skDrawSurface(
const Surface* src,
const gfx::Rect& srcRect,
const gfx::Rect& dstRect,
const SkSamplingOptions& sampling,
const SkPaint& paint);
const SkPaint& paint,
SkCanvas::SrcRectConstraint constraint);
void skDrawSurface(
const SkiaSurface* src,
const SkRect& srcRect,
const SkRect& dstRect,
const SkSamplingOptions& sampling,
const SkPaint& paint);
const SkPaint& paint,
SkCanvas::SrcRectConstraint constraint);

#if SK_SUPPORT_GPU
const SkImage* getOrCreateTextureImage() const;
Expand Down
Loading