skia2/tests/ImageIsOpaqueTest.cpp
Cary Clark 3b68882918 remove imageinfo flatten altogether
If SkImageInfo flatten and unflatten aren't referenced outside
of one test, perhaps they can be removed altogether.

R=reed@google.com

Bug: skia:6898
Change-Id: Ia6f82b66d4496a628ad95c386d1865793f3e31a9
Reviewed-on: https://skia-review.googlesource.com/115074
Commit-Queue: Cary Clark <caryclark@skia.org>
Reviewed-by: Mike Reed <reed@google.com>
2018-03-19 21:28:46 +00:00

85 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"
#if SK_SUPPORT_GPU
#include "GrContext.h"
#endif
#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);
}
#if SK_SUPPORT_GPU
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);
}
#endif
///////////////////////////////////////////////////////////////////////////////////////////////////
#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);
}