/* * Copyright 2021 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #include "modules/androidkit/src/Utils.h" namespace androidkit { namespace utils { SkSamplingOptions SamplingOptions(jint desc, jfloat coeffB, jfloat coeffC) { if (desc & 0x01) { return SkSamplingOptions(SkCubicResampler{coeffB, coeffC}); } const auto fm = static_cast((desc >> 1) & 0x01); SkASSERT(fm <= SkFilterMode::kLast); const auto mm = static_cast((desc >> 2) & 0x03); SkASSERT(mm <= SkMipmapMode::kLast); return SkSamplingOptions(fm, mm); } SkTileMode TileMode(jint tm) { // to catch Skia API changes static_assert(static_cast(SkTileMode::kClamp ) == 0); static_assert(static_cast(SkTileMode::kRepeat) == 1); static_assert(static_cast(SkTileMode::kMirror) == 2); static_assert(static_cast(SkTileMode::kDecal ) == 3); return static_cast(tm); } SkBlendMode BlendMode(jint bm) { // catch API changes static_assert(0 == static_cast(SkBlendMode::kClear)); static_assert(1 == static_cast(SkBlendMode::kSrc)); static_assert(2 == static_cast(SkBlendMode::kDst)); static_assert(3 == static_cast(SkBlendMode::kSrcOver)); static_assert(4 == static_cast(SkBlendMode::kDstOver)); static_assert(5 == static_cast(SkBlendMode::kSrcIn)); static_assert(6 == static_cast(SkBlendMode::kDstIn)); static_assert(7 == static_cast(SkBlendMode::kSrcOut)); static_assert(8 == static_cast(SkBlendMode::kDstOut)); static_assert(9 == static_cast(SkBlendMode::kSrcATop)); static_assert(10 == static_cast(SkBlendMode::kDstATop)); static_assert(11 == static_cast(SkBlendMode::kXor)); static_assert(12 == static_cast(SkBlendMode::kPlus)); static_assert(13 == static_cast(SkBlendMode::kModulate)); static_assert(14 == static_cast(SkBlendMode::kScreen)); static_assert(15 == static_cast(SkBlendMode::kOverlay)); static_assert(16 == static_cast(SkBlendMode::kDarken)); static_assert(17 == static_cast(SkBlendMode::kLighten)); static_assert(18 == static_cast(SkBlendMode::kColorDodge)); static_assert(19 == static_cast(SkBlendMode::kColorBurn)); static_assert(20 == static_cast(SkBlendMode::kHardLight)); static_assert(21 == static_cast(SkBlendMode::kSoftLight)); static_assert(22 == static_cast(SkBlendMode::kDifference)); static_assert(23 == static_cast(SkBlendMode::kExclusion)); static_assert(24 == static_cast(SkBlendMode::kMultiply)); static_assert(25 == static_cast(SkBlendMode::kHue)); static_assert(26 == static_cast(SkBlendMode::kSaturation)); static_assert(27 == static_cast(SkBlendMode::kColor)); static_assert(28 == static_cast(SkBlendMode::kLuminosity)); return static_cast(bm); } } // namespace utils } // namespace androidkit