2014-08-19 21:29:02 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkTypes.h"
|
|
|
|
#include "tests/Test.h"
|
|
|
|
#include "tools/Resources.h"
|
2014-11-10 16:57:21 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkImage.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
|
|
|
#include "include/gpu/GrContext.h"
|
|
|
|
#include "src/core/SkReadBuffer.h"
|
|
|
|
#include "src/core/SkWriteBuffer.h"
|
2014-08-19 21:29:02 +00:00
|
|
|
|
2016-03-24 01:59:25 +00:00
|
|
|
static void check_isopaque(skiatest::Reporter* reporter, const sk_sp<SkSurface>& surface,
|
|
|
|
bool expectedOpaque) {
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> image(surface->makeImageSnapshot());
|
2014-08-20 14:24:01 +00:00
|
|
|
REPORTER_ASSERT(reporter, image->isOpaque() == expectedOpaque);
|
|
|
|
}
|
|
|
|
|
2014-08-19 21:29:02 +00:00
|
|
|
DEF_TEST(ImageIsOpaqueTest, reporter) {
|
|
|
|
SkImageInfo infoTransparent = SkImageInfo::MakeN32Premul(5, 5);
|
2016-03-24 01:59:25 +00:00
|
|
|
auto surfaceTransparent(SkSurface::MakeRaster(infoTransparent));
|
2014-08-20 14:24:01 +00:00
|
|
|
check_isopaque(reporter, surfaceTransparent, false);
|
2014-08-19 21:29:02 +00:00
|
|
|
|
|
|
|
SkImageInfo infoOpaque = SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType);
|
2016-03-24 01:59:25 +00:00
|
|
|
auto surfaceOpaque(SkSurface::MakeRaster(infoOpaque));
|
2014-08-20 14:24:01 +00:00
|
|
|
check_isopaque(reporter, surfaceOpaque, true);
|
2014-08-19 21:29:02 +00:00
|
|
|
}
|
|
|
|
|
2016-06-28 15:07:26 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageIsOpaqueTest_Gpu, reporter, ctxInfo) {
|
2016-05-11 13:33:06 +00:00
|
|
|
GrContext* context = ctxInfo.grContext();
|
2015-12-01 12:35:26 +00:00
|
|
|
SkImageInfo infoTransparent = SkImageInfo::MakeN32Premul(5, 5);
|
2016-03-24 01:59:25 +00:00
|
|
|
auto surfaceTransparent(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, infoTransparent));
|
2015-12-01 12:35:26 +00:00
|
|
|
check_isopaque(reporter, surfaceTransparent, false);
|
2014-08-19 21:29:02 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
SkImageInfo infoOpaque = SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType);
|
2016-03-24 01:59:25 +00:00
|
|
|
auto surfaceOpaque(SkSurface::MakeRenderTarget(context,SkBudgeted::kNo, infoOpaque));
|
2015-10-01 16:49:25 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
check_isopaque(reporter, surfaceOpaque, true);
|
2014-08-19 21:29:02 +00:00
|
|
|
}
|
|
|
|
|
2016-10-31 12:27:28 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkPictureRecorder.h"
|
2016-10-31 12:27:28 +00:00
|
|
|
|
|
|
|
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),
|
2017-12-08 15:21:31 +00:00
|
|
|
GetResourceAsImage("images/mandrill_128.png"),
|
|
|
|
GetResourceAsImage("images/color_wheel.jpg"),
|
2016-12-16 16:55:18 +00:00
|
|
|
SkImage::MakeFromPicture(make_picture(), { 10, 10 }, nullptr, nullptr,
|
2017-01-09 17:38:59 +00:00
|
|
|
SkImage::BitDepth::kU8,
|
2017-02-07 18:56:11 +00:00
|
|
|
SkColorSpace::MakeSRGB()),
|
2016-10-31 12:27:28 +00:00
|
|
|
})
|
|
|
|
{
|
|
|
|
REPORTER_ASSERT(reporter, image->isAlphaOnly() == false);
|
|
|
|
}
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, SkImage::MakeRasterCopy({
|
|
|
|
SkImageInfo::MakeA8(1, 1), (uint8_t*)&pmColors, 1})->isAlphaOnly() == true);
|
|
|
|
}
|