20#ifndef INCLUDED_VCL_INC_SKIA_UTILS_H
21#define INCLUDED_VCL_INC_SKIA_UTILS_H
30#include <test/GraphicsRenderTests.hxx>
35#if defined __GNUC__ && !defined __clang__
36#pragma GCC diagnostic push
37#pragma GCC diagnostic ignored "-Wattributes"
38#pragma GCC diagnostic ignored "-Wshadow"
40#include <tools/sk_app/WindowContext.h>
41#if defined __GNUC__ && !defined __clang__
42#pragma GCC diagnostic pop
57 SkColorType type = kN32_SkColorType,
58 SkAlphaType alpha = kPremul_SkAlphaType);
61 SkAlphaType alpha = kPremul_SkAlphaType)
82 const SkIRect& bounds);
84inline Size imageSize(
const sk_sp<SkImage>& image) {
return Size(image->width(), image->height()); }
93 return SkColorSetA(
toSkColor(aColor), 255 * (1.0 - fTransparency));
98 return SkColorSetARGB(
color.GetAlpha(),
color.GetRed() * intensity / 100,
99 color.GetGreen() * intensity / 100,
color.GetBlue() * intensity / 100);
124 prepareSkia(std::unique_ptr<sk_app::WindowContext> (*createGpuWindowContext)(
bool));
145 static const char*
const testname = getenv(
"LO_TESTNAME");
146 if (testname !=
nullptr)
150 const char*
const testname = getenv(
"LO_TESTNAME");
151 if (testname !=
nullptr && std::string_view(
name) == testname)
180 if (scalingFactor != 1)
181 matrix.postScale(scalingFactor, scalingFactor);
184 return SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kLinear);
185 return SkSamplingOptions(SkCubicResampler::Mitchell());
189 return SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kNearest);
192 return SkSamplingOptions(SkFilterMode::kNearest, SkMipmapMode::kNone);
195 return SkSamplingOptions();
200 Size destSize,
int scalingFactor)
205 if (scalingFactor != 1)
206 destSize *= scalingFactor;
209 return SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kLinear);
210 return SkSamplingOptions(SkCubicResampler::Mitchell());
213 return SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kNearest);
216 return SkSamplingOptions(SkFilterMode::kNearest, SkMipmapMode::kNone);
219 return SkSamplingOptions();
224 int srcScalingFactor,
bool isGPU)
229 return SkSamplingOptions();
232 if (scalingFactor != 1)
233 destSize *= scalingFactor;
234 if (srcScalingFactor != 1)
235 srcSize *= srcScalingFactor;
236 if (srcSize != destSize)
238 return SkSamplingOptions();
243 return SkRect::MakeXYWH(rect.x() * scaling, rect.y() * scaling, rect.width() * scaling,
244 rect.height() * scaling);
247inline SkIRect
scaleRect(
const SkIRect& rect,
int scaling)
249 return SkIRect::MakeXYWH(rect.x() * scaling, rect.y() * scaling, rect.width() * scaling,
250 rect.height() * scaling);
276template <
typename charT,
typename traits>
277inline std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& stream,
278 const SkRect& rectangle)
287template <
typename charT,
typename traits>
288inline std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& stream,
289 const SkIRect& rectangle)
298template <
typename charT,
typename traits>
299inline std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& stream,
300 const SkRegion& region)
302 if (region.isEmpty())
305 SkRegion::Iterator it(region);
306 for (
int i = 0; !it.done(); it.next(), ++i)
307 stream <<
"[" <<
i <<
"] " << it.rect();
312template <
typename charT,
typename traits>
313inline std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& stream,
314 const SkMatrix& matrix)
321template <
typename charT,
typename traits>
322inline std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& stream,
323 const SkImage& image)
326 return stream << static_cast<const void*>(&image) <<
" " <<
Size(image.width(), image.height())
327 <<
"/" << (SkColorTypeBytesPerPixel(image.imageInfo().colorType()) * 8)
328 << (image.isTextureBacked() ?
"G" :
"");
330template <
typename charT,
typename traits>
331inline std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& stream,
332 const sk_sp<SkImage>& image)
334 if (image ==
nullptr)
335 return stream <<
"(null)";
constexpr tools::Long Height() const
constexpr tools::Long Width() const
Reference< XOutputStream > stream
DeviceVendor GetVendorFromId(uint32_t id)
Returns vendor for the given vendor ID, or VendorAll if not known.
Size imageSize(const sk_sp< SkImage > &image)
void setBlenderXor(SkPaint *paint)
BmpScaleFlag goodScalingQuality(bool isGPU)
Color fromSkColor(SkColor color)
constexpr int downscaleRatioThreshold
SkColor toSkColorWithTransparency(Color aColor, double fTransparency)
VCL_DLLPUBLIC uint32_t vendorId
void disableRenderMethod(RenderMethod method)
GrDirectContext * getSharedGrDirectContext()
SkRect scaleRect(const SkRect &rect, int scaling)
void addCachedImage(const OString &key, sk_sp< SkImage > image)
sk_sp< SkImage > findCachedImage(const OString &key)
bool isUnitTestRunning(const char *name=nullptr)
VCL_DLLPUBLIC sk_sp< SkImage > createSkImage(const SkBitmap &bitmap)
VCL_DLLPUBLIC sk_sp< SkSurface > createSkSurface(int width, int height, SkColorType type=kN32_SkColorType, SkAlphaType alpha=kPremul_SkAlphaType)
VCL_DLLPUBLIC void setPixelGeometry(SkPixelGeometry pixelGeometry)
void prefillSurface(const sk_sp< SkSurface > &surface)
SkSamplingOptions makeSamplingOptions(BmpScaleFlag scalingType, SkMatrix matrix, int scalingFactor)
VCL_DLLPUBLIC sk_sp< SkImage > makeCheckedImageSnapshot(sk_sp< SkSurface > surface)
DriverBlocklist::DeviceVendor getVendor()
tools::Long maxImageCacheSize()
void setBlenderInvert(SkPaint *paint)
void removeCachedImage(sk_sp< SkImage > image)
VCL_DLLPUBLIC const SkSurfaceProps * surfaceProps()
VCL_DLLPUBLIC void dump(const SkBitmap &bitmap, const char *file)
uint32_t getSkImageChecksum(sk_sp< SkImage > image)
VCL_DLLPUBLIC void prepareSkia(std::unique_ptr< sk_app::WindowContext >(*createGpuWindowContext)(bool))
SkColor toSkColor(Color color)
SkColor toSkColorWithIntensity(Color color, int intensity)
VCL_DLLPUBLIC bool matrixNeedsHighQuality(const SkMatrix &matrix)
constexpr double alpha[nDetails]
const OUString & activeGraphicsRenderTest()
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &stream, const SkRect &rectangle)