1 /* 2 * Copyright 2021 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #include "modules/androidkit/src/Utils.h" 9 10 namespace androidkit { 11 namespace utils { 12 SamplingOptions(jint desc,jfloat coeffB,jfloat coeffC)13SkSamplingOptions SamplingOptions(jint desc, jfloat coeffB, jfloat coeffC) { 14 if (desc & 0x01) { 15 return SkSamplingOptions(SkCubicResampler{coeffB, coeffC}); 16 } 17 18 const auto fm = static_cast<SkFilterMode>((desc >> 1) & 0x01); 19 SkASSERT(fm <= SkFilterMode::kLast); 20 const auto mm = static_cast<SkMipmapMode>((desc >> 2) & 0x03); 21 SkASSERT(mm <= SkMipmapMode::kLast); 22 23 return SkSamplingOptions(fm, mm); 24 } 25 TileMode(jint tm)26SkTileMode TileMode(jint tm) { 27 // to catch Skia API changes 28 static_assert(static_cast<int>(SkTileMode::kClamp ) == 0); 29 static_assert(static_cast<int>(SkTileMode::kRepeat) == 1); 30 static_assert(static_cast<int>(SkTileMode::kMirror) == 2); 31 static_assert(static_cast<int>(SkTileMode::kDecal ) == 3); 32 33 return static_cast<SkTileMode>(tm); 34 } 35 BlendMode(jint bm)36SkBlendMode BlendMode(jint bm) { 37 // catch API changes 38 static_assert(0 == static_cast<int>(SkBlendMode::kClear)); 39 static_assert(1 == static_cast<int>(SkBlendMode::kSrc)); 40 static_assert(2 == static_cast<int>(SkBlendMode::kDst)); 41 static_assert(3 == static_cast<int>(SkBlendMode::kSrcOver)); 42 static_assert(4 == static_cast<int>(SkBlendMode::kDstOver)); 43 static_assert(5 == static_cast<int>(SkBlendMode::kSrcIn)); 44 static_assert(6 == static_cast<int>(SkBlendMode::kDstIn)); 45 static_assert(7 == static_cast<int>(SkBlendMode::kSrcOut)); 46 static_assert(8 == static_cast<int>(SkBlendMode::kDstOut)); 47 static_assert(9 == static_cast<int>(SkBlendMode::kSrcATop)); 48 static_assert(10 == static_cast<int>(SkBlendMode::kDstATop)); 49 static_assert(11 == static_cast<int>(SkBlendMode::kXor)); 50 static_assert(12 == static_cast<int>(SkBlendMode::kPlus)); 51 static_assert(13 == static_cast<int>(SkBlendMode::kModulate)); 52 static_assert(14 == static_cast<int>(SkBlendMode::kScreen)); 53 54 static_assert(15 == static_cast<int>(SkBlendMode::kOverlay)); 55 static_assert(16 == static_cast<int>(SkBlendMode::kDarken)); 56 static_assert(17 == static_cast<int>(SkBlendMode::kLighten)); 57 static_assert(18 == static_cast<int>(SkBlendMode::kColorDodge)); 58 static_assert(19 == static_cast<int>(SkBlendMode::kColorBurn)); 59 static_assert(20 == static_cast<int>(SkBlendMode::kHardLight)); 60 static_assert(21 == static_cast<int>(SkBlendMode::kSoftLight)); 61 static_assert(22 == static_cast<int>(SkBlendMode::kDifference)); 62 static_assert(23 == static_cast<int>(SkBlendMode::kExclusion)); 63 static_assert(24 == static_cast<int>(SkBlendMode::kMultiply)); 64 65 static_assert(25 == static_cast<int>(SkBlendMode::kHue)); 66 static_assert(26 == static_cast<int>(SkBlendMode::kSaturation)); 67 static_assert(27 == static_cast<int>(SkBlendMode::kColor)); 68 static_assert(28 == static_cast<int>(SkBlendMode::kLuminosity)); 69 70 71 return static_cast<SkBlendMode>(bm); 72 } 73 74 } // namespace utils 75 } // namespace androidkit 76