paint_op_helper_unittest.cc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "cc/test/paint_op_helper.h"
  5. #include "cc/paint/paint_canvas.h"
  6. #include "cc/paint/paint_op_buffer.h"
  7. #include "testing/gtest/include/gtest/gtest.h"
  8. #include "third_party/skia/include/core/SkTextBlob.h"
  9. namespace cc {
  10. namespace {
  11. TEST(PaintOpHelper, AnnotateToString) {
  12. AnnotateOp op(PaintCanvas::AnnotationType::URL, SkRect::MakeXYWH(1, 2, 3, 4),
  13. nullptr);
  14. std::string str = PaintOpHelper::ToString(&op);
  15. EXPECT_EQ(str,
  16. "AnnotateOp(type=URL, rect=[1.000,2.000 3.000x4.000], data=(nil))");
  17. }
  18. TEST(PaintOpHelper, ClipPathToString) {
  19. ClipPathOp op(SkPath(), SkClipOp::kDifference, true,
  20. UsePaintCache::kDisabled);
  21. std::string str = PaintOpHelper::ToString(&op);
  22. EXPECT_EQ(str,
  23. "ClipPathOp(path=<SkPath>, op=kDifference, antialias=true, "
  24. "use_cache=false)");
  25. }
  26. TEST(PaintOpHelper, ClipRectToString) {
  27. ClipRectOp op(SkRect::MakeXYWH(10.1f, 20.2f, 30.3f, 40.4f),
  28. SkClipOp::kIntersect, false);
  29. std::string str = PaintOpHelper::ToString(&op);
  30. EXPECT_EQ(str,
  31. "ClipRectOp(rect=[10.100,20.200 30.300x40.400], op=kIntersect, "
  32. "antialias=false)");
  33. }
  34. TEST(PaintOpHelper, ClipRRectToString) {
  35. ClipRRectOp op(SkRRect::MakeRect(SkRect::MakeXYWH(1, 2, 3, 4)),
  36. SkClipOp::kDifference, false);
  37. std::string str = PaintOpHelper::ToString(&op);
  38. EXPECT_EQ(str,
  39. "ClipRRectOp(rrect=[bounded by 1.000,2.000 3.000x4.000], "
  40. "op=kDifference, antialias=false)");
  41. }
  42. TEST(PaintOpHelper, ConcatToString) {
  43. ConcatOp op(SkM44(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16));
  44. std::string str = PaintOpHelper::ToString(&op);
  45. EXPECT_EQ(str,
  46. "ConcatOp(matrix=[ 1.0000 2.0000 3.0000 4.0000][ 5.0000 "
  47. "6.0000 7.0000 8.0000][ 9.0000 10.0000 11.0000 12.0000][ "
  48. "13.0000 14.0000 15.0000 16.0000]])");
  49. }
  50. TEST(PaintOpHelper, DrawColorToString) {
  51. DrawColorOp op({0.1, 0.2, 0.3, 0.4}, SkBlendMode::kSrc);
  52. std::string str = PaintOpHelper::ToString(&op);
  53. EXPECT_EQ(str,
  54. "DrawColorOp(color=rgba(0.100000, 0.200000, 0.300000, 0.400000), "
  55. "mode=kSrc)");
  56. }
  57. TEST(PaintOpHelper, DrawDRRectToString) {
  58. DrawDRRectOp op(SkRRect::MakeRect(SkRect::MakeXYWH(1, 2, 3, 4)),
  59. SkRRect::MakeRect(SkRect::MakeXYWH(5, 6, 7, 8)),
  60. PaintFlags());
  61. std::string str = PaintOpHelper::ToString(&op);
  62. EXPECT_EQ(
  63. str,
  64. "DrawDRRectOp(outer=[bounded by 1.000,2.000 3.000x4.000], inner=[bounded "
  65. "by 5.000,6.000 7.000x8.000], flags=[color=rgba(0, 0, 0, 255), "
  66. "blendMode=kSrcOver, isAntiAlias=false, isDither=false, "
  67. "filterQuality=kNone_SkFilterQuality, "
  68. "strokeWidth=0.000, strokeMiter=4.000, strokeCap=kButt_Cap, "
  69. "strokeJoin=kMiter_Join, colorFilter=(nil), "
  70. "maskFilter=(nil), shader=(nil), hasShader=false, shaderIsOpaque=false, "
  71. "pathEffect=(nil), imageFilter=(nil), drawLooper=(nil), "
  72. "isSimpleOpacity=true, supportsFoldingAlpha=true, isValid=true, "
  73. "hasDiscardableImages=false])");
  74. }
  75. TEST(PaintOpHelper, DrawImageToString) {
  76. DrawImageOp op(PaintImage(), 10.5f, 20.3f);
  77. std::string str = PaintOpHelper::ToString(&op);
  78. EXPECT_EQ(
  79. str,
  80. "DrawImageOp(image=<paint image>, left=10.500, top=20.300, "
  81. "flags=[color=rgba(0, 0, 0, 255), blendMode=kSrcOver, isAntiAlias=false, "
  82. "isDither=false, filterQuality=kNone_SkFilterQuality, strokeWidth=0.000, "
  83. "strokeMiter=4.000, strokeCap=kButt_Cap, strokeJoin=kMiter_Join, "
  84. "colorFilter=(nil), maskFilter=(nil), shader=(nil), "
  85. "hasShader=false, shaderIsOpaque=false, pathEffect=(nil), "
  86. "imageFilter=(nil), drawLooper=(nil), isSimpleOpacity=true, "
  87. "supportsFoldingAlpha=true, isValid=true, hasDiscardableImages=false])");
  88. }
  89. TEST(PaintOpHelper, DrawImageRectToString) {
  90. DrawImageRectOp op(PaintImage(), SkRect::MakeXYWH(1, 2, 3, 4),
  91. SkRect::MakeXYWH(5, 6, 7, 8),
  92. SkCanvas::kStrict_SrcRectConstraint);
  93. std::string str = PaintOpHelper::ToString(&op);
  94. EXPECT_EQ(
  95. str,
  96. "DrawImageRectOp(image=<paint image>, src=[1.000,2.000 3.000x4.000], "
  97. "dst=[5.000,6.000 7.000x8.000], constraint=kStrict_SrcRectConstraint, "
  98. "flags=[color=rgba(0, 0, 0, 255), blendMode=kSrcOver, isAntiAlias=false, "
  99. "isDither=false, filterQuality=kNone_SkFilterQuality, strokeWidth=0.000, "
  100. "strokeMiter=4.000, strokeCap=kButt_Cap, strokeJoin=kMiter_Join, "
  101. "colorFilter=(nil), maskFilter=(nil), shader=(nil), "
  102. "hasShader=false, shaderIsOpaque=false, pathEffect=(nil), "
  103. "imageFilter=(nil), drawLooper=(nil), isSimpleOpacity=true, "
  104. "supportsFoldingAlpha=true, isValid=true, hasDiscardableImages=false])");
  105. }
  106. TEST(PaintOpHelper, DrawIRectToString) {
  107. DrawIRectOp op(SkIRect::MakeXYWH(1, 2, 3, 4), PaintFlags());
  108. std::string str = PaintOpHelper::ToString(&op);
  109. EXPECT_EQ(str,
  110. "DrawIRectOp(rect=[1,2 3x4], flags=[color=rgba(0, 0, 0, 255), "
  111. "blendMode=kSrcOver, isAntiAlias=false, isDither=false, "
  112. "filterQuality=kNone_SkFilterQuality, strokeWidth=0.000, "
  113. "strokeMiter=4.000, strokeCap=kButt_Cap, strokeJoin=kMiter_Join, "
  114. "colorFilter=(nil), maskFilter=(nil), "
  115. "shader=(nil), hasShader=false, shaderIsOpaque=false, "
  116. "pathEffect=(nil), imageFilter=(nil), drawLooper=(nil), "
  117. "isSimpleOpacity=true, supportsFoldingAlpha=true, isValid=true, "
  118. "hasDiscardableImages=false])");
  119. }
  120. TEST(PaintOpHelper, DrawLineToString) {
  121. DrawLineOp op(1.1f, 2.2f, 3.3f, 4.4f, PaintFlags());
  122. std::string str = PaintOpHelper::ToString(&op);
  123. EXPECT_EQ(
  124. str,
  125. "DrawLineOp(x0=1.100, y0=2.200, x1=3.300, y1=4.400, flags=[color=rgba(0, "
  126. "0, 0, 255), blendMode=kSrcOver, isAntiAlias=false, isDither=false, "
  127. "filterQuality=kNone_SkFilterQuality, strokeWidth=0.000, "
  128. "strokeMiter=4.000, strokeCap=kButt_Cap, strokeJoin=kMiter_Join, "
  129. "colorFilter=(nil), maskFilter=(nil), shader=(nil), "
  130. "hasShader=false, shaderIsOpaque=false, pathEffect=(nil), "
  131. "imageFilter=(nil), drawLooper=(nil), isSimpleOpacity=true, "
  132. "supportsFoldingAlpha=true, isValid=true, hasDiscardableImages=false])");
  133. }
  134. TEST(PaintOpHelper, DrawOvalToString) {
  135. DrawOvalOp op(SkRect::MakeXYWH(100, 200, 300, 400), PaintFlags());
  136. std::string str = PaintOpHelper::ToString(&op);
  137. EXPECT_EQ(
  138. str,
  139. "DrawOvalOp(oval=[100.000,200.000 300.000x400.000], flags=[color=rgba(0, "
  140. "0, 0, 255), blendMode=kSrcOver, isAntiAlias=false, isDither=false, "
  141. "filterQuality=kNone_SkFilterQuality, strokeWidth=0.000, "
  142. "strokeMiter=4.000, strokeCap=kButt_Cap, strokeJoin=kMiter_Join, "
  143. "colorFilter=(nil), maskFilter=(nil), shader=(nil), "
  144. "hasShader=false, shaderIsOpaque=false, pathEffect=(nil), "
  145. "imageFilter=(nil), drawLooper=(nil), isSimpleOpacity=true, "
  146. "supportsFoldingAlpha=true, isValid=true, hasDiscardableImages=false])");
  147. }
  148. TEST(PaintOpHelper, DrawPathToString) {
  149. SkPath path;
  150. DrawPathOp op(path, PaintFlags(), UsePaintCache::kDisabled);
  151. std::string str = PaintOpHelper::ToString(&op);
  152. EXPECT_EQ(str,
  153. "DrawPathOp(path=<SkPath>, flags=[color=rgba(0, 0, 0, 255), "
  154. "blendMode=kSrcOver, isAntiAlias=false, isDither=false, "
  155. "filterQuality=kNone_SkFilterQuality, strokeWidth=0.000, "
  156. "strokeMiter=4.000, strokeCap=kButt_Cap, strokeJoin=kMiter_Join, "
  157. "colorFilter=(nil), maskFilter=(nil), "
  158. "shader=(nil), hasShader=false, shaderIsOpaque=false, "
  159. "pathEffect=(nil), imageFilter=(nil), drawLooper=(nil), "
  160. "isSimpleOpacity=true, supportsFoldingAlpha=true, isValid=true, "
  161. "hasDiscardableImages=false], use_cache=false)");
  162. }
  163. TEST(PaintOpHelper, DrawRecordToString) {
  164. DrawRecordOp op(nullptr);
  165. std::string str = PaintOpHelper::ToString(&op);
  166. EXPECT_EQ(str, "DrawRecordOp(record=(nil))");
  167. }
  168. TEST(PaintOpHelper, DrawRectToString) {
  169. DrawRectOp op(SkRect::MakeXYWH(-1, -2, -3, -4), PaintFlags());
  170. std::string str = PaintOpHelper::ToString(&op);
  171. EXPECT_EQ(
  172. str,
  173. "DrawRectOp(rect=[-1.000,-2.000 -3.000x-4.000], flags=[color=rgba(0, 0, "
  174. "0, 255), blendMode=kSrcOver, isAntiAlias=false, "
  175. "isDither=false, filterQuality=kNone_SkFilterQuality, "
  176. "strokeWidth=0.000, strokeMiter=4.000, strokeCap=kButt_Cap, "
  177. "strokeJoin=kMiter_Join, colorFilter=(nil), "
  178. "maskFilter=(nil), shader=(nil), hasShader=false, shaderIsOpaque=false, "
  179. "pathEffect=(nil), imageFilter=(nil), drawLooper=(nil), "
  180. "isSimpleOpacity=true, supportsFoldingAlpha=true, isValid=true, "
  181. "hasDiscardableImages=false])");
  182. }
  183. TEST(PaintOpHelper, DrawRRectToString) {
  184. DrawRRectOp op(SkRRect::MakeRect(SkRect::MakeXYWH(-1, -2, 3, 4)),
  185. PaintFlags());
  186. std::string str = PaintOpHelper::ToString(&op);
  187. EXPECT_EQ(
  188. str,
  189. "DrawRRectOp(rrect=[bounded by -1.000,-2.000 3.000x4.000], "
  190. "flags=[color=rgba(0, 0, 0, 255), blendMode=kSrcOver, isAntiAlias=false, "
  191. "isDither=false, filterQuality=kNone_SkFilterQuality, strokeWidth=0.000, "
  192. "strokeMiter=4.000, strokeCap=kButt_Cap, strokeJoin=kMiter_Join, "
  193. "colorFilter=(nil), maskFilter=(nil), shader=(nil), "
  194. "hasShader=false, shaderIsOpaque=false, pathEffect=(nil), "
  195. "imageFilter=(nil), drawLooper=(nil), isSimpleOpacity=true, "
  196. "supportsFoldingAlpha=true, isValid=true, hasDiscardableImages=false])");
  197. }
  198. TEST(PaintOpHelper, DrawTextBlobToString) {
  199. DrawTextBlobOp op(nullptr, 100, -222, PaintFlags());
  200. std::string str = PaintOpHelper::ToString(&op);
  201. EXPECT_EQ(
  202. str,
  203. "DrawTextBlobOp(blob=(nil), x=100.000, y=-222.000, flags=[color=rgba(0, "
  204. "0, 0, 255), blendMode=kSrcOver, isAntiAlias=false, isDither=false, "
  205. "filterQuality=kNone_SkFilterQuality, strokeWidth=0.000, "
  206. "strokeMiter=4.000, strokeCap=kButt_Cap, strokeJoin=kMiter_Join, "
  207. "colorFilter=(nil), maskFilter=(nil), shader=(nil), "
  208. "hasShader=false, shaderIsOpaque=false, pathEffect=(nil), "
  209. "imageFilter=(nil), drawLooper=(nil), isSimpleOpacity=true, "
  210. "supportsFoldingAlpha=true, isValid=true, hasDiscardableImages=false])");
  211. }
  212. TEST(PaintOpHelper, NoopToString) {
  213. NoopOp op;
  214. std::string str = PaintOpHelper::ToString(&op);
  215. EXPECT_EQ(str, "NoopOp()");
  216. }
  217. TEST(PaintOpHelper, RestoreToString) {
  218. RestoreOp op;
  219. std::string str = PaintOpHelper::ToString(&op);
  220. EXPECT_EQ(str, "RestoreOp()");
  221. }
  222. TEST(PaintOpHelper, RotateToString) {
  223. RotateOp op(360);
  224. std::string str = PaintOpHelper::ToString(&op);
  225. EXPECT_EQ(str, "RotateOp(degrees=360.000)");
  226. }
  227. TEST(PaintOpHelper, SaveToString) {
  228. SaveOp op;
  229. std::string str = PaintOpHelper::ToString(&op);
  230. EXPECT_EQ(str, "SaveOp()");
  231. }
  232. TEST(PaintOpHelper, SaveLayerToString) {
  233. SkRect bounds = SkRect::MakeXYWH(1, 2, 3, 4);
  234. SaveLayerOp op(&bounds, nullptr);
  235. std::string str = PaintOpHelper::ToString(&op);
  236. EXPECT_EQ(
  237. str,
  238. "SaveLayerOp(bounds=[1.000,2.000 3.000x4.000], flags=[color=rgba(0, 0, "
  239. "0, 255), blendMode=kSrcOver, isAntiAlias=false, isDither=false, "
  240. "filterQuality=kNone_SkFilterQuality, "
  241. "strokeWidth=0.000, strokeMiter=4.000, strokeCap=kButt_Cap, "
  242. "strokeJoin=kMiter_Join, colorFilter=(nil), "
  243. "maskFilter=(nil), shader=(nil), hasShader=false, shaderIsOpaque=false, "
  244. "pathEffect=(nil), imageFilter=(nil), drawLooper=(nil), "
  245. "isSimpleOpacity=true, supportsFoldingAlpha=true, isValid=true, "
  246. "hasDiscardableImages=false])");
  247. }
  248. TEST(PaintOpHelper, SaveLayerAlphaToString) {
  249. SkRect bounds = SkRect::MakeXYWH(1, 2, 3, 4);
  250. SaveLayerAlphaOp op(&bounds, 1.0f);
  251. std::string str = PaintOpHelper::ToString(&op);
  252. EXPECT_EQ(str,
  253. "SaveLayerAlphaOp(bounds=[1.000,2.000 3.000x4.000], alpha=255)");
  254. }
  255. TEST(PaintOpHelper, ScaleToString) {
  256. ScaleOp op(12, 13.9f);
  257. std::string str = PaintOpHelper::ToString(&op);
  258. EXPECT_EQ(str, "ScaleOp(sx=12.000, sy=13.900)");
  259. }
  260. TEST(PaintOpHelper, SetMatrixToString) {
  261. SetMatrixOp op(SkM44(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16));
  262. std::string str = PaintOpHelper::ToString(&op);
  263. EXPECT_EQ(str,
  264. "SetMatrixOp(matrix=[ 1.0000 2.0000 3.0000 4.0000][ 5.0000 "
  265. " 6.0000 7.0000 8.0000][ 9.0000 10.0000 11.0000 12.0000][ "
  266. "13.0000 14.0000 15.0000 16.0000]])");
  267. }
  268. TEST(PaintOpHelper, TranslateToString) {
  269. TranslateOp op(0, 0);
  270. std::string str = PaintOpHelper::ToString(&op);
  271. EXPECT_EQ(str, "TranslateOp(dx=0.000, dy=0.000)");
  272. }
  273. } // namespace
  274. } // namespace cc