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=87f55e62ec4c3535e1a5d0f1415b20c6 5cb93a386Sopenharmony_ciREG_FIDDLE(Canvas_MakeRasterDirectN32, 256, 256, true, 0) { 6cb93a386Sopenharmony_civoid draw(SkCanvas* ) { 7cb93a386Sopenharmony_ci const int width = 3; 8cb93a386Sopenharmony_ci const int height = 3; 9cb93a386Sopenharmony_ci SkPMColor pixels[height][width]; // allocate a 3 by 3 Premultiplied bitmap on the stack 10cb93a386Sopenharmony_ci // create a SkCanvas backed by a raster device, and delete it when the 11cb93a386Sopenharmony_ci // function goes out of scope. 12cb93a386Sopenharmony_ci std::unique_ptr<SkCanvas> canvas = SkCanvas::MakeRasterDirectN32( 13cb93a386Sopenharmony_ci width, 14cb93a386Sopenharmony_ci height, 15cb93a386Sopenharmony_ci pixels[0], // top-left of the bitmap 16cb93a386Sopenharmony_ci sizeof(pixels[0])); // byte width of the each row 17cb93a386Sopenharmony_ci // write a Premultiplied value for white into all pixels in the bitmap 18cb93a386Sopenharmony_ci canvas->clear(SK_ColorWHITE); 19cb93a386Sopenharmony_ci SkPMColor pmWhite = pixels[0][0]; // the Premultiplied format may vary 20cb93a386Sopenharmony_ci SkPaint paint; // by default, draws black 21cb93a386Sopenharmony_ci canvas->drawPoint(1, 1, paint); // draw in the center 22cb93a386Sopenharmony_ci canvas->flush(); // ensure that pixels is ready to be read 23cb93a386Sopenharmony_ci for (int y = 0; y < height; ++y) { 24cb93a386Sopenharmony_ci for (int x = 0; x < width; ++x) { 25cb93a386Sopenharmony_ci SkDebugf("%c", pixels[y][x] == pmWhite ? '-' : 'x'); 26cb93a386Sopenharmony_ci } 27cb93a386Sopenharmony_ci SkDebugf("\n"); 28cb93a386Sopenharmony_ci } 29cb93a386Sopenharmony_ci} 30cb93a386Sopenharmony_ci} // END FIDDLE 31