skia2/gm/copyTo4444.cpp
Chris Dalton 50e24d7d5f Add a mechanism for GMs to silently exclude themselves from Gold
This is useful, for example, when trying to test a hardware feature
that isn't supported in the current context.

Bug: skia:8731
Change-Id: I9a363159300c92e4039bfd05400238c27002efb1
Reviewed-on: https://skia-review.googlesource.com/c/189133
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
2019-02-08 00:05:15 +00:00

81 lines
2.2 KiB
C++

/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "gm.h"
#include "sk_tool_utils.h"
#include "Resources.h"
#include "SkCanvas.h"
#include "SkOSFile.h"
namespace skiagm {
/**
* Test copying an image from 8888 to 4444.
*/
class CopyTo4444GM : public GM {
public:
CopyTo4444GM() {}
protected:
virtual SkString onShortName() {
return SkString("copyTo4444");
}
virtual SkISize onISize() {
return SkISize::Make(360, 180);
}
DrawResult onDraw(SkCanvas* canvas, SkString* errorMsg) {
SkBitmap bm, bm4444;
if (!GetResourceAsBitmap("images/dog.jpg", &bm)) {
*errorMsg = "Could not decode the file. Did you forget to set the resourcePath?";
return DrawResult::kFail;
}
canvas->drawBitmap(bm, 0, 0);
// This should dither or we will see artifacts in the background of the image.
SkAssertResult(sk_tool_utils::copy_to(&bm4444, kARGB_4444_SkColorType, bm));
canvas->drawBitmap(bm4444, SkIntToScalar(bm.width()), 0);
return DrawResult::kOk;
}
private:
typedef GM INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
DEF_GM( return new CopyTo4444GM; )
}
DEF_SIMPLE_GM(format4444, canvas, 64, 64) {
canvas->scale(16, 16);
SkBitmap bitmap;
SkImageInfo imageInfo = SkImageInfo::Make(1, 1, kARGB_4444_SkColorType, kPremul_SkAlphaType);
bitmap.allocPixels(imageInfo);
SkCanvas offscreen(bitmap);
offscreen.clear(SK_ColorRED);
canvas->drawBitmap(bitmap, 0, 0);
offscreen.clear(SK_ColorBLUE);
canvas->drawBitmap(bitmap, 1, 1);
auto pack4444 = [](unsigned a, unsigned r, unsigned g, unsigned b) -> uint16_t {
return (a << 0) | (b << 4) | (g << 8) | (r << 12);
};
uint16_t red4444 = pack4444(0xF, 0xF, 0x0, 0x0);
uint16_t blue4444 = pack4444(0xF, 0x0, 0x0, 0x0F);
SkPixmap redPixmap(imageInfo, &red4444, 2);
if (bitmap.writePixels(redPixmap, 0, 0)) {
canvas->drawBitmap(bitmap, 2, 2);
}
SkPixmap bluePixmap(imageInfo, &blue4444, 2);
if (bitmap.writePixels(bluePixmap, 0, 0)) {
canvas->drawBitmap(bitmap, 3, 3);
}
}