2017-02-06 21:48:57 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 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 "gm/gm.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
2020-07-01 16:55:01 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
|
|
|
#include "include/gpu/GrRecordingContext.h"
|
2017-02-06 21:48:57 +00:00
|
|
|
|
|
|
|
// This test exercises Ganesh's drawing of tiled bitmaps. In particular, that the offsets and the
|
|
|
|
// extents of the tiles don't causes gaps between tiles.
|
2021-07-21 19:39:51 +00:00
|
|
|
static void draw_tile_bitmap_with_fractional_offset(GrRecordingContext* rContext,
|
2020-06-29 19:36:12 +00:00
|
|
|
SkCanvas* canvas,
|
2019-02-07 22:23:36 +00:00
|
|
|
bool vertical) {
|
2017-02-06 21:48:57 +00:00
|
|
|
// This should match kBmpSmallTileSize in SkGpuDevice.cpp. Note that our canvas size is tuned
|
|
|
|
// to this constant as well.
|
|
|
|
const int kTileSize = 1 << 10;
|
|
|
|
|
|
|
|
// We're going to draw a section of the bitmap that intersects 3 tiles (3x1 or 1x3).
|
|
|
|
// We need that to be < 50% of the total image, so our image is 7 tiles (7x1 or 1x7).
|
|
|
|
const int kBitmapLongEdge = 7 * kTileSize;
|
|
|
|
const int kBitmapShortEdge = 1 * kTileSize;
|
|
|
|
|
2021-07-21 19:39:51 +00:00
|
|
|
if (auto dContext = rContext->asDirectContext()) {
|
2020-06-26 12:08:22 +00:00
|
|
|
// To trigger tiling, we also need the image to be more than 50% of the cache, so we
|
|
|
|
// ensure the cache is sized to make that true.
|
|
|
|
const int kBitmapArea = kBitmapLongEdge * kBitmapShortEdge;
|
|
|
|
const size_t kBitmapBytes = kBitmapArea * sizeof(SkPMColor);
|
2017-02-06 21:48:57 +00:00
|
|
|
|
2020-06-26 12:08:22 +00:00
|
|
|
const size_t newMaxResourceBytes = kBitmapBytes + (kBitmapBytes / 2);
|
2021-07-21 19:39:51 +00:00
|
|
|
dContext->setResourceCacheLimit(newMaxResourceBytes);
|
2020-06-26 12:08:22 +00:00
|
|
|
}
|
2017-02-06 21:48:57 +00:00
|
|
|
|
|
|
|
// Construct our bitmap as either very wide or very tall
|
|
|
|
SkBitmap bmp;
|
|
|
|
bmp.allocN32Pixels(vertical ? kBitmapShortEdge : kBitmapLongEdge,
|
|
|
|
vertical ? kBitmapLongEdge : kBitmapShortEdge, true);
|
|
|
|
bmp.eraseColor(SK_ColorWHITE);
|
|
|
|
|
|
|
|
// Draw ten strips with varying fractional offset to catch any rasterization issues with tiling
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
|
|
float offset = i * 0.1f;
|
|
|
|
if (vertical) {
|
2021-01-25 00:49:21 +00:00
|
|
|
canvas->drawImageRect(bmp.asImage(),
|
|
|
|
SkRect::MakeXYWH(0, (kTileSize - 50) + offset, 32, 1124.0f),
|
|
|
|
SkRect::MakeXYWH(37.0f * i, 0.0f, 32.0f, 1124.0f),
|
|
|
|
SkSamplingOptions(), nullptr,
|
|
|
|
SkCanvas::kStrict_SrcRectConstraint);
|
2017-02-06 21:48:57 +00:00
|
|
|
} else {
|
2021-01-25 00:49:21 +00:00
|
|
|
canvas->drawImageRect(bmp.asImage(),
|
|
|
|
SkRect::MakeXYWH((kTileSize - 50) + offset, 0, 1124, 32),
|
|
|
|
SkRect::MakeXYWH(0.0f, 37.0f * i, 1124.0f, 32.0f),
|
|
|
|
SkSamplingOptions(), nullptr,
|
|
|
|
SkCanvas::kStrict_SrcRectConstraint);
|
2017-02-06 21:48:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-07 22:23:36 +00:00
|
|
|
DEF_SIMPLE_GPU_GM_BG(
|
2021-07-21 19:39:51 +00:00
|
|
|
bitmaptiled_fractional_horizontal, rContext, canvas, 1124, 365, SK_ColorBLACK) {
|
|
|
|
draw_tile_bitmap_with_fractional_offset(rContext, canvas, false);
|
2017-02-06 21:48:57 +00:00
|
|
|
}
|
|
|
|
|
2019-02-07 22:23:36 +00:00
|
|
|
DEF_SIMPLE_GPU_GM_BG(
|
2021-07-21 19:39:51 +00:00
|
|
|
bitmaptiled_fractional_vertical, rContext, canvas, 365, 1124, SK_ColorBLACK) {
|
|
|
|
draw_tile_bitmap_with_fractional_offset(rContext, canvas, true);
|
2017-02-06 21:48:57 +00:00
|
|
|
}
|