skia2/tests/TestUtils.h

84 lines
3.9 KiB
C
Raw Normal View History

/*
* Copyright 2017 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "include/core/SkBitmap.h"
#include "src/gpu/GrDataUtils.h"
#include "tests/Test.h"
class GrSurfaceContext;
class GrSurfaceProxy;
typedef uint32_t GrColor;
// Ensure that reading back from 'srcContext' as RGBA 8888 matches 'expectedPixelValues
void test_read_pixels(skiatest::Reporter*, GrSurfaceContext* srcContext,
uint32_t expectedPixelValues[], const char* testName);
// See if trying to write RGBA 8888 pixels to 'dstContext' matches matches the
// expectation ('expectedToWork')
void test_write_pixels(skiatest::Reporter*, GrSurfaceContext* srcContext, bool expectedToWork,
const char* testName);
// Ensure that the pixels can be copied from 'proxy' viewed as colorType, to an RGBA 8888
// destination (both texture-backed and rendertarget-backed).
void test_copy_from_surface(skiatest::Reporter*, GrContext*, GrSurfaceProxy* proxy,
GrColorType colorType, uint32_t expectedPixelValues[],
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
const char* testName);
// Fills data with a red-green gradient
void fill_pixel_data(int width, int height, GrColor* data);
// Create a solid colored backend texture
bool create_backend_texture(GrContext*, GrBackendTexture* backendTex,
const SkImageInfo& ii, const SkColor4f& color,
GrMipMapped, GrRenderable);
void delete_backend_texture(GrContext*, const GrBackendTexture& backendTex);
// Checks srcBuffer and dstBuffer contain the same colors
bool does_full_buffer_contain_correct_color(const GrColor* srcBuffer, const GrColor* dstBuffer,
int width, int height);
// Encodes the bitmap into a data:/image/png;base64,... url suitable to view in a browser after
// printing to a log. If false is returned, dst holds an error message instead of a URI.
bool bitmap_to_base64_data_uri(const SkBitmap& bitmap, SkString* dst);
/** Used by compare_pixels. */
using ComparePixmapsErrorReporter = void(int x, int y, const float diffs[4]);
/**
* Compares pixels pointed to by 'a' with 'infoA' and rowBytesA to pixels pointed to by 'b' with
* 'infoB' and 'rowBytesB'.
*
* If the infos have different dimensions error is called with negative coordinate values and
* zero diffs and no comparisons are made.
*
* Before comparison pixels are converted to a common color type, alpha type, and color space.
* The color type is always 32 bit float. The alpha type is premul if one of 'infoA' and 'infoB' is
* premul and the other is unpremul. The color space is linear sRGB if 'infoA' and 'infoB' have
* different colorspaces, otherwise their common color space is used.
*
* 'tolRGBA' expresses the allowed difference between pixels in the comparison space per channel. If
* pixel components differ more than by 'tolRGBA' in absolute value in any channel then 'error' is
* called with the coordinate and difference in the comparison space (B - A).
*
* The function quits after a single error is reported and returns false if 'error' was called and
* true otherwise.
*/
bool compare_pixels(const GrPixelInfo& infoA, const char* a, size_t rowBytesA,
const GrPixelInfo& infoB, const char* b, size_t rowBytesB,
const float tolRGBA[4], std::function<ComparePixmapsErrorReporter>& error);
/** Convenience version of above that takes SkPixmap inputs. */
bool compare_pixels(const SkPixmap& a, const SkPixmap& b, const float tolRGBA[4],
std::function<ComparePixmapsErrorReporter>& error);
/**
* Convenience version that checks that 'pixmap' is a solid field of 'col'
*/
bool check_solid_pixels(const SkColor4f& col, const SkPixmap& pixmap,
const float tolRGBA[4], std::function<ComparePixmapsErrorReporter>& error);