Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(320)

Unified Diff: samplecode/SampleFilterFuzz.cpp

Issue 169063002: use SkColorType instead of SkBitmap::Config in samplecode (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « samplecode/SampleFilter2.cpp ('k') | samplecode/SampleFontCache.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samplecode/SampleFilterFuzz.cpp
diff --git a/samplecode/SampleFilterFuzz.cpp b/samplecode/SampleFilterFuzz.cpp
index 4ef7d4033a897b0ed4cffa29a092f3d437991db5..f753b503049c8f346f9cd5b000306bbcae615b9b 100644
--- a/samplecode/SampleFilterFuzz.cpp
+++ b/samplecode/SampleFilterFuzz.cpp
@@ -111,13 +111,36 @@ static SkDisplacementMapEffect::ChannelSelectorType make_channel_selector_type()
return static_cast<SkDisplacementMapEffect::ChannelSelectorType>(R(4)+1);
}
-static void make_g_bitmap(SkBitmap& bitmap) {
- bitmap.setConfig((SkBitmap::Config)R(SkBitmap::kConfigCount), kBitmapSize, kBitmapSize);
- while (!bitmap.allocPixels()) {
- bitmap.setConfig((SkBitmap::Config)R(SkBitmap::kConfigCount), kBitmapSize, kBitmapSize);
+static bool valid_for_raster_canvas(const SkImageInfo& info) {
+ switch (info.colorType()) {
+ case kAlpha_8_SkColorType:
+ case kRGB_565_SkColorType:
+ return true;
+ case kPMColor_SkColorType:
+ return kPremul_SkAlphaType == info.alphaType() ||
+ kOpaque_SkAlphaType == info.alphaType();
+ default:
+ break;
}
- SkBitmapDevice device(bitmap);
- SkCanvas canvas(&device);
+ return false;
+}
+
+static SkColorType rand_colortype() {
+ return (SkColorType)R(kLastEnum_SkColorType + 1);
+}
+
+static void rand_bitmap_for_canvas(SkBitmap* bitmap) {
+ SkImageInfo info;
+ do {
+ info = SkImageInfo::Make(kBitmapSize, kBitmapSize, rand_colortype(),
+ kPremul_SkAlphaType);
+ } while (!valid_for_raster_canvas(info) || !bitmap->allocPixels(info));
+}
+
+static void make_g_bitmap(SkBitmap& bitmap) {
+ rand_bitmap_for_canvas(&bitmap);
+
+ SkCanvas canvas(bitmap);
canvas.clear(0x00000000);
SkPaint paint;
paint.setAntiAlias(true);
@@ -128,31 +151,10 @@ static void make_g_bitmap(SkBitmap& bitmap) {
SkIntToScalar(kBitmapSize/4), paint);
}
-static bool valid_for_raster_canvas(const SkBitmap& bm) {
- SkImageInfo info;
- if (!bm.asImageInfo(&info)) {
- return false;
- }
- switch (info.fColorType) {
- case kAlpha_8_SkColorType:
- case kRGB_565_SkColorType:
- return true;
- case kPMColor_SkColorType:
- return kPremul_SkAlphaType == info.fAlphaType ||
- kOpaque_SkAlphaType == info.fAlphaType;
- default:
- break;
- }
- return false;
-}
-
static void make_checkerboard_bitmap(SkBitmap& bitmap) {
- bitmap.setConfig((SkBitmap::Config)R(SkBitmap::kConfigCount), kBitmapSize, kBitmapSize);
- while (valid_for_raster_canvas(bitmap) && !bitmap.allocPixels()) {
- bitmap.setConfig((SkBitmap::Config)R(SkBitmap::kConfigCount), kBitmapSize, kBitmapSize);
- }
- SkBitmapDevice device(bitmap);
- SkCanvas canvas(&device);
+ rand_bitmap_for_canvas(&bitmap);
+
+ SkCanvas canvas(bitmap);
canvas.clear(0x00000000);
SkPaint darkPaint;
darkPaint.setColor(0xFF804020);
« no previous file with comments | « samplecode/SampleFilter2.cpp ('k') | samplecode/SampleFontCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698