20 #ifndef INCLUDED_VCL_INC_SKIA_UTILS_H
21 #define INCLUDED_VCL_INC_SKIA_UTILS_H
30 #include <test/GraphicsRenderTests.hxx>
34 #include <SkSurface.h>
35 #include <tools/sk_app/WindowContext.h>
38 #include <string_view>
49 SkColorType type = kN32_SkColorType,
50 SkAlphaType alpha = kPremul_SkAlphaType);
53 SkAlphaType alpha = kPremul_SkAlphaType)
74 const SkIRect& bounds);
76 inline Size imageSize(
const sk_sp<SkImage>& image) {
return Size(image->width(), image->height()); }
85 return SkColorSetA(
toSkColor(aColor), 255 * (1.0 - fTransparency));
90 return SkColorSetARGB(color.
GetAlpha(), color.
GetRed() * intensity / 100,
96 return Color(
ColorAlpha, SkColorGetA(color), SkColorGetR(color), SkColorGetG(color),
116 prepareSkia(std::unique_ptr<sk_app::WindowContext> (*createGpuWindowContext)(
bool));
137 static const char*
const testname = getenv(
"LO_TESTNAME");
138 if (testname !=
nullptr)
142 const char*
const testname = getenv(
"LO_TESTNAME");
143 if (testname !=
nullptr && std::string_view(
name) == testname)
172 if (scalingFactor != 1)
173 matrix.postScale(scalingFactor, scalingFactor);
174 if (matrix.getScaleX() <= 1.0 / downscaleRatioThreshold
176 return SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kLinear);
177 return SkSamplingOptions(SkCubicResampler::Mitchell());
181 return SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kNearest);
184 return SkSamplingOptions(SkFilterMode::kNearest, SkMipmapMode::kNone);
187 return SkSamplingOptions();
192 Size destSize,
int scalingFactor)
197 if (scalingFactor != 1)
198 destSize *= scalingFactor;
199 if (srcSize.
Width() / destSize.
Width() >= downscaleRatioThreshold
201 return SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kLinear);
202 return SkSamplingOptions(SkCubicResampler::Mitchell());
205 return SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kNearest);
208 return SkSamplingOptions(SkFilterMode::kNearest, SkMipmapMode::kNone);
211 return SkSamplingOptions();
216 int srcScalingFactor,
bool isGPU)
221 return SkSamplingOptions();
224 if (scalingFactor != 1)
225 destSize *= scalingFactor;
226 if (srcScalingFactor != 1)
227 srcSize *= srcScalingFactor;
228 if (srcSize != destSize)
230 return SkSamplingOptions();
233 inline SkRect
scaleRect(
const SkRect& rect,
int scaling)
235 return SkRect::MakeXYWH(rect.x() * scaling, rect.y() * scaling, rect.width() * scaling,
236 rect.height() * scaling);
239 inline SkIRect
scaleRect(
const SkIRect& rect,
int scaling)
241 return SkIRect::MakeXYWH(rect.x() * scaling, rect.y() * scaling, rect.width() * scaling,
242 rect.height() * scaling);
268 template <
typename charT,
typename traits>
269 inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>&
stream,
273 return stream <<
"EMPTY";
279 template <
typename charT,
typename traits>
280 inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& stream,
284 return stream <<
"EMPTY";
290 template <
typename charT,
typename traits>
291 inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& stream,
292 const SkRegion& region)
294 if (region.isEmpty())
295 return stream <<
"EMPTY";
297 SkRegion::Iterator it(region);
298 for (
int i = 0; !it.done(); it.next(), ++
i)
299 stream <<
"[" <<
i <<
"] " << it.rect();
304 template <
typename charT,
typename traits>
305 inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& stream,
306 const SkMatrix& matrix)
308 return stream <<
"[" << matrix[0] <<
" " << matrix[1] <<
" " << matrix[2] <<
"]"
309 <<
"[" << matrix[3] <<
" " << matrix[4] <<
" " << matrix[5] <<
"]"
310 <<
"[" << matrix[6] <<
" " << matrix[7] <<
" " << matrix[8] <<
"]";
313 template <
typename charT,
typename traits>
314 inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& stream,
315 const SkImage& image)
318 return stream << static_cast<const void*>(&image) <<
" " <<
Size(image.width(), image.height())
319 <<
"/" << (SkColorTypeBytesPerPixel(image.imageInfo().colorType()) * 8)
320 << (image.isTextureBacked() ?
"G" :
"");
322 template <
typename charT,
typename traits>
323 inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& stream,
324 const sk_sp<SkImage>& image)
326 if (image ==
nullptr)
327 return stream <<
"(null)";
328 return stream << *image;
331 #endif // INCLUDED_VCL_INC_SKIA_UTILS_H
void setBlenderInvert(SkPaint *paint)
sal_uInt8 GetAlpha() const
GrDirectContext * getSharedGrDirectContext()
VCL_DLLPUBLIC sk_sp< SkImage > makeCheckedImageSnapshot(sk_sp< SkSurface > surface)
BmpScaleFlag goodScalingQuality(bool isGPU)
void setBlenderXor(SkPaint *paint)
Size imageSize(const sk_sp< SkImage > &image)
SkColor toSkColorWithTransparency(Color aColor, double fTransparency)
VCL_DLLPUBLIC const SkSurfaceProps * surfaceProps()
VCL_DLLPUBLIC void setPixelGeometry(SkPixelGeometry pixelGeometry)
const OUString & activeGraphicsRenderTest()
bool isUnitTestRunning(const char *name=nullptr)
sk_sp< SkImage > findCachedImage(const OString &key)
DeviceVendor GetVendorFromId(uint32_t id)
Returns vendor for the given vendor ID, or VendorAll if not known.
constexpr tools::Long Width() const
VCL_DLLPUBLIC bool matrixNeedsHighQuality(const SkMatrix &matrix)
VCL_DLLPUBLIC sk_sp< SkImage > createSkImage(const SkBitmap &bitmap)
constexpr int downscaleRatioThreshold
sal_uInt8 GetBlue() const
tools::Long maxImageCacheSize()
uint32_t getSkImageChecksum(sk_sp< SkImage > image)
void disableRenderMethod(RenderMethod method)
SkSamplingOptions makeSamplingOptions(BmpScaleFlag scalingType, SkMatrix matrix, int scalingFactor)
DriverBlocklist::DeviceVendor getVendor()
SkColor toSkColorWithIntensity(Color color, int intensity)
void prefillSurface(const sk_sp< SkSurface > &surface)
VCL_DLLPUBLIC void dump(const SkBitmap &bitmap, const char *file)
Reference< XOutputStream > stream
Color fromSkColor(SkColor color)
sal_uInt8 GetGreen() const
VCL_DLLPUBLIC uint32_t vendorId
constexpr tools::Long Height() const
VCL_DLLPUBLIC sk_sp< SkSurface > createSkSurface(int width, int height, SkColorType type=kN32_SkColorType, SkAlphaType alpha=kPremul_SkAlphaType)
VCL_DLLPUBLIC void prepareSkia(std::unique_ptr< sk_app::WindowContext >(*createGpuWindowContext)(bool))
void removeCachedImage(sk_sp< SkImage > image)
SkColor toSkColor(Color color)
SkRect scaleRect(const SkRect &rect, int scaling)
void addCachedImage(const OString &key, sk_sp< SkImage > image)