2017-01-27 15:11:42 +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 "tests/TestUtils.h"
|
|
|
|
|
|
|
|
#include "include/encode/SkPngEncoder.h"
|
|
|
|
#include "include/utils/SkBase64.h"
|
2020-12-24 01:36:44 +00:00
|
|
|
#include "src/core/SkAutoPixmapStorage.h"
|
2019-05-07 17:29:22 +00:00
|
|
|
#include "src/core/SkUtils.h"
|
2020-10-14 15:23:11 +00:00
|
|
|
#include "src/gpu/GrDirectContextPriv.h"
|
Reland "Reland "Remove support for copyAsDraw in gpu copySurface.""
This reverts commit 4c6f9b767034c6812d868108516c2580dce3cb56.
Reason for revert: Landing with neuxs 7 and androind one fixes
Original change's description:
> Revert "Reland "Remove support for copyAsDraw in gpu copySurface.""
>
> This reverts commit 84ea04949cabc87a88d06c5c6f6aeb944a745911.
>
> Reason for revert: nexus 7 and android one broken
>
> Original change's description:
> > Reland "Remove support for copyAsDraw in gpu copySurface."
> >
> > This reverts commit c5167c053bd58e6afbad83fe493c0231df3f9704.
> >
> > Reason for revert: fixed
> >
> > Original change's description:
> > > Revert "Remove support for copyAsDraw in gpu copySurface."
> > >
> > > This reverts commit 6565506463db042d3d543a1707f473cdf1ef4e9e.
> > >
> > > Reason for revert: seems to break things?
> > >
> > > Original change's description:
> > > > Remove support for copyAsDraw in gpu copySurface.
> > > >
> > > > The major changes on a higher lever are:
> > > > 1) The majority of all copies now go through GrSurfaceProxy::Copy which
> > > > takes in a proxy and returns a new one with the data copied to it. This
> > > > is the most common use case within Ganesh.
> > > >
> > > > 2) The backend copy calls no longer do draws, require origins to be the
> > > > same, and won't do any swizzling or adjustment of subrects. They are
> > > > all implemented to be dumb copy this data to this other spot.
> > > >
> > > > 3) The GrSurfaceContext copy call has now been moved to priv and renamed
> > > > copyNoDraw, and a new priv copyAsDraw was added to GrRenderTargetContext.
> > > >
> > > > 4) WritePixels and ReplaceRenderTarget both need to specifiy the destination
> > > > of copies. They are the only users (besides the GrSurfaceProxy::Copy) which
> > > > call the priv methods on GrSurfaceContext.
> > > >
> > > > Change-Id: Iaf1eb3a73ccaf39a75af77e281dae594f809186f
> > > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/217459
> > > > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > > > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > >
> > > TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com
> > >
> > > Change-Id: Id43aa8aa1451e794342e930441d9975b90e6b59f
> > > No-Presubmit: true
> > > No-Tree-Checks: true
> > > No-Try: true
> > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/218549
> > > Reviewed-by: Greg Daniel <egdaniel@google.com>
> > > Commit-Queue: Greg Daniel <egdaniel@google.com>
> >
> > TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com
> >
> > Change-Id: I1a96f85ae2ff7622a6b57406755d478e7fbcf56e
> > No-Presubmit: true
> > No-Tree-Checks: true
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/218797
> > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
>
> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com
>
> Change-Id: I310930a9df30535f45a065263a40239141e15562
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/219384
> Reviewed-by: Greg Daniel <egdaniel@google.com>
> Commit-Queue: Greg Daniel <egdaniel@google.com>
TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com
Change-Id: I88df4f19aa26ed77b5af4e25d138387cbabd1934
No-Presubmit: true
No-Tree-Checks: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/219386
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
2019-06-07 15:43:30 +00:00
|
|
|
#include "src/gpu/GrDrawingManager.h"
|
2019-05-07 17:29:22 +00:00
|
|
|
#include "src/gpu/GrGpu.h"
|
2019-09-30 16:15:30 +00:00
|
|
|
#include "src/gpu/GrImageInfo.h"
|
2020-07-20 19:00:36 +00:00
|
|
|
#include "src/gpu/GrRecordingContextPriv.h"
|
2019-06-18 13:58:02 +00:00
|
|
|
#include "src/gpu/GrSurfaceProxy.h"
|
|
|
|
#include "src/gpu/GrTextureProxy.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/SkGr.h"
|
2021-08-10 17:49:51 +00:00
|
|
|
#include "src/gpu/SurfaceContext.h"
|
2017-01-27 15:11:42 +00:00
|
|
|
|
2019-10-25 00:07:39 +00:00
|
|
|
void TestReadPixels(skiatest::Reporter* reporter,
|
2020-08-11 16:02:22 +00:00
|
|
|
GrDirectContext* dContext,
|
2021-08-10 17:49:51 +00:00
|
|
|
skgpu::SurfaceContext* srcContext,
|
2019-10-25 00:07:39 +00:00
|
|
|
uint32_t expectedPixelValues[],
|
|
|
|
const char* testName) {
|
2017-01-27 15:11:42 +00:00
|
|
|
int pixelCnt = srcContext->width() * srcContext->height();
|
2020-12-24 01:36:44 +00:00
|
|
|
SkImageInfo ii = SkImageInfo::Make(srcContext->dimensions(),
|
|
|
|
kRGBA_8888_SkColorType,
|
|
|
|
kPremul_SkAlphaType);
|
|
|
|
SkAutoPixmapStorage pm;
|
|
|
|
pm.alloc(ii);
|
|
|
|
pm.erase(SK_ColorTRANSPARENT);
|
2017-01-27 15:11:42 +00:00
|
|
|
|
2020-12-24 01:36:44 +00:00
|
|
|
bool read = srcContext->readPixels(dContext, pm, {0, 0});
|
2017-01-27 15:11:42 +00:00
|
|
|
if (!read) {
|
|
|
|
ERRORF(reporter, "%s: Error reading from texture.", testName);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < pixelCnt; ++i) {
|
2020-12-24 01:36:44 +00:00
|
|
|
if (pm.addr32()[i] != expectedPixelValues[i]) {
|
2017-01-27 15:11:42 +00:00
|
|
|
ERRORF(reporter, "%s: Error, pixel value %d should be 0x%08x, got 0x%08x.",
|
2020-12-24 01:36:44 +00:00
|
|
|
testName, i, expectedPixelValues[i], pm.addr32()[i]);
|
2017-01-27 15:11:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-25 00:07:39 +00:00
|
|
|
void TestWritePixels(skiatest::Reporter* reporter,
|
2020-08-11 16:02:22 +00:00
|
|
|
GrDirectContext* dContext,
|
2021-08-10 17:49:51 +00:00
|
|
|
skgpu::SurfaceContext* dstContext,
|
2019-10-25 00:07:39 +00:00
|
|
|
bool expectedToWork,
|
|
|
|
const char* testName) {
|
2020-12-24 01:36:44 +00:00
|
|
|
SkImageInfo ii = SkImageInfo::Make(dstContext->dimensions(),
|
|
|
|
kRGBA_8888_SkColorType,
|
|
|
|
kPremul_SkAlphaType);
|
|
|
|
SkAutoPixmapStorage pm;
|
|
|
|
pm.alloc(ii);
|
|
|
|
for (int y = 0; y < dstContext->height(); ++y) {
|
|
|
|
for (int x = 0; x < dstContext->width(); ++x) {
|
|
|
|
*pm.writable_addr32(x, y) = SkColorToPremulGrColor(SkColorSetARGB(2*y, x, y, x + y));
|
2017-01-27 15:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-24 01:36:44 +00:00
|
|
|
bool write = dstContext->writePixels(dContext, pm, {0, 0});
|
2017-01-27 15:11:42 +00:00
|
|
|
if (!write) {
|
|
|
|
if (expectedToWork) {
|
|
|
|
ERRORF(reporter, "%s: Error writing to texture.", testName);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (write && !expectedToWork) {
|
|
|
|
ERRORF(reporter, "%s: writePixels succeeded when it wasn't supposed to.", testName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-24 01:36:44 +00:00
|
|
|
TestReadPixels(reporter, dContext, dstContext, pm.writable_addr32(0, 0), testName);
|
2017-01-27 15:11:42 +00:00
|
|
|
}
|
|
|
|
|
2019-10-25 00:07:39 +00:00
|
|
|
void TestCopyFromSurface(skiatest::Reporter* reporter,
|
2020-08-11 16:02:22 +00:00
|
|
|
GrDirectContext* dContext,
|
2021-01-21 15:43:35 +00:00
|
|
|
sk_sp<GrSurfaceProxy> proxy,
|
2020-01-30 19:55:05 +00:00
|
|
|
GrSurfaceOrigin origin,
|
2019-10-25 00:07:39 +00:00
|
|
|
GrColorType colorType,
|
|
|
|
uint32_t expectedPixelValues[],
|
|
|
|
const char* testName) {
|
2021-01-21 15:43:35 +00:00
|
|
|
auto copy = GrSurfaceProxy::Copy(dContext, std::move(proxy), origin, GrMipmapped::kNo,
|
2020-07-20 19:00:36 +00:00
|
|
|
SkBackingFit::kExact, SkBudgeted::kYes);
|
2020-04-02 16:50:34 +00:00
|
|
|
SkASSERT(copy && copy->asTextureProxy());
|
2020-08-11 16:02:22 +00:00
|
|
|
auto swizzle = dContext->priv().caps()->getReadSwizzle(copy->backendFormat(), colorType);
|
2020-04-02 16:50:34 +00:00
|
|
|
GrSurfaceProxyView view(std::move(copy), origin, swizzle);
|
2021-08-02 15:14:38 +00:00
|
|
|
auto dstContext = dContext->priv().makeSC(std::move(view),
|
|
|
|
{colorType, kPremul_SkAlphaType, nullptr});
|
2019-08-21 13:38:10 +00:00
|
|
|
SkASSERT(dstContext);
|
2017-01-27 15:11:42 +00:00
|
|
|
|
2020-08-11 16:02:22 +00:00
|
|
|
TestReadPixels(reporter, dContext, dstContext.get(), expectedPixelValues, testName);
|
2017-01-27 15:11:42 +00:00
|
|
|
}
|
2018-07-17 17:28:20 +00:00
|
|
|
|
2019-10-25 00:07:39 +00:00
|
|
|
bool BipmapToBase64DataURI(const SkBitmap& bitmap, SkString* dst) {
|
2018-10-01 16:42:53 +00:00
|
|
|
SkPixmap pm;
|
|
|
|
if (!bitmap.peekPixels(&pm)) {
|
|
|
|
dst->set("peekPixels failed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We're going to embed this PNG in a data URI, so make it as small as possible
|
|
|
|
SkPngEncoder::Options options;
|
|
|
|
options.fFilterFlags = SkPngEncoder::FilterFlag::kAll;
|
|
|
|
options.fZLibLevel = 9;
|
|
|
|
|
|
|
|
SkDynamicMemoryWStream wStream;
|
|
|
|
if (!SkPngEncoder::Encode(&wStream, pm, options)) {
|
|
|
|
dst->set("SkPngEncoder::Encode failed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
sk_sp<SkData> pngData = wStream.detachAsData();
|
|
|
|
size_t len = SkBase64::Encode(pngData->data(), pngData->size(), nullptr);
|
|
|
|
|
|
|
|
// The PNG can be almost arbitrarily large. We don't want to fill our logs with enormous URLs.
|
|
|
|
// Infra says these can be pretty big, as long as we're only outputting them on failure.
|
|
|
|
static const size_t kMaxBase64Length = 1024 * 1024;
|
|
|
|
if (len > kMaxBase64Length) {
|
|
|
|
dst->printf("Encoded image too large (%u bytes)", static_cast<uint32_t>(len));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
dst->resize(len);
|
|
|
|
SkBase64::Encode(pngData->data(), pngData->size(), dst->writable_str());
|
|
|
|
dst->prepend("data:image/png;base64,");
|
|
|
|
return true;
|
|
|
|
}
|
2019-04-11 21:10:17 +00:00
|
|
|
|
2021-03-30 20:14:37 +00:00
|
|
|
static bool compare_colors(int x, int y,
|
|
|
|
const float rgbaA[],
|
|
|
|
const float rgbaB[],
|
|
|
|
const float tolRGBA[4],
|
|
|
|
std::function<ComparePixmapsErrorReporter>& error) {
|
|
|
|
float diffs[4];
|
|
|
|
bool bad = false;
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
diffs[i] = rgbaB[i] - rgbaA[i];
|
|
|
|
if (std::abs(diffs[i]) > std::abs(tolRGBA[i])) {
|
|
|
|
bad = true;
|
2019-09-11 15:26:46 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-30 20:14:37 +00:00
|
|
|
if (bad) {
|
|
|
|
error(x, y, diffs);
|
|
|
|
return false;
|
|
|
|
}
|
2019-09-11 15:26:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-03-31 18:19:31 +00:00
|
|
|
bool ComparePixels(const GrCPixmap& a,
|
|
|
|
const GrCPixmap& b,
|
|
|
|
const float tolRGBA[4],
|
|
|
|
std::function<ComparePixmapsErrorReporter>& error) {
|
|
|
|
if (a.dimensions() != b.dimensions()) {
|
2021-06-16 19:28:00 +00:00
|
|
|
static constexpr float kEmptyDiffs[4] = {};
|
|
|
|
error(-1, -1, kEmptyDiffs);
|
2019-07-15 16:30:44 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-03-31 18:19:31 +00:00
|
|
|
SkAlphaType floatAlphaType = a.alphaType();
|
2019-07-15 16:30:44 +00:00
|
|
|
// If one is premul and the other is unpremul we do the comparison in premul space.
|
2021-03-31 18:19:31 +00:00
|
|
|
if ((a.alphaType() == kPremul_SkAlphaType || b.alphaType() == kPremul_SkAlphaType) &&
|
|
|
|
(a.alphaType() == kUnpremul_SkAlphaType || b.alphaType() == kUnpremul_SkAlphaType)) {
|
2019-07-15 16:30:44 +00:00
|
|
|
floatAlphaType = kPremul_SkAlphaType;
|
|
|
|
}
|
|
|
|
sk_sp<SkColorSpace> floatCS;
|
2021-03-31 18:19:31 +00:00
|
|
|
if (SkColorSpace::Equals(a.colorSpace(), b.colorSpace())) {
|
|
|
|
floatCS = a.refColorSpace();
|
2019-07-15 16:30:44 +00:00
|
|
|
} else {
|
|
|
|
floatCS = SkColorSpace::MakeSRGBLinear();
|
|
|
|
}
|
2021-03-30 20:14:37 +00:00
|
|
|
GrImageInfo floatInfo(GrColorType::kRGBA_F32,
|
|
|
|
floatAlphaType,
|
|
|
|
std::move(floatCS),
|
2021-03-31 18:19:31 +00:00
|
|
|
a.dimensions());
|
2021-03-30 20:14:37 +00:00
|
|
|
|
|
|
|
GrPixmap floatA = GrPixmap::Allocate(floatInfo);
|
|
|
|
GrPixmap floatB = GrPixmap::Allocate(floatInfo);
|
2021-03-31 18:19:31 +00:00
|
|
|
SkAssertResult(GrConvertPixels(floatA, a));
|
|
|
|
SkAssertResult(GrConvertPixels(floatB, b));
|
2021-03-30 20:14:37 +00:00
|
|
|
|
|
|
|
SkASSERT(floatA.rowBytes() == floatB.rowBytes());
|
|
|
|
auto at = [rb = floatA.rowBytes()](const void* base, int x, int y) {
|
|
|
|
return SkTAddOffset<const float>(base, y*rb + x*sizeof(float)*4);
|
|
|
|
};
|
|
|
|
|
|
|
|
for (int y = 0; y < floatA.height(); ++y) {
|
|
|
|
for (int x = 0; x < floatA.width(); ++x) {
|
|
|
|
const float* rgbaA = at(floatA.addr(), x, y);
|
|
|
|
const float* rgbaB = at(floatB.addr(), x, y);
|
|
|
|
if (!compare_colors(x, y, rgbaA, rgbaB, tolRGBA, error)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2019-07-15 16:30:44 +00:00
|
|
|
}
|
|
|
|
|
2021-03-30 20:14:37 +00:00
|
|
|
bool CheckSolidPixels(const SkColor4f& col,
|
|
|
|
const SkPixmap& pixmap,
|
|
|
|
const float tolRGBA[4],
|
|
|
|
std::function<ComparePixmapsErrorReporter>& error) {
|
2019-09-11 15:26:46 +00:00
|
|
|
size_t floatBpp = GrColorTypeBytesPerPixel(GrColorType::kRGBA_F32);
|
|
|
|
|
|
|
|
// First convert 'col' to be compatible with 'pixmap'
|
2021-03-30 20:14:37 +00:00
|
|
|
GrPixmap colorPixmap;
|
2019-09-11 15:26:46 +00:00
|
|
|
{
|
|
|
|
sk_sp<SkColorSpace> srcCS = SkColorSpace::MakeSRGBLinear();
|
2021-03-30 20:14:37 +00:00
|
|
|
GrImageInfo srcInfo(GrColorType::kRGBA_F32,
|
|
|
|
kUnpremul_SkAlphaType,
|
|
|
|
std::move(srcCS),
|
|
|
|
{1, 1});
|
|
|
|
GrCPixmap srcPixmap(srcInfo, col.vec(), floatBpp);
|
|
|
|
GrImageInfo dstInfo =
|
|
|
|
srcInfo.makeAlphaType(pixmap.alphaType()).makeColorSpace(pixmap.refColorSpace());
|
|
|
|
colorPixmap = GrPixmap::Allocate(dstInfo);
|
|
|
|
SkAssertResult(GrConvertPixels(colorPixmap, srcPixmap));
|
2019-09-11 15:26:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t floatRowBytes = floatBpp * pixmap.width();
|
|
|
|
std::unique_ptr<char[]> floatB(new char[floatRowBytes * pixmap.height()]);
|
|
|
|
// Then convert 'pixmap' to RGBA_F32
|
2021-03-30 20:14:37 +00:00
|
|
|
GrPixmap f32Pixmap = GrPixmap::Allocate(pixmap.info().makeColorType(kRGBA_F32_SkColorType));
|
|
|
|
SkAssertResult(GrConvertPixels(f32Pixmap, pixmap));
|
|
|
|
|
|
|
|
for (int y = 0; y < f32Pixmap.height(); ++y) {
|
|
|
|
for (int x = 0; x < f32Pixmap.width(); ++x) {
|
|
|
|
auto rgbaA = SkTAddOffset<const float>(f32Pixmap.addr(),
|
|
|
|
f32Pixmap.rowBytes()*y + floatBpp*x);
|
|
|
|
auto rgbaB = static_cast<const float*>(colorPixmap.addr());
|
|
|
|
if (!compare_colors(x, y, rgbaA, rgbaB, tolRGBA, error)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2019-09-11 15:26:46 +00:00
|
|
|
}
|
2021-03-30 20:14:37 +00:00
|
|
|
return true;
|
2019-09-11 15:26:46 +00:00
|
|
|
}
|
|
|
|
|
2019-10-25 00:07:39 +00:00
|
|
|
void CheckSingleThreadedProxyRefs(skiatest::Reporter* reporter,
|
2020-02-10 21:36:07 +00:00
|
|
|
GrSurfaceProxy* proxy,
|
2019-10-25 00:07:39 +00:00
|
|
|
int32_t expectedProxyRefs,
|
|
|
|
int32_t expectedBackingRefs) {
|
2019-10-24 14:37:08 +00:00
|
|
|
int32_t actualBackingRefs = proxy->testingOnly_getBackingRefCnt();
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, proxy->refCntGreaterThan(expectedProxyRefs - 1) &&
|
|
|
|
!proxy->refCntGreaterThan(expectedProxyRefs));
|
|
|
|
REPORTER_ASSERT(reporter, actualBackingRefs == expectedBackingRefs);
|
|
|
|
}
|
|
|
|
|
2021-08-16 15:41:27 +00:00
|
|
|
std::unique_ptr<skgpu::SurfaceContext> CreateSurfaceContext(GrRecordingContext* rContext,
|
|
|
|
const GrImageInfo& info,
|
|
|
|
SkBackingFit fit,
|
|
|
|
GrSurfaceOrigin origin,
|
|
|
|
GrRenderable renderable,
|
|
|
|
int sampleCount,
|
|
|
|
GrMipmapped mipmapped,
|
|
|
|
GrProtected isProtected,
|
|
|
|
SkBudgeted budgeted) {
|
|
|
|
GrBackendFormat format = rContext->priv().caps()->getDefaultBackendFormat(info.colorType(),
|
|
|
|
renderable);
|
|
|
|
return rContext->priv().makeSC(info,
|
|
|
|
format,
|
|
|
|
fit,
|
|
|
|
origin,
|
|
|
|
renderable,
|
|
|
|
sampleCount,
|
|
|
|
mipmapped,
|
|
|
|
isProtected,
|
|
|
|
budgeted);
|
|
|
|
}
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/utils/SkCharToGlyphCache.h"
|
2019-04-11 21:10:17 +00:00
|
|
|
|
|
|
|
static SkGlyphID hash_to_glyph(uint32_t value) {
|
|
|
|
return SkToU16(((value >> 16) ^ value) & 0xFFFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class UnicharGen {
|
|
|
|
SkUnichar fU;
|
|
|
|
const int fStep;
|
|
|
|
public:
|
|
|
|
UnicharGen(int step) : fU(0), fStep(step) {}
|
|
|
|
|
|
|
|
SkUnichar next() {
|
|
|
|
fU += fStep;
|
|
|
|
return fU;
|
|
|
|
}
|
|
|
|
};
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace
|
2019-04-11 21:10:17 +00:00
|
|
|
|
|
|
|
DEF_TEST(chartoglyph_cache, reporter) {
|
|
|
|
SkCharToGlyphCache cache;
|
|
|
|
const int step = 3;
|
|
|
|
|
|
|
|
UnicharGen gen(step);
|
|
|
|
for (int i = 0; i < 500; ++i) {
|
|
|
|
SkUnichar c = gen.next();
|
|
|
|
SkGlyphID glyph = hash_to_glyph(c);
|
|
|
|
|
|
|
|
int index = cache.findGlyphIndex(c);
|
2019-04-15 16:07:19 +00:00
|
|
|
if (index >= 0) {
|
|
|
|
index = cache.findGlyphIndex(c);
|
|
|
|
}
|
2019-04-11 21:10:17 +00:00
|
|
|
REPORTER_ASSERT(reporter, index < 0);
|
|
|
|
cache.insertCharAndGlyph(~index, c, glyph);
|
|
|
|
|
|
|
|
UnicharGen gen2(step);
|
|
|
|
for (int j = 0; j <= i; ++j) {
|
|
|
|
c = gen2.next();
|
|
|
|
glyph = hash_to_glyph(c);
|
|
|
|
index = cache.findGlyphIndex(c);
|
2019-04-15 16:07:19 +00:00
|
|
|
if ((unsigned)index != glyph) {
|
|
|
|
index = cache.findGlyphIndex(c);
|
|
|
|
}
|
2019-04-11 21:10:17 +00:00
|
|
|
REPORTER_ASSERT(reporter, (unsigned)index == glyph);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|