1cb93a386Sopenharmony_ci// Copyright 2019 Google LLC. 2cb93a386Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. 3cb93a386Sopenharmony_ci#include "tools/fiddle/examples.h" 4cb93a386Sopenharmony_ci// HASH=de9be45255e48fae445c916a41063abc 5cb93a386Sopenharmony_ciREG_FIDDLE(Bitmap_swap, 256, 256, true, 0) { 6cb93a386Sopenharmony_civoid draw(SkCanvas* canvas) { 7cb93a386Sopenharmony_ci auto debugster = [](const char* prefix, const SkBitmap& b) -> void { 8cb93a386Sopenharmony_ci const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"}; 9cb93a386Sopenharmony_ci const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", 10cb93a386Sopenharmony_ci "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16Norm", 11cb93a386Sopenharmony_ci "RGBA_F16"}; 12cb93a386Sopenharmony_ci SkDebugf("%s width:%d height:%d colorType:k%s_SkColorType alphaType:k%s_SkAlphaType\n", 13cb93a386Sopenharmony_ci prefix, b.width(), b.height(), colors[b.colorType()], alphas[b.alphaType()]); 14cb93a386Sopenharmony_ci }; 15cb93a386Sopenharmony_ci SkBitmap one, two; 16cb93a386Sopenharmony_ci if (!one.tryAllocPixels( 17cb93a386Sopenharmony_ci SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kOpaque_SkAlphaType))) { 18cb93a386Sopenharmony_ci return; 19cb93a386Sopenharmony_ci } 20cb93a386Sopenharmony_ci if (!two.tryAllocPixels( 21cb93a386Sopenharmony_ci SkImageInfo::Make(2, 2, kBGRA_8888_SkColorType, kPremul_SkAlphaType))) { 22cb93a386Sopenharmony_ci return; 23cb93a386Sopenharmony_ci } 24cb93a386Sopenharmony_ci for (int index = 0; index < 2; ++index) { 25cb93a386Sopenharmony_ci debugster("one", one); 26cb93a386Sopenharmony_ci debugster("two", two); 27cb93a386Sopenharmony_ci one.swap(two); 28cb93a386Sopenharmony_ci } 29cb93a386Sopenharmony_ci} 30cb93a386Sopenharmony_ci} // END FIDDLE 31