OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkShader.h" | 10 #include "SkShader.h" |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 y0 = 0; | 284 y0 = 0; |
285 } | 285 } |
286 } | 286 } |
287 s->unref(); | 287 s->unref(); |
288 } | 288 } |
289 | 289 |
290 private: | 290 private: |
291 typedef GM INHERITED; | 291 typedef GM INHERITED; |
292 }; | 292 }; |
293 DEF_GM( return new XfermodesGM; ) | 293 DEF_GM( return new XfermodesGM; ) |
294 | |
295 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | |
296 | |
297 void draw_mode(const SkBitmap& srcB, const SkBitmap& dstB, | |
298 SkCanvas* canvas, SkXfermode* mode, SkScalar x, SkScalar y, float
src_alpha) { | |
299 canvas->saveLayer(SkRect::MakeXYWH(x, y, 64, 64), nullptr); | |
300 canvas->drawBitmap(srcB, x, y, nullptr); | |
301 | |
302 SkPaint paint; | |
303 paint.setXfermode(mode); | |
304 canvas->drawBitmap(dstB, x, y, &paint); | |
305 | |
306 canvas->restore(); | |
307 } | |
308 | |
309 DEF_SIMPLE_GM(xfermodes_proc4f, canvas, 1000, 1000) { | |
310 SkBitmap bg, srcB, dstB, transparent; | |
311 | |
312 bg.installPixels(SkImageInfo::Make(2, 2, kARGB_4444_SkColorType, kOpaque_SkA
lphaType), | |
313 gData, 4); | |
314 make_bitmaps(64, 64, &dstB, &srcB, &transparent); | |
315 | |
316 canvas->translate(10, 20); | |
317 | |
318 const SkScalar w = 64; | |
319 const SkScalar h = 64; | |
320 SkMatrix m = SkMatrix::MakeScale(6, 6); | |
321 SkShader* s = SkShader::CreateBitmapShader(bg, | |
322 SkShader::kRepeat_TileMode, | |
323 SkShader::kRepeat_TileMode, | |
324 &m); | |
325 | |
326 SkPaint labelP; | |
327 labelP.setAntiAlias(true); | |
328 sk_tool_utils::set_portable_typeface(&labelP); | |
329 labelP.setTextAlign(SkPaint::kCenter_Align); | |
330 | |
331 const int W = 5; | |
332 | |
333 const float alphas[] = { 1.0f, 0.5f }; | |
334 | |
335 for (auto alpha : alphas) { | |
336 SkScalar x0 = 0; | |
337 SkScalar y0 = 0; | |
338 SkScalar x = x0, y = y0; | |
339 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) { | |
340 SkXfermode* mode = SkXfermode::Create(gModes[i].fMode); | |
341 SkAutoUnref aur(mode); | |
342 SkRect r; | |
343 r.set(x, y, x+w, y+h); | |
344 | |
345 SkPaint p; | |
346 p.setStyle(SkPaint::kFill_Style); | |
347 p.setShader(s); | |
348 canvas->drawRect(r, p); | |
349 | |
350 draw_mode(srcB, dstB, canvas, mode, r.fLeft, r.fTop, alpha); | |
351 | |
352 r.inset(-SK_ScalarHalf, -SK_ScalarHalf); | |
353 p.setStyle(SkPaint::kStroke_Style); | |
354 p.setShader(nullptr); | |
355 canvas->drawRect(r, p); | |
356 | |
357 #if 1 | |
358 canvas->drawText(gModes[i].fLabel, strlen(gModes[i].fLabel), | |
359 x + w/2, y - labelP.getTextSize()/2, labelP); | |
360 #endif | |
361 x += w + SkIntToScalar(10); | |
362 if ((i % W) == W - 1) { | |
363 x = x0; | |
364 y += h + SkIntToScalar(30); | |
365 } | |
366 } | |
367 if (y < 320) { | |
368 if (x > x0) { | |
369 y += h + SkIntToScalar(30); | |
370 } | |
371 y0 = y; | |
372 } else { | |
373 x0 += SkIntToScalar(400); | |
374 y0 = 0; | |
375 } | |
376 | |
377 canvas->translate(400, 0); | |
378 } | |
379 s->unref(); | |
380 } | |
OLD | NEW |