5e8f45faf1
This updates all our callsites in preparation for removing the #include "include/core/SkColorSpace.h" from SkImageInfo.h According to go/chrome-includes [1], this will save ~150MB (0.07%) from the compilation size. I think SkColorSpace is a big include because it loads the skcms header, which is big. The follow-on CL will remove that link, once clients have been updated as well. [1] https://commondatastorage.googleapis.com/chromium-browser-clang/chrome_includes_2022-03-31_124042.html#view=edges&filter=%5Ethird_party%2Fskia%2Finclude%2Fcore%2FSkImageInfo%5C.h%24&sort=asize&reverse=&includer=%5Ethird_party%2Fskia%2Finclude%2Fcore%2FSkImageInfo%5C.h%24&included=&limit=1000 Change-Id: I1b5ff491ac495317b0e5af3a2082b080d43697ae Bug: skia:13052 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/525639 Reviewed-by: Robert Phillips <robertphillips@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com> Reviewed-by: Florin Malita <fmalita@google.com> Commit-Queue: Kevin Lubick <kjlubick@google.com>
103 lines
3.8 KiB
C++
103 lines
3.8 KiB
C++
/*
|
|
* Copyright 2022 Google LLC
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
#include "include/core/SkColorSpace.h"
|
|
#include "include/core/SkSurface.h"
|
|
#include "include/gpu/GrDirectContext.h"
|
|
#include "tests/Test.h"
|
|
#include "tests/TestUtils.h"
|
|
|
|
static void check_pixels(skiatest::Reporter* reporter, const SkBitmap& bitmap,
|
|
GrSurfaceOrigin origin) {
|
|
const uint32_t* canvasPixels = static_cast<const uint32_t*>(bitmap.getPixels());
|
|
|
|
bool failureFound = false;
|
|
bool foundNonBlue = false;
|
|
|
|
for (int cy = 0; cy < 8 && !failureFound; ++cy) {
|
|
int cx = 4; // Just need to check one column;
|
|
SkPMColor canvasPixel = canvasPixels[cy * 8 + cx];
|
|
// We don't know which way the GPU will snap so the non-blue line could either be at row
|
|
// 3 or 4 since we drew the line at a y value of 4. We check that one of those two values
|
|
// is green and all the rest are blue. The key thing is that we should not get any red
|
|
// values since the green line in the saveLayer should snap the same way and overwrite the
|
|
// red line.
|
|
if (cy == 3) {
|
|
if (canvasPixel != 0xFFFF0000 && canvasPixel != 0xFF00FF00) {
|
|
failureFound = true;
|
|
ERRORF(reporter, "Wrong color at %d, %d. Got 0x%08x when we expected Blue or Green."
|
|
" Origin is: %s",
|
|
cx, cy, canvasPixel, GrSurfaceOriginToStr(origin));
|
|
}
|
|
if (canvasPixel != 0XFFFF0000) {
|
|
foundNonBlue = true;
|
|
}
|
|
} else {
|
|
SkPMColor expectedPixel;
|
|
if (cy == 4 && !foundNonBlue) {
|
|
expectedPixel = 0xFF00FF00; // Green
|
|
} else {
|
|
expectedPixel = 0xFFFF0000; // Blue
|
|
}
|
|
if (canvasPixel != expectedPixel) {
|
|
failureFound = true;
|
|
ERRORF(reporter,
|
|
"Wrong color at %d, %d. Got 0x%08x when we expected 0x%08x. Origin is: %s",
|
|
cx, cy, canvasPixel, expectedPixel, GrSurfaceOriginToStr(origin));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
static void run_test(skiatest::Reporter* reporter,
|
|
GrDirectContext* context,
|
|
GrSurfaceOrigin origin) {
|
|
auto beTexture = context->createBackendTexture(8, 8, kRGBA_8888_SkColorType, GrMipMapped::kNo,
|
|
GrRenderable::kYes, GrProtected::kNo);
|
|
REPORTER_ASSERT(reporter, beTexture.isValid());
|
|
if (!beTexture.isValid()) {
|
|
return;
|
|
}
|
|
|
|
auto surface = SkSurface::MakeFromBackendTexture(context, beTexture, origin, 0,
|
|
kRGBA_8888_SkColorType, nullptr, nullptr);
|
|
REPORTER_ASSERT(reporter, surface);
|
|
if (!surface) {
|
|
return;
|
|
}
|
|
|
|
SkCanvas* canvas = surface->getCanvas();
|
|
|
|
canvas->clear(SK_ColorBLUE);
|
|
|
|
SkPaint paint;
|
|
paint.setColor(SK_ColorRED);
|
|
canvas->drawLine({ 0,4 }, { 8,4 }, paint);
|
|
|
|
SkRect bounds = SkRect::MakeWH(8, 8);
|
|
SkPaint layerPaint;
|
|
canvas->saveLayer(bounds, &paint);
|
|
paint.setColor(SK_ColorGREEN);
|
|
canvas->drawLine({ 0,4 }, { 8,4 }, paint);
|
|
canvas->restore();
|
|
|
|
SkBitmap bitmap;
|
|
bitmap.allocPixels(SkImageInfo::Make(8, 8, kRGBA_8888_SkColorType, kPremul_SkAlphaType));
|
|
surface->readPixels(bitmap, 0, 0);
|
|
|
|
check_pixels(reporter, bitmap, origin);
|
|
|
|
context->deleteBackendTexture(beTexture);
|
|
}
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SaveLayerOrigin, reporter, context_info) {
|
|
GrDirectContext* context = context_info.directContext();
|
|
run_test(reporter, context, kBottomLeft_GrSurfaceOrigin);
|
|
run_test(reporter, context, kTopLeft_GrSurfaceOrigin);
|
|
}
|