skia2/tests/ImageIsOpaqueTest.cpp
Brian Osman c7ad40f76f Remove SK_SUPPORT_GPU checks in tool-only code
Most of this is (obviously) not necessary to do, but once
I started, I figured I'd just get it all. Tools (nanobench,
DM, skiaserve), all GMs, benches, and unit tests, plus support
code (command line parsing and config stuff).

This is almost entirely mechanical.

Bug: skia:
Change-Id: I209500f8df8c5bd43f8298ff26440d1c4d7425fb
Reviewed-on: https://skia-review.googlesource.com/131153
Reviewed-by: Mike Klein <mtklein@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2018-05-31 18:59:44 +00:00

79 lines
2.7 KiB
C++

/*
* Copyright 2014 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkTypes.h"
#include "Resources.h"
#include "Test.h"
#include "GrContext.h"
#include "SkCanvas.h"
#include "SkImage.h"
#include "SkSurface.h"
#include "SkReadBuffer.h"
#include "SkWriteBuffer.h"
static void check_isopaque(skiatest::Reporter* reporter, const sk_sp<SkSurface>& surface,
bool expectedOpaque) {
sk_sp<SkImage> image(surface->makeImageSnapshot());
REPORTER_ASSERT(reporter, image->isOpaque() == expectedOpaque);
}
DEF_TEST(ImageIsOpaqueTest, reporter) {
SkImageInfo infoTransparent = SkImageInfo::MakeN32Premul(5, 5);
auto surfaceTransparent(SkSurface::MakeRaster(infoTransparent));
check_isopaque(reporter, surfaceTransparent, false);
SkImageInfo infoOpaque = SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType);
auto surfaceOpaque(SkSurface::MakeRaster(infoOpaque));
check_isopaque(reporter, surfaceOpaque, true);
}
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageIsOpaqueTest_Gpu, reporter, ctxInfo) {
GrContext* context = ctxInfo.grContext();
SkImageInfo infoTransparent = SkImageInfo::MakeN32Premul(5, 5);
auto surfaceTransparent(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, infoTransparent));
check_isopaque(reporter, surfaceTransparent, false);
SkImageInfo infoOpaque = SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType);
auto surfaceOpaque(SkSurface::MakeRenderTarget(context,SkBudgeted::kNo, infoOpaque));
check_isopaque(reporter, surfaceOpaque, true);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
#include "SkPictureRecorder.h"
static sk_sp<SkPicture> make_picture() {
SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording({ 0, 0, 10, 10 });
canvas->drawColor(SK_ColorRED);
return recorder.finishRecordingAsPicture();
}
DEF_TEST(Image_isAlphaOnly, reporter) {
SkPMColor pmColors = 0;
SkPixmap pmap = {
SkImageInfo::MakeN32Premul(1, 1),
&pmColors,
sizeof(pmColors)
};
for (auto& image : {
SkImage::MakeRasterCopy(pmap),
GetResourceAsImage("images/mandrill_128.png"),
GetResourceAsImage("images/color_wheel.jpg"),
SkImage::MakeFromPicture(make_picture(), { 10, 10 }, nullptr, nullptr,
SkImage::BitDepth::kU8,
SkColorSpace::MakeSRGB()),
})
{
REPORTER_ASSERT(reporter, image->isAlphaOnly() == false);
}
REPORTER_ASSERT(reporter, SkImage::MakeRasterCopy({
SkImageInfo::MakeA8(1, 1), (uint8_t*)&pmColors, 1})->isAlphaOnly() == true);
}