c95b589112
This reverts commitcf0d08e149
. Reason for revert: fix codegen Original change's description: > Revert "Migrate GrSurfaceContext readPixels to take direct context" > > This reverts commitd169e1915c
. > > Reason for revert: broke chrome via code generator > > Original change's description: > > Migrate GrSurfaceContext readPixels to take direct context > > > > After this lands we'll proceed up the stack and add the direct > > context requirement to the public API and SkImage. > > > > Bug: skia:104662 > > Change-Id: I4b2d779a7fcd65eec68e631757821ac8e136ddba > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309044 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > TBR=robertphillips@google.com,adlai@google.com > > Change-Id: I6126f2dca4bc902c903512ac486e22841cc472e5 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:104662 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309281 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> TBR=robertphillips@google.com,adlai@google.com Bug: skia:104662 Change-Id: If899edab54d031a3619a4bbab90d13738679c037 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309319 Commit-Queue: Adlai Holler <adlai@google.com> Reviewed-by: Adlai Holler <adlai@google.com>
109 lines
4.9 KiB
C++
109 lines
4.9 KiB
C++
/*
|
|
* 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 TestReadPixels(skiatest::Reporter*, GrDirectContext*, GrSurfaceContext* srcContext,
|
|
uint32_t expectedPixelValues[], const char* testName);
|
|
|
|
// See if trying to write RGBA 8888 pixels to 'dstContext' matches matches the
|
|
// expectation ('expectedToWork')
|
|
void TestWritePixels(skiatest::Reporter*, GrDirectContext*, 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 TestCopyFromSurface(skiatest::Reporter*, GrDirectContext*, GrSurfaceProxy* proxy,
|
|
GrSurfaceOrigin origin, GrColorType colorType,
|
|
uint32_t expectedPixelValues[], const char* testName);
|
|
|
|
// Fills data with a red-green gradient
|
|
void FillPixelData(int width, int height, GrColor* data);
|
|
|
|
// Create a solid colored backend texture and syncs the CPU to wait for upload to finish
|
|
bool CreateBackendTexture(GrDirectContext*,
|
|
GrBackendTexture* backendTex,
|
|
int width, int height,
|
|
SkColorType colorType,
|
|
const SkColor4f& color,
|
|
GrMipmapped,
|
|
GrRenderable,
|
|
GrProtected = GrProtected::kNo);
|
|
|
|
bool CreateBackendTexture(GrDirectContext*,
|
|
GrBackendTexture* backendTex,
|
|
const SkImageInfo& ii,
|
|
const SkColor4f& color,
|
|
GrMipmapped,
|
|
GrRenderable,
|
|
GrProtected = GrProtected::kNo);
|
|
|
|
void DeleteBackendTexture(GrDirectContext*, const GrBackendTexture& backendTex);
|
|
|
|
// Checks srcBuffer and dstBuffer contain the same colors
|
|
bool DoesFullBufferContainCorrectColor(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 BipmapToBase64DataURI(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 ComparePixels(const GrImageInfo& infoA, const char* a, size_t rowBytesA,
|
|
const GrImageInfo& infoB, const char* b, size_t rowBytesB,
|
|
const float tolRGBA[4], std::function<ComparePixmapsErrorReporter>& error);
|
|
|
|
/** Convenience version of above that takes SkPixmap inputs. */
|
|
bool ComparePixels(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 CheckSolidPixels(const SkColor4f& col,
|
|
const SkPixmap& pixmap,
|
|
const float tolRGBA[4],
|
|
std::function<ComparePixmapsErrorReporter>& error);
|
|
|
|
/**
|
|
* Checks the ref cnt on a proxy and its backing store. This is only valid if the proxy and the
|
|
* resource are both used on a single thread.
|
|
*/
|
|
void CheckSingleThreadedProxyRefs(skiatest::Reporter* reporter,
|
|
GrSurfaceProxy* proxy,
|
|
int32_t expectedProxyRefs,
|
|
int32_t expectedBackingRefs);
|