2012-07-27 21:10:42 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkSurface_DEFINED
|
|
|
|
#define SkSurface_DEFINED
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkImage.h"
|
2020-07-14 15:29:38 +00:00
|
|
|
#include "include/core/SkPixmap.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkSurfaceProps.h"
|
2012-07-27 21:10:42 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrTypes.h"
|
Revert "Revert "Revert "Revert "Add support for semaphores to be inserted on GrContext flush""""
This reverts commit cc8eb60c486eaf397685c60b28998682025fee1a.
Reason for revert: Chrome change landed that should fix chrome roll
Original change's description:
> Revert "Revert "Revert "Add support for semaphores to be inserted on GrContext flush"""
>
> This reverts commit 876aed8758b7109574999ffac43b1ea47f359bd7.
>
> Reason for revert: the bots seem to be unhappily red with this CL
>
> Original change's description:
> > Revert "Revert "Add support for semaphores to be inserted on GrContext flush""
> >
> > This reverts commit 8724b4609996eb6369b454611e31b065f3d8d2cf.
> >
> > Reason for revert: Creating a test CL to see what happens on the bots
> >
> > Original change's description:
> > > Revert "Add support for semaphores to be inserted on GrContext flush"
> > >
> > > This reverts commit cd1416efbc7af6f115dbaa09dce48e075d1d96ca.
> > >
> > > Reason for revert: speculative, to try to fix roll see gpu_tests.pixel_integration_test.PixelIntegrationTest.Pixel_GpuRasterization_ConcavePaths
> > >
> > > Original change's description:
> > > > Add support for semaphores to be inserted on GrContext flush
> > > >
> > > > This also moves the logic of inserting semaphores down into GrDrawingManager
> > > > and finishFlush on GrGpu. With it being on finishFlush, there should be no
> > > > issues when the DrawingManager starts respecting the proxy passed in assuming
> > > > it always calls finishFlush at the end (which it should).
> > > >
> > > > Bug: skia:
> > > > Change-Id: I925c2a289dcbbb9159b9120878af1d34f21a2dc7
> > > > Reviewed-on: https://skia-review.googlesource.com/25641
> > > > 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: I9c5b9cf8c060193e1861dbb8f0c10fb11dfb5249
> > > No-Presubmit: true
> > > No-Tree-Checks: true
> > > No-Try: true
> > > Bug: skia:
> > > Reviewed-on: https://skia-review.googlesource.com/25980
> > > Reviewed-by: Mike Reed <reed@google.com>
> > > Commit-Queue: Mike Reed <reed@google.com>
> >
> > TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reed@google.com
> >
> > # Not skipping CQ checks because original CL landed > 1 day ago.
> >
> > Bug: skia:
> > Change-Id: I5edbeaa0769670ee58f362f0ccaa78319410aa6c
> > Reviewed-on: https://skia-review.googlesource.com/26160
> > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
>
> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reed@google.com
>
> Change-Id: I22fd6febafe70489a5fdb695c6f4263368eb423d
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: skia:
> Reviewed-on: https://skia-review.googlesource.com/29422
> Reviewed-by: Yuqian Li <liyuqian@google.com>
> Commit-Queue: Yuqian Li <liyuqian@google.com>
TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,liyuqian@google.com,reed@google.com
Change-Id: Ie3eae818b02599a70f714ef6b6635ce7d171bde6
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/30000
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2017-08-02 15:10:09 +00:00
|
|
|
|
2019-02-06 20:30:34 +00:00
|
|
|
#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
|
|
|
|
#include <android/hardware_buffer.h>
|
|
|
|
#endif
|
|
|
|
|
2019-09-19 17:03:09 +00:00
|
|
|
#ifdef SK_METAL
|
|
|
|
#include "include/gpu/mtl/GrMtlTypes.h"
|
|
|
|
#endif
|
|
|
|
|
2012-07-27 21:10:42 +00:00
|
|
|
class SkCanvas;
|
2017-08-30 16:06:35 +00:00
|
|
|
class SkDeferredDisplayList;
|
2012-07-27 21:10:42 +00:00
|
|
|
class SkPaint;
|
2017-08-30 16:06:35 +00:00
|
|
|
class SkSurfaceCharacterization;
|
2017-04-18 19:52:36 +00:00
|
|
|
class GrBackendRenderTarget;
|
2017-06-16 13:45:32 +00:00
|
|
|
class GrBackendSemaphore;
|
2020-06-11 15:51:06 +00:00
|
|
|
class GrBackendSurfaceMutableState;
|
2018-04-05 13:30:38 +00:00
|
|
|
class GrBackendTexture;
|
2020-10-20 14:11:53 +00:00
|
|
|
class GrDirectContext;
|
2019-02-19 17:52:29 +00:00
|
|
|
class GrRecordingContext;
|
2012-07-31 15:45:27 +00:00
|
|
|
class GrRenderTarget;
|
2012-07-27 21:10:42 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** \class SkSurface
|
|
|
|
SkSurface is responsible for managing the pixels that a canvas draws into. The pixels can be
|
|
|
|
allocated either in CPU memory (a raster surface) or on the GPU (a GrRenderTarget surface).
|
|
|
|
SkSurface takes care of allocating a SkCanvas that will draw into the surface. Call
|
|
|
|
surface->getCanvas() to use that canvas (but don't delete it, it is owned by the surface).
|
|
|
|
SkSurface always has non-zero dimensions. If there is a request for a new surface, and either
|
|
|
|
of the requested dimensions are zero, then nullptr will be returned.
|
|
|
|
*/
|
2013-04-18 13:28:19 +00:00
|
|
|
class SK_API SkSurface : public SkRefCnt {
|
2012-07-27 21:10:42 +00:00
|
|
|
public:
|
2018-02-27 15:22:04 +00:00
|
|
|
|
|
|
|
/** Allocates raster SkSurface. SkCanvas returned by SkSurface draws directly into pixels.
|
|
|
|
|
|
|
|
SkSurface is returned if all parameters are valid.
|
|
|
|
Valid parameters include:
|
|
|
|
info dimensions are greater than zero;
|
|
|
|
info contains SkColorType and SkAlphaType supported by raster surface;
|
|
|
|
pixels is not nullptr;
|
|
|
|
rowBytes is large enough to contain info width pixels of SkColorType.
|
|
|
|
|
|
|
|
Pixel buffer size should be info height times computed rowBytes.
|
|
|
|
Pixels are not initialized.
|
2020-01-23 17:30:31 +00:00
|
|
|
To access pixels after drawing, peekPixels() or readPixels().
|
2018-02-27 15:22:04 +00:00
|
|
|
|
|
|
|
@param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace,
|
|
|
|
of raster surface; width and height must be greater than zero
|
|
|
|
@param pixels pointer to destination pixels buffer
|
|
|
|
@param rowBytes interval from one SkSurface row to the next
|
|
|
|
@param surfaceProps LCD striping orientation and setting for device independent fonts;
|
|
|
|
may be nullptr
|
|
|
|
@return SkSurface if all parameters are valid; otherwise, nullptr
|
|
|
|
*/
|
2017-11-03 12:06:09 +00:00
|
|
|
static sk_sp<SkSurface> MakeRasterDirect(const SkImageInfo& imageInfo, void* pixels,
|
|
|
|
size_t rowBytes,
|
|
|
|
const SkSurfaceProps* surfaceProps = nullptr);
|
2012-07-27 21:10:42 +00:00
|
|
|
|
2020-07-14 15:29:38 +00:00
|
|
|
static sk_sp<SkSurface> MakeRasterDirect(const SkPixmap& pm,
|
|
|
|
const SkSurfaceProps* props = nullptr) {
|
|
|
|
return MakeRasterDirect(pm.info(), pm.writable_addr(), pm.rowBytes(), props);
|
|
|
|
}
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Allocates raster SkSurface. SkCanvas returned by SkSurface draws directly into pixels.
|
|
|
|
releaseProc is called with pixels and context when SkSurface is deleted.
|
|
|
|
|
|
|
|
SkSurface is returned if all parameters are valid.
|
|
|
|
Valid parameters include:
|
|
|
|
info dimensions are greater than zero;
|
|
|
|
info contains SkColorType and SkAlphaType supported by raster surface;
|
|
|
|
pixels is not nullptr;
|
|
|
|
rowBytes is large enough to contain info width pixels of SkColorType.
|
|
|
|
|
|
|
|
Pixel buffer size should be info height times computed rowBytes.
|
|
|
|
Pixels are not initialized.
|
|
|
|
To access pixels after drawing, call flush() or peekPixels().
|
|
|
|
|
|
|
|
@param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace,
|
|
|
|
of raster surface; width and height must be greater than zero
|
|
|
|
@param pixels pointer to destination pixels buffer
|
|
|
|
@param rowBytes interval from one SkSurface row to the next
|
|
|
|
@param releaseProc called when SkSurface is deleted; may be nullptr
|
|
|
|
@param context passed to releaseProc; may be nullptr
|
|
|
|
@param surfaceProps LCD striping orientation and setting for device independent fonts;
|
|
|
|
may be nullptr
|
|
|
|
@return SkSurface if all parameters are valid; otherwise, nullptr
|
|
|
|
*/
|
2017-11-03 12:06:09 +00:00
|
|
|
static sk_sp<SkSurface> MakeRasterDirectReleaseProc(const SkImageInfo& imageInfo, void* pixels,
|
|
|
|
size_t rowBytes,
|
|
|
|
void (*releaseProc)(void* pixels, void* context),
|
|
|
|
void* context, const SkSurfaceProps* surfaceProps = nullptr);
|
2014-06-27 13:48:14 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Allocates raster SkSurface. SkCanvas returned by SkSurface draws directly into pixels.
|
|
|
|
Allocates and zeroes pixel memory. Pixel memory size is imageInfo.height() times
|
|
|
|
rowBytes, or times imageInfo.minRowBytes() if rowBytes is zero.
|
|
|
|
Pixel memory is deleted when SkSurface is deleted.
|
|
|
|
|
|
|
|
SkSurface is returned if all parameters are valid.
|
|
|
|
Valid parameters include:
|
|
|
|
info dimensions are greater than zero;
|
|
|
|
info contains SkColorType and SkAlphaType supported by raster surface;
|
|
|
|
rowBytes is large enough to contain info width pixels of SkColorType, or is zero.
|
|
|
|
|
2020-01-23 17:30:31 +00:00
|
|
|
If rowBytes is zero, a suitable value will be chosen internally.
|
2018-02-27 15:22:04 +00:00
|
|
|
|
|
|
|
@param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace,
|
|
|
|
of raster surface; width and height must be greater than zero
|
|
|
|
@param rowBytes interval from one SkSurface row to the next; may be zero
|
|
|
|
@param surfaceProps LCD striping orientation and setting for device independent fonts;
|
|
|
|
may be nullptr
|
|
|
|
@return SkSurface if all parameters are valid; otherwise, nullptr
|
|
|
|
*/
|
2017-11-03 12:06:09 +00:00
|
|
|
static sk_sp<SkSurface> MakeRaster(const SkImageInfo& imageInfo, size_t rowBytes,
|
|
|
|
const SkSurfaceProps* surfaceProps);
|
2016-01-30 18:01:06 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Allocates raster SkSurface. SkCanvas returned by SkSurface draws directly into pixels.
|
|
|
|
Allocates and zeroes pixel memory. Pixel memory size is imageInfo.height() times
|
|
|
|
imageInfo.minRowBytes().
|
|
|
|
Pixel memory is deleted when SkSurface is deleted.
|
|
|
|
|
|
|
|
SkSurface is returned if all parameters are valid.
|
|
|
|
Valid parameters include:
|
|
|
|
info dimensions are greater than zero;
|
|
|
|
info contains SkColorType and SkAlphaType supported by raster surface.
|
|
|
|
|
|
|
|
@param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace,
|
|
|
|
of raster surface; width and height must be greater than zero
|
|
|
|
@param props LCD striping orientation and setting for device independent fonts;
|
|
|
|
may be nullptr
|
|
|
|
@return SkSurface if all parameters are valid; otherwise, nullptr
|
|
|
|
*/
|
2017-11-03 12:06:09 +00:00
|
|
|
static sk_sp<SkSurface> MakeRaster(const SkImageInfo& imageInfo,
|
2016-07-06 13:22:06 +00:00
|
|
|
const SkSurfaceProps* props = nullptr) {
|
2017-11-03 12:06:09 +00:00
|
|
|
return MakeRaster(imageInfo, 0, props);
|
2016-07-06 13:22:06 +00:00
|
|
|
}
|
2012-07-27 21:10:42 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Allocates raster SkSurface. SkCanvas returned by SkSurface draws directly into pixels.
|
|
|
|
Allocates and zeroes pixel memory. Pixel memory size is height times width times
|
|
|
|
four. Pixel memory is deleted when SkSurface is deleted.
|
|
|
|
|
2018-05-30 13:20:29 +00:00
|
|
|
Internally, sets SkImageInfo to width, height, native color type, and
|
2018-02-27 15:22:04 +00:00
|
|
|
kPremul_SkAlphaType.
|
|
|
|
|
|
|
|
SkSurface is returned if width and height are greater than zero.
|
|
|
|
|
|
|
|
Use to create SkSurface that matches SkPMColor, the native pixel arrangement on
|
|
|
|
the platform. SkSurface drawn to output device skips converting its pixel format.
|
|
|
|
|
|
|
|
@param width pixel column count; must be greater than zero
|
|
|
|
@param height pixel row count; must be greater than zero
|
|
|
|
@param surfaceProps LCD striping orientation and setting for device independent
|
|
|
|
fonts; may be nullptr
|
|
|
|
@return SkSurface if all parameters are valid; otherwise, nullptr
|
|
|
|
*/
|
2016-03-24 01:59:25 +00:00
|
|
|
static sk_sp<SkSurface> MakeRasterN32Premul(int width, int height,
|
2019-02-07 21:18:22 +00:00
|
|
|
const SkSurfaceProps* surfaceProps = nullptr);
|
2013-09-17 20:03:43 +00:00
|
|
|
|
2019-02-05 15:08:43 +00:00
|
|
|
/** Caller data passed to RenderTarget/TextureReleaseProc; may be nullptr. */
|
|
|
|
typedef void* ReleaseContext;
|
|
|
|
|
|
|
|
/** User function called when supplied render target may be deleted. */
|
|
|
|
typedef void (*RenderTargetReleaseProc)(ReleaseContext releaseContext);
|
|
|
|
|
|
|
|
/** User function called when supplied texture may be deleted. */
|
|
|
|
typedef void (*TextureReleaseProc)(ReleaseContext releaseContext);
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Wraps a GPU-backed texture into SkSurface. Caller must ensure the texture is
|
|
|
|
valid for the lifetime of returned SkSurface. If sampleCnt greater than zero,
|
|
|
|
creates an intermediate MSAA SkSurface which is used for drawing backendTexture.
|
|
|
|
|
|
|
|
SkSurface is returned if all parameters are valid. backendTexture is valid if
|
|
|
|
its pixel configuration agrees with colorSpace and context; for instance, if
|
|
|
|
backendTexture has an sRGB configuration, then context must support sRGB,
|
|
|
|
and colorSpace must be present. Further, backendTexture width and height must
|
|
|
|
not exceed context capabilities, and the context must be able to support
|
|
|
|
back-end textures.
|
|
|
|
|
2020-06-03 02:01:39 +00:00
|
|
|
Upon success textureReleaseProc is called when it is safe to delete the texture in the
|
|
|
|
backend API (accounting only for use of the texture by this surface). If SkSurface creation
|
|
|
|
fails textureReleaseProc is called before this function returns.
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr.
|
|
|
|
|
2019-02-05 15:08:43 +00:00
|
|
|
@param context GPU context
|
|
|
|
@param backendTexture texture residing on GPU
|
|
|
|
@param sampleCnt samples per pixel, or 0 to disable full scene anti-aliasing
|
|
|
|
@param colorSpace range of colors; may be nullptr
|
|
|
|
@param surfaceProps LCD striping orientation and setting for device independent
|
|
|
|
fonts; may be nullptr
|
|
|
|
@param textureReleaseProc function called when texture can be released
|
|
|
|
@param releaseContext state passed to textureReleaseProc
|
|
|
|
@return SkSurface if all parameters are valid; otherwise, nullptr
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2020-10-07 15:36:49 +00:00
|
|
|
static sk_sp<SkSurface> MakeFromBackendTexture(GrRecordingContext* context,
|
2017-12-19 18:15:02 +00:00
|
|
|
const GrBackendTexture& backendTexture,
|
|
|
|
GrSurfaceOrigin origin, int sampleCnt,
|
|
|
|
SkColorType colorType,
|
|
|
|
sk_sp<SkColorSpace> colorSpace,
|
2019-02-05 15:08:43 +00:00
|
|
|
const SkSurfaceProps* surfaceProps,
|
|
|
|
TextureReleaseProc textureReleaseProc = nullptr,
|
|
|
|
ReleaseContext releaseContext = nullptr);
|
2017-12-19 18:15:02 +00:00
|
|
|
|
2018-04-03 15:49:10 +00:00
|
|
|
/** Wraps a GPU-backed buffer into SkSurface. Caller must ensure backendRenderTarget
|
|
|
|
is valid for the lifetime of returned SkSurface.
|
2018-02-27 15:22:04 +00:00
|
|
|
|
|
|
|
SkSurface is returned if all parameters are valid. backendRenderTarget is valid if
|
|
|
|
its pixel configuration agrees with colorSpace and context; for instance, if
|
|
|
|
backendRenderTarget has an sRGB configuration, then context must support sRGB,
|
|
|
|
and colorSpace must be present. Further, backendRenderTarget width and height must
|
|
|
|
not exceed context capabilities, and the context must be able to support
|
|
|
|
back-end render targets.
|
|
|
|
|
2020-06-03 02:01:39 +00:00
|
|
|
Upon success releaseProc is called when it is safe to delete the render target in the
|
|
|
|
backend API (accounting only for use of the render target by this surface). If SkSurface
|
|
|
|
creation fails releaseProc is called before this function returns.
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr.
|
|
|
|
|
2019-02-05 15:08:43 +00:00
|
|
|
@param context GPU context
|
|
|
|
@param backendRenderTarget GPU intermediate memory buffer
|
|
|
|
@param colorSpace range of colors
|
|
|
|
@param surfaceProps LCD striping orientation and setting for device independent
|
|
|
|
fonts; may be nullptr
|
2020-06-03 02:01:39 +00:00
|
|
|
@param releaseProc function called when backendRenderTarget can be released
|
|
|
|
@param releaseContext state passed to releaseProc
|
2019-02-05 15:08:43 +00:00
|
|
|
@return SkSurface if all parameters are valid; otherwise, nullptr
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2020-10-07 15:36:49 +00:00
|
|
|
static sk_sp<SkSurface> MakeFromBackendRenderTarget(GrRecordingContext* context,
|
2017-11-03 12:06:09 +00:00
|
|
|
const GrBackendRenderTarget& backendRenderTarget,
|
|
|
|
GrSurfaceOrigin origin,
|
2017-12-19 18:15:02 +00:00
|
|
|
SkColorType colorType,
|
2017-11-03 12:06:09 +00:00
|
|
|
sk_sp<SkColorSpace> colorSpace,
|
2019-02-05 15:08:43 +00:00
|
|
|
const SkSurfaceProps* surfaceProps,
|
2019-02-13 19:26:37 +00:00
|
|
|
RenderTargetReleaseProc releaseProc = nullptr,
|
2019-02-05 15:08:43 +00:00
|
|
|
ReleaseContext releaseContext = nullptr);
|
2017-04-18 19:52:36 +00:00
|
|
|
|
2019-02-06 20:30:34 +00:00
|
|
|
#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
|
2019-02-13 19:26:37 +00:00
|
|
|
/** Private.
|
|
|
|
Creates SkSurface from Android hardware buffer.
|
2019-02-06 20:30:34 +00:00
|
|
|
Returned SkSurface takes a reference on the buffer. The ref on the buffer will be released
|
|
|
|
when the SkSurface is destroyed and there is no pending work on the GPU involving the
|
|
|
|
buffer.
|
|
|
|
|
|
|
|
Only available on Android, when __ANDROID_API__ is defined to be 26 or greater.
|
|
|
|
|
|
|
|
Currently this is only supported for buffers that can be textured as well as rendered to.
|
2019-09-19 17:03:09 +00:00
|
|
|
In other words that must have both AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT and
|
2019-02-06 20:30:34 +00:00
|
|
|
AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE usage bits.
|
|
|
|
|
|
|
|
@param context GPU context
|
|
|
|
@param hardwareBuffer AHardwareBuffer Android hardware buffer
|
|
|
|
@param colorSpace range of colors; may be nullptr
|
|
|
|
@param surfaceProps LCD striping orientation and setting for device independent
|
|
|
|
fonts; may be nullptr
|
|
|
|
@return created SkSurface, or nullptr
|
|
|
|
*/
|
2020-10-07 15:36:49 +00:00
|
|
|
static sk_sp<SkSurface> MakeFromAHardwareBuffer(GrDirectContext* context,
|
2019-02-06 20:30:34 +00:00
|
|
|
AHardwareBuffer* hardwareBuffer,
|
|
|
|
GrSurfaceOrigin origin,
|
|
|
|
sk_sp<SkColorSpace> colorSpace,
|
|
|
|
const SkSurfaceProps* surfaceProps);
|
|
|
|
#endif
|
|
|
|
|
2019-09-19 17:03:09 +00:00
|
|
|
#ifdef SK_METAL
|
2020-01-08 17:15:44 +00:00
|
|
|
/** Creates SkSurface from CAMetalLayer.
|
2019-09-19 17:03:09 +00:00
|
|
|
Returned SkSurface takes a reference on the CAMetalLayer. The ref on the layer will be
|
|
|
|
released when the SkSurface is destroyed.
|
|
|
|
|
|
|
|
Only available when Metal API is enabled.
|
|
|
|
|
|
|
|
Will grab the current drawable from the layer and use its texture as a backendRT to
|
|
|
|
create a renderable surface.
|
|
|
|
|
|
|
|
@param context GPU context
|
|
|
|
@param layer GrMTLHandle (expected to be a CAMetalLayer*)
|
|
|
|
@param sampleCnt samples per pixel, or 0 to disable full scene anti-aliasing
|
|
|
|
@param colorSpace range of colors; may be nullptr
|
|
|
|
@param surfaceProps LCD striping orientation and setting for device independent
|
|
|
|
fonts; may be nullptr
|
|
|
|
@param drawable Pointer to drawable to be filled in when this surface is
|
|
|
|
instantiated; may not be nullptr
|
|
|
|
@return created SkSurface, or nullptr
|
|
|
|
*/
|
2020-09-23 18:01:58 +00:00
|
|
|
static sk_sp<SkSurface> MakeFromCAMetalLayer(GrRecordingContext* context,
|
2019-09-19 17:03:09 +00:00
|
|
|
GrMTLHandle layer,
|
|
|
|
GrSurfaceOrigin origin,
|
|
|
|
int sampleCnt,
|
|
|
|
SkColorType colorType,
|
|
|
|
sk_sp<SkColorSpace> colorSpace,
|
|
|
|
const SkSurfaceProps* surfaceProps,
|
2020-04-23 00:48:18 +00:00
|
|
|
GrMTLHandle* drawable)
|
|
|
|
SK_API_AVAILABLE_CA_METAL_LAYER;
|
2019-09-19 17:03:09 +00:00
|
|
|
|
2020-01-08 17:15:44 +00:00
|
|
|
/** Creates SkSurface from MTKView.
|
|
|
|
Returned SkSurface takes a reference on the MTKView. The ref on the layer will be
|
|
|
|
released when the SkSurface is destroyed.
|
|
|
|
|
|
|
|
Only available when Metal API is enabled.
|
|
|
|
|
|
|
|
Will grab the current drawable from the layer and use its texture as a backendRT to
|
|
|
|
create a renderable surface.
|
|
|
|
|
|
|
|
@param context GPU context
|
|
|
|
@param layer GrMTLHandle (expected to be a MTKView*)
|
|
|
|
@param sampleCnt samples per pixel, or 0 to disable full scene anti-aliasing
|
|
|
|
@param colorSpace range of colors; may be nullptr
|
|
|
|
@param surfaceProps LCD striping orientation and setting for device independent
|
|
|
|
fonts; may be nullptr
|
|
|
|
@return created SkSurface, or nullptr
|
|
|
|
*/
|
2020-09-23 18:01:58 +00:00
|
|
|
static sk_sp<SkSurface> MakeFromMTKView(GrRecordingContext* context,
|
2020-01-08 17:15:44 +00:00
|
|
|
GrMTLHandle mtkView,
|
|
|
|
GrSurfaceOrigin origin,
|
|
|
|
int sampleCnt,
|
|
|
|
SkColorType colorType,
|
|
|
|
sk_sp<SkColorSpace> colorSpace,
|
2020-01-09 19:03:54 +00:00
|
|
|
const SkSurfaceProps* surfaceProps)
|
2020-03-18 21:37:23 +00:00
|
|
|
SK_API_AVAILABLE(macos(10.11), ios(9.0));
|
2019-09-19 17:03:09 +00:00
|
|
|
#endif
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Returns SkSurface on GPU indicated by context. Allocates memory for
|
2018-10-31 14:54:50 +00:00
|
|
|
pixels, based on the width, height, and SkColorType in SkImageInfo. budgeted
|
2018-02-27 15:22:04 +00:00
|
|
|
selects whether allocation for pixels is tracked by context. imageInfo
|
|
|
|
describes the pixel format in SkColorType, and transparency in
|
|
|
|
SkAlphaType, and color matching in SkColorSpace.
|
|
|
|
|
|
|
|
sampleCount requests the number of samples per pixel.
|
2018-06-14 17:21:08 +00:00
|
|
|
Pass zero to disable multi-sample anti-aliasing. The request is rounded
|
2018-02-27 15:22:04 +00:00
|
|
|
up to the next supported count, or rounded down if it is larger than the
|
|
|
|
maximum supported count.
|
|
|
|
|
|
|
|
surfaceOrigin pins either the top-left or the bottom-left corner to the origin.
|
|
|
|
|
2018-06-14 17:21:08 +00:00
|
|
|
shouldCreateWithMips hints that SkImage returned by makeImageSnapshot() is mip map.
|
2018-02-27 15:22:04 +00:00
|
|
|
|
|
|
|
If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr.
|
|
|
|
|
|
|
|
@param context GPU context
|
|
|
|
@param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace;
|
|
|
|
width, or height, or both, may be zero
|
|
|
|
@param sampleCount samples per pixel, or 0 to disable full scene anti-aliasing
|
|
|
|
@param surfaceProps LCD striping orientation and setting for device independent
|
|
|
|
fonts; may be nullptr
|
2018-06-14 17:21:08 +00:00
|
|
|
@param shouldCreateWithMips hint that SkSurface will host mip map images
|
2018-02-27 15:22:04 +00:00
|
|
|
@return SkSurface if all parameters are valid; otherwise, nullptr
|
|
|
|
*/
|
2020-07-07 14:20:27 +00:00
|
|
|
static sk_sp<SkSurface> MakeRenderTarget(GrRecordingContext* context, SkBudgeted budgeted,
|
|
|
|
const SkImageInfo& imageInfo,
|
|
|
|
int sampleCount, GrSurfaceOrigin surfaceOrigin,
|
|
|
|
const SkSurfaceProps* surfaceProps,
|
|
|
|
bool shouldCreateWithMips = false);
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Returns SkSurface on GPU indicated by context. Allocates memory for
|
2018-10-31 14:54:50 +00:00
|
|
|
pixels, based on the width, height, and SkColorType in SkImageInfo. budgeted
|
2018-02-27 15:22:04 +00:00
|
|
|
selects whether allocation for pixels is tracked by context. imageInfo
|
|
|
|
describes the pixel format in SkColorType, and transparency in
|
|
|
|
SkAlphaType, and color matching in SkColorSpace.
|
|
|
|
|
|
|
|
sampleCount requests the number of samples per pixel.
|
2018-06-14 17:21:08 +00:00
|
|
|
Pass zero to disable multi-sample anti-aliasing. The request is rounded
|
2018-02-27 15:22:04 +00:00
|
|
|
up to the next supported count, or rounded down if it is larger than the
|
|
|
|
maximum supported count.
|
|
|
|
|
|
|
|
SkSurface bottom-left corner is pinned to the origin.
|
|
|
|
|
|
|
|
@param context GPU context
|
|
|
|
@param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace,
|
|
|
|
of raster surface; width, or height, or both, may be zero
|
2018-06-14 17:21:08 +00:00
|
|
|
@param sampleCount samples per pixel, or 0 to disable multi-sample anti-aliasing
|
2019-07-02 21:58:27 +00:00
|
|
|
@param surfaceProps LCD striping orientation and setting for device independent
|
2018-02-27 15:22:04 +00:00
|
|
|
fonts; may be nullptr
|
|
|
|
@return SkSurface if all parameters are valid; otherwise, nullptr
|
|
|
|
*/
|
2020-07-07 14:20:27 +00:00
|
|
|
static sk_sp<SkSurface> MakeRenderTarget(GrRecordingContext* context, SkBudgeted budgeted,
|
2017-11-03 12:06:09 +00:00
|
|
|
const SkImageInfo& imageInfo, int sampleCount,
|
2019-07-02 21:58:27 +00:00
|
|
|
const SkSurfaceProps* surfaceProps) {
|
2017-11-03 12:06:09 +00:00
|
|
|
return MakeRenderTarget(context, budgeted, imageInfo, sampleCount,
|
2019-07-02 21:58:27 +00:00
|
|
|
kBottomLeft_GrSurfaceOrigin, surfaceProps);
|
2016-07-26 18:38:17 +00:00
|
|
|
}
|
2016-03-24 01:59:25 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Returns SkSurface on GPU indicated by context. Allocates memory for
|
2018-10-31 14:54:50 +00:00
|
|
|
pixels, based on the width, height, and SkColorType in SkImageInfo. budgeted
|
2018-02-27 15:22:04 +00:00
|
|
|
selects whether allocation for pixels is tracked by context. imageInfo
|
|
|
|
describes the pixel format in SkColorType, and transparency in
|
|
|
|
SkAlphaType, and color matching in SkColorSpace.
|
|
|
|
|
|
|
|
SkSurface bottom-left corner is pinned to the origin.
|
|
|
|
|
|
|
|
@param context GPU context
|
|
|
|
@param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace,
|
|
|
|
of raster surface; width, or height, or both, may be zero
|
|
|
|
@return SkSurface if all parameters are valid; otherwise, nullptr
|
|
|
|
*/
|
2020-07-07 14:20:27 +00:00
|
|
|
static sk_sp<SkSurface> MakeRenderTarget(GrRecordingContext* context, SkBudgeted budgeted,
|
2017-11-03 12:06:09 +00:00
|
|
|
const SkImageInfo& imageInfo) {
|
|
|
|
if (!imageInfo.width() || !imageInfo.height()) {
|
2016-11-07 13:23:48 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2017-11-03 12:06:09 +00:00
|
|
|
return MakeRenderTarget(context, budgeted, imageInfo, 0, kBottomLeft_GrSurfaceOrigin,
|
|
|
|
nullptr);
|
2016-03-24 01:59:25 +00:00
|
|
|
}
|
2014-09-22 14:29:03 +00:00
|
|
|
|
2018-03-30 17:57:00 +00:00
|
|
|
/** Returns SkSurface on GPU indicated by context that is compatible with the provided
|
|
|
|
characterization. budgeted selects whether allocation for pixels is tracked by context.
|
|
|
|
|
|
|
|
@param context GPU context
|
|
|
|
@param characterization description of the desired SkSurface
|
|
|
|
@return SkSurface if all parameters are valid; otherwise, nullptr
|
|
|
|
*/
|
2019-02-19 17:52:29 +00:00
|
|
|
static sk_sp<SkSurface> MakeRenderTarget(GrRecordingContext* context,
|
2018-03-30 17:57:00 +00:00
|
|
|
const SkSurfaceCharacterization& characterization,
|
|
|
|
SkBudgeted budgeted);
|
|
|
|
|
2019-06-25 18:47:04 +00:00
|
|
|
/** Is this surface compatible with the provided characterization?
|
|
|
|
|
|
|
|
This method can be used to determine if an existing SkSurface is a viable destination
|
|
|
|
for an SkDeferredDisplayList.
|
|
|
|
|
|
|
|
@param characterization The characterization for which a compatibility check is desired
|
|
|
|
@return true if this surface is compatible with the characterization;
|
|
|
|
false otherwise
|
|
|
|
*/
|
|
|
|
bool isCompatible(const SkSurfaceCharacterization& characterization) const;
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Returns SkSurface without backing pixels. Drawing to SkCanvas returned from SkSurface
|
|
|
|
has no effect. Calling makeImageSnapshot() on returned SkSurface returns nullptr.
|
|
|
|
|
|
|
|
@param width one or greater
|
|
|
|
@param height one or greater
|
|
|
|
@return SkSurface if width and height are positive; otherwise, nullptr
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Surface_MakeNull
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2017-06-28 23:57:21 +00:00
|
|
|
static sk_sp<SkSurface> MakeNull(int width, int height);
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Returns pixel count in each row; may be zero or greater.
|
|
|
|
|
|
|
|
@return number of pixel columns
|
|
|
|
*/
|
2012-07-27 21:10:42 +00:00
|
|
|
int width() const { return fWidth; }
|
2018-02-27 15:22:04 +00:00
|
|
|
|
|
|
|
/** Returns pixel row count; may be zero or greater.
|
|
|
|
|
|
|
|
@return number of pixel rows
|
|
|
|
*/
|
2012-07-27 21:10:42 +00:00
|
|
|
int height() const { return fHeight; }
|
|
|
|
|
2019-06-17 21:45:01 +00:00
|
|
|
/** Returns an ImageInfo describing the surface.
|
|
|
|
*/
|
|
|
|
SkImageInfo imageInfo();
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Returns unique value identifying the content of SkSurface. Returned value changes
|
|
|
|
each time the content changes. Content is changed by drawing, or by calling
|
|
|
|
notifyContentWillChange().
|
|
|
|
|
|
|
|
@return unique content identifier
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Surface_notifyContentWillChange
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2012-08-28 12:19:02 +00:00
|
|
|
uint32_t generationID();
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** \enum SkSurface::ContentChangeMode
|
|
|
|
ContentChangeMode members are parameters to notifyContentWillChange().
|
|
|
|
*/
|
2013-04-22 14:28:01 +00:00
|
|
|
enum ContentChangeMode {
|
2018-05-30 13:20:29 +00:00
|
|
|
kDiscard_ContentChangeMode, //!< discards surface on change
|
|
|
|
kRetain_ContentChangeMode, //!< preserves surface on change
|
2013-04-22 14:28:01 +00:00
|
|
|
};
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Notifies that SkSurface contents will be changed by code outside of Skia.
|
|
|
|
Subsequent calls to generationID() return a different value.
|
|
|
|
|
2018-11-15 13:25:12 +00:00
|
|
|
TODO: Can kRetain_ContentChangeMode be deprecated?
|
2018-02-27 15:22:04 +00:00
|
|
|
|
2019-03-15 19:47:01 +00:00
|
|
|
example: https://fiddle.skia.org/c/@Surface_notifyContentWillChange
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2013-04-22 14:28:01 +00:00
|
|
|
void notifyContentWillChange(ContentChangeMode mode);
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2020-07-06 19:50:15 +00:00
|
|
|
/** Returns the recording context being used by the SkSurface.
|
|
|
|
|
|
|
|
@return the recording context, if available; nullptr otherwise
|
2020-06-26 18:04:05 +00:00
|
|
|
*/
|
|
|
|
GrRecordingContext* recordingContext();
|
|
|
|
|
2015-07-08 19:54:04 +00:00
|
|
|
enum BackendHandleAccess {
|
2018-05-30 13:20:29 +00:00
|
|
|
kFlushRead_BackendHandleAccess, //!< back-end object is readable
|
|
|
|
kFlushWrite_BackendHandleAccess, //!< back-end object is writable
|
|
|
|
kDiscardWrite_BackendHandleAccess, //!< back-end object must be overwritten
|
2015-06-29 14:37:01 +00:00
|
|
|
};
|
2015-07-08 19:54:04 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Deprecated.
|
|
|
|
*/
|
2015-07-08 19:54:04 +00:00
|
|
|
static const BackendHandleAccess kFlushRead_TextureHandleAccess =
|
|
|
|
kFlushRead_BackendHandleAccess;
|
2018-02-27 15:22:04 +00:00
|
|
|
|
|
|
|
/** Deprecated.
|
|
|
|
*/
|
2015-07-08 19:54:04 +00:00
|
|
|
static const BackendHandleAccess kFlushWrite_TextureHandleAccess =
|
|
|
|
kFlushWrite_BackendHandleAccess;
|
2018-02-27 15:22:04 +00:00
|
|
|
|
|
|
|
/** Deprecated.
|
|
|
|
*/
|
2015-07-08 19:54:04 +00:00
|
|
|
static const BackendHandleAccess kDiscardWrite_TextureHandleAccess =
|
|
|
|
kDiscardWrite_BackendHandleAccess;
|
|
|
|
|
2018-05-30 13:20:29 +00:00
|
|
|
/** Retrieves the back-end texture. If SkSurface has no back-end texture, an invalid
|
2018-04-05 13:30:38 +00:00
|
|
|
object is returned. Call GrBackendTexture::isValid to determine if the result
|
|
|
|
is valid.
|
|
|
|
|
2018-05-30 13:20:29 +00:00
|
|
|
The returned GrBackendTexture should be discarded if the SkSurface is drawn to or deleted.
|
2018-04-05 13:30:38 +00:00
|
|
|
|
|
|
|
@return GPU texture reference; invalid on failure
|
|
|
|
*/
|
|
|
|
GrBackendTexture getBackendTexture(BackendHandleAccess backendHandleAccess);
|
|
|
|
|
2018-05-30 13:20:29 +00:00
|
|
|
/** Retrieves the back-end render target. If SkSurface has no back-end render target, an invalid
|
2018-04-05 13:30:38 +00:00
|
|
|
object is returned. Call GrBackendRenderTarget::isValid to determine if the result
|
|
|
|
is valid.
|
|
|
|
|
2018-05-30 13:20:29 +00:00
|
|
|
The returned GrBackendRenderTarget should be discarded if the SkSurface is drawn to
|
2018-04-05 13:30:38 +00:00
|
|
|
or deleted.
|
|
|
|
|
|
|
|
@return GPU render target reference; invalid on failure
|
|
|
|
*/
|
|
|
|
GrBackendRenderTarget getBackendRenderTarget(BackendHandleAccess backendHandleAccess);
|
|
|
|
|
2019-05-24 14:16:35 +00:00
|
|
|
/** If the surface was made via MakeFromBackendTexture then it's backing texture may be
|
|
|
|
substituted with a different texture. The contents of the previous backing texture are
|
|
|
|
copied into the new texture. SkCanvas state is preserved. The original sample count is
|
|
|
|
used. The GrBackendFormat and dimensions of replacement texture must match that of
|
|
|
|
the original.
|
|
|
|
|
2020-06-03 02:01:39 +00:00
|
|
|
Upon success textureReleaseProc is called when it is safe to delete the texture in the
|
|
|
|
backend API (accounting only for use of the texture by this surface). If SkSurface creation
|
|
|
|
fails textureReleaseProc is called before this function returns.
|
|
|
|
|
2020-02-14 23:10:40 +00:00
|
|
|
@param backendTexture the new backing texture for the surface
|
|
|
|
@param mode Retain or discard current Content
|
2019-05-24 14:16:35 +00:00
|
|
|
@param textureReleaseProc function called when texture can be released
|
|
|
|
@param releaseContext state passed to textureReleaseProc
|
|
|
|
*/
|
|
|
|
bool replaceBackendTexture(const GrBackendTexture& backendTexture,
|
|
|
|
GrSurfaceOrigin origin,
|
2020-02-14 23:10:40 +00:00
|
|
|
ContentChangeMode mode = kRetain_ContentChangeMode,
|
2019-05-24 14:16:35 +00:00
|
|
|
TextureReleaseProc textureReleaseProc = nullptr,
|
|
|
|
ReleaseContext releaseContext = nullptr);
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Returns SkCanvas that draws into SkSurface. Subsequent calls return the same SkCanvas.
|
|
|
|
SkCanvas returned is managed and owned by SkSurface, and is deleted when SkSurface
|
|
|
|
is deleted.
|
|
|
|
|
|
|
|
@return drawing SkCanvas for SkSurface
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Surface_getCanvas
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2012-07-30 21:03:46 +00:00
|
|
|
SkCanvas* getCanvas();
|
2012-07-27 21:10:42 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Returns a compatible SkSurface, or nullptr. Returned SkSurface contains
|
|
|
|
the same raster, GPU, or null properties as the original. Returned SkSurface
|
|
|
|
does not share the same pixels.
|
|
|
|
|
|
|
|
Returns nullptr if imageInfo width or height are zero, or if imageInfo
|
|
|
|
is incompatible with SkSurface.
|
|
|
|
|
|
|
|
@param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace,
|
|
|
|
of SkSurface; width and height must be greater than zero
|
|
|
|
@return compatible SkSurface or nullptr
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Surface_makeSurface
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2017-11-03 12:06:09 +00:00
|
|
|
sk_sp<SkSurface> makeSurface(const SkImageInfo& imageInfo);
|
2012-07-27 21:10:42 +00:00
|
|
|
|
2019-06-17 21:45:01 +00:00
|
|
|
/** Calls makeSurface(ImageInfo) with the same ImageInfo as this surface, but with the
|
|
|
|
* specified width and height.
|
|
|
|
*/
|
|
|
|
sk_sp<SkSurface> makeSurface(int width, int height);
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Returns SkImage capturing SkSurface contents. Subsequent drawing to SkSurface contents
|
|
|
|
are not captured. SkImage allocation is accounted for if SkSurface was created with
|
|
|
|
SkBudgeted::kYes.
|
|
|
|
|
|
|
|
@return SkImage initialized with SkSurface contents
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Surface_makeImageSnapshot
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2017-03-20 12:38:50 +00:00
|
|
|
sk_sp<SkImage> makeImageSnapshot();
|
2012-07-27 21:10:42 +00:00
|
|
|
|
2018-11-21 14:12:09 +00:00
|
|
|
/**
|
|
|
|
* Like the no-parameter version, this returns an image of the current surface contents.
|
|
|
|
* This variant takes a rectangle specifying the subset of the surface that is of interest.
|
|
|
|
* These bounds will be sanitized before being used.
|
|
|
|
* - If bounds extends beyond the surface, it will be trimmed to just the intersection of
|
|
|
|
* it and the surface.
|
|
|
|
* - If bounds does not intersect the surface, then this returns nullptr.
|
|
|
|
* - If bounds == the surface, then this is the same as calling the no-parameter variant.
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Surface_makeImageSnapshot_2
|
2018-11-21 14:12:09 +00:00
|
|
|
*/
|
|
|
|
sk_sp<SkImage> makeImageSnapshot(const SkIRect& bounds);
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Draws SkSurface contents to canvas, with its top-left corner at (x, y).
|
|
|
|
|
2020-05-26 21:31:28 +00:00
|
|
|
If SkPaint paint is not nullptr, apply SkColorFilter, alpha, SkImageFilter, and SkBlendMode.
|
2018-02-27 15:22:04 +00:00
|
|
|
|
|
|
|
@param canvas SkCanvas drawn into
|
|
|
|
@param x horizontal offset in SkCanvas
|
|
|
|
@param y vertical offset in SkCanvas
|
2021-01-06 13:43:51 +00:00
|
|
|
@param sampling what technique to use when sampling the surface pixels
|
2018-02-27 15:22:04 +00:00
|
|
|
@param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
|
|
|
|
and so on; or nullptr
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Surface_draw
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2021-01-06 13:43:51 +00:00
|
|
|
void draw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkSamplingOptions& sampling,
|
|
|
|
const SkPaint* paint);
|
|
|
|
void draw(SkCanvas* canvas, SkScalar x, SkScalar y) {
|
|
|
|
this->draw(canvas, x, y, SkSamplingOptions(), nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// DEPRECATED -- use explicit sampling options
|
2017-11-03 12:06:09 +00:00
|
|
|
void draw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint);
|
2012-07-27 21:10:42 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Copies SkSurface pixel address, row bytes, and SkImageInfo to SkPixmap, if address
|
|
|
|
is available, and returns true. If pixel address is not available, return
|
|
|
|
false and leave SkPixmap unchanged.
|
|
|
|
|
|
|
|
pixmap contents become invalid on any future change to SkSurface.
|
|
|
|
|
|
|
|
@param pixmap storage for pixel state if pixels are readable; otherwise, ignored
|
|
|
|
@return true if SkSurface has direct access to pixels
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Surface_peekPixels
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2017-11-03 12:06:09 +00:00
|
|
|
bool peekPixels(SkPixmap* pixmap);
|
2016-03-09 22:26:26 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Copies SkRect of pixels to dst.
|
|
|
|
|
|
|
|
Source SkRect corners are (srcX, srcY) and SkSurface (width(), height()).
|
|
|
|
Destination SkRect corners are (0, 0) and (dst.width(), dst.height()).
|
|
|
|
Copies each readable pixel intersecting both rectangles, without scaling,
|
|
|
|
converting to dst.colorType() and dst.alphaType() if required.
|
|
|
|
|
|
|
|
Pixels are readable when SkSurface is raster, or backed by a GPU.
|
|
|
|
|
|
|
|
The destination pixel storage must be allocated by the caller.
|
|
|
|
|
|
|
|
Pixel values are converted only if SkColorType and SkAlphaType
|
|
|
|
do not match. Only pixels within both source and destination rectangles
|
|
|
|
are copied. dst contents outside SkRect intersection are unchanged.
|
|
|
|
|
|
|
|
Pass negative values for srcX or srcY to offset pixels across or down destination.
|
|
|
|
|
|
|
|
Does not copy, and returns false if:
|
|
|
|
- Source and destination rectangles do not intersect.
|
|
|
|
- SkPixmap pixels could not be allocated.
|
|
|
|
- dst.rowBytes() is too small to contain one row of pixels.
|
|
|
|
|
|
|
|
@param dst storage for pixels copied from SkSurface
|
2018-06-14 17:21:08 +00:00
|
|
|
@param srcX offset into readable pixels on x-axis; may be negative
|
|
|
|
@param srcY offset into readable pixels on y-axis; may be negative
|
2018-02-27 15:22:04 +00:00
|
|
|
@return true if pixels were copied
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Surface_readPixels
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2017-07-21 15:01:18 +00:00
|
|
|
bool readPixels(const SkPixmap& dst, int srcX, int srcY);
|
2018-02-27 15:22:04 +00:00
|
|
|
|
|
|
|
/** Copies SkRect of pixels from SkCanvas into dstPixels.
|
|
|
|
|
|
|
|
Source SkRect corners are (srcX, srcY) and SkSurface (width(), height()).
|
|
|
|
Destination SkRect corners are (0, 0) and (dstInfo.width(), dstInfo.height()).
|
|
|
|
Copies each readable pixel intersecting both rectangles, without scaling,
|
|
|
|
converting to dstInfo.colorType() and dstInfo.alphaType() if required.
|
|
|
|
|
|
|
|
Pixels are readable when SkSurface is raster, or backed by a GPU.
|
|
|
|
|
|
|
|
The destination pixel storage must be allocated by the caller.
|
|
|
|
|
|
|
|
Pixel values are converted only if SkColorType and SkAlphaType
|
|
|
|
do not match. Only pixels within both source and destination rectangles
|
|
|
|
are copied. dstPixels contents outside SkRect intersection are unchanged.
|
|
|
|
|
|
|
|
Pass negative values for srcX or srcY to offset pixels across or down destination.
|
|
|
|
|
|
|
|
Does not copy, and returns false if:
|
|
|
|
- Source and destination rectangles do not intersect.
|
|
|
|
- SkSurface pixels could not be converted to dstInfo.colorType() or dstInfo.alphaType().
|
|
|
|
- dstRowBytes is too small to contain one row of pixels.
|
|
|
|
|
|
|
|
@param dstInfo width, height, SkColorType, and SkAlphaType of dstPixels
|
|
|
|
@param dstPixels storage for pixels; dstInfo.height() times dstRowBytes, or larger
|
|
|
|
@param dstRowBytes size of one destination row; dstInfo.width() times pixel size, or larger
|
2018-06-14 17:21:08 +00:00
|
|
|
@param srcX offset into readable pixels on x-axis; may be negative
|
|
|
|
@param srcY offset into readable pixels on y-axis; may be negative
|
2018-02-27 15:22:04 +00:00
|
|
|
@return true if pixels were copied
|
|
|
|
*/
|
2014-12-09 22:39:44 +00:00
|
|
|
bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
|
|
|
|
int srcX, int srcY);
|
2018-02-27 15:22:04 +00:00
|
|
|
|
|
|
|
/** Copies SkRect of pixels from SkSurface into bitmap.
|
|
|
|
|
|
|
|
Source SkRect corners are (srcX, srcY) and SkSurface (width(), height()).
|
|
|
|
Destination SkRect corners are (0, 0) and (bitmap.width(), bitmap.height()).
|
|
|
|
Copies each readable pixel intersecting both rectangles, without scaling,
|
|
|
|
converting to bitmap.colorType() and bitmap.alphaType() if required.
|
|
|
|
|
|
|
|
Pixels are readable when SkSurface is raster, or backed by a GPU.
|
|
|
|
|
|
|
|
The destination pixel storage must be allocated by the caller.
|
|
|
|
|
|
|
|
Pixel values are converted only if SkColorType and SkAlphaType
|
|
|
|
do not match. Only pixels within both source and destination rectangles
|
|
|
|
are copied. dst contents outside SkRect intersection are unchanged.
|
|
|
|
|
|
|
|
Pass negative values for srcX or srcY to offset pixels across or down destination.
|
|
|
|
|
|
|
|
Does not copy, and returns false if:
|
|
|
|
- Source and destination rectangles do not intersect.
|
|
|
|
- SkSurface pixels could not be converted to dst.colorType() or dst.alphaType().
|
|
|
|
- dst pixels could not be allocated.
|
|
|
|
- dst.rowBytes() is too small to contain one row of pixels.
|
|
|
|
|
|
|
|
@param dst storage for pixels copied from SkSurface
|
2018-06-14 17:21:08 +00:00
|
|
|
@param srcX offset into readable pixels on x-axis; may be negative
|
|
|
|
@param srcY offset into readable pixels on y-axis; may be negative
|
2018-02-27 15:22:04 +00:00
|
|
|
@return true if pixels were copied
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Surface_readPixels_3
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2017-07-21 15:01:18 +00:00
|
|
|
bool readPixels(const SkBitmap& dst, int srcX, int srcY);
|
2014-12-09 22:39:44 +00:00
|
|
|
|
2020-06-26 17:32:09 +00:00
|
|
|
using AsyncReadResult = SkImage::AsyncReadResult;
|
2019-10-03 17:26:54 +00:00
|
|
|
|
|
|
|
/** Client-provided context that is passed to client-provided ReadPixelsContext. */
|
|
|
|
using ReadPixelsContext = void*;
|
|
|
|
|
|
|
|
/** Client-provided callback to asyncRescaleAndReadPixels() or
|
|
|
|
asyncRescaleAndReadPixelsYUV420() that is called when read result is ready or on failure.
|
|
|
|
*/
|
|
|
|
using ReadPixelsCallback = void(ReadPixelsContext, std::unique_ptr<const AsyncReadResult>);
|
|
|
|
|
|
|
|
/** Controls the gamma that rescaling occurs in for asyncRescaleAndReadPixels() and
|
|
|
|
asyncRescaleAndReadPixelsYUV420().
|
|
|
|
*/
|
2020-06-26 17:32:09 +00:00
|
|
|
using RescaleGamma = SkImage::RescaleGamma;
|
2021-01-03 02:44:59 +00:00
|
|
|
using RescaleMode = SkImage::RescaleMode;
|
2019-10-03 17:26:54 +00:00
|
|
|
|
|
|
|
/** Makes surface pixel data available to caller, possibly asynchronously. It can also rescale
|
|
|
|
the surface pixels.
|
2019-05-10 18:24:50 +00:00
|
|
|
|
|
|
|
Currently asynchronous reads are only supported on the GPU backend and only when the
|
|
|
|
underlying 3D API supports transfer buffers and CPU/GPU synchronization primitives. In all
|
|
|
|
other cases this operates synchronously.
|
|
|
|
|
2019-10-03 17:26:54 +00:00
|
|
|
Data is read from the source sub-rectangle, is optionally converted to a linear gamma, is
|
2019-05-17 16:05:44 +00:00
|
|
|
rescaled to the size indicated by 'info', is then converted to the color space, color type,
|
2019-10-03 17:26:54 +00:00
|
|
|
and alpha type of 'info'. A 'srcRect' that is not contained by the bounds of the surface
|
|
|
|
causes failure.
|
|
|
|
|
|
|
|
When the pixel data is ready the caller's ReadPixelsCallback is called with a
|
|
|
|
AsyncReadResult containing pixel data in the requested color type, alpha type, and color
|
|
|
|
space. The AsyncReadResult will have count() == 1. Upon failure the callback is called
|
2020-06-02 15:47:26 +00:00
|
|
|
with nullptr for AsyncReadResult. For a GPU surface this flushes work but a submit must
|
|
|
|
occur to guarantee a finite time before the callback is called.
|
2019-10-03 17:26:54 +00:00
|
|
|
|
|
|
|
The data is valid for the lifetime of AsyncReadResult with the exception that if the
|
2020-10-20 14:11:53 +00:00
|
|
|
SkSurface is GPU-backed the data is immediately invalidated if the context is abandoned
|
2019-10-03 17:26:54 +00:00
|
|
|
or destroyed.
|
|
|
|
|
|
|
|
@param info info of the requested pixels
|
|
|
|
@param srcRect subrectangle of surface to read
|
|
|
|
@param rescaleGamma controls whether rescaling is done in the surface's gamma or whether
|
|
|
|
the source data is transformed to a linear gamma before rescaling.
|
2021-01-03 02:44:59 +00:00
|
|
|
@param rescaleMode controls the technique of the rescaling
|
2019-10-03 17:26:54 +00:00
|
|
|
@param callback function to call with result of the read
|
|
|
|
@param context passed to callback
|
|
|
|
*/
|
2020-06-26 17:32:09 +00:00
|
|
|
void asyncRescaleAndReadPixels(const SkImageInfo& info,
|
|
|
|
const SkIRect& srcRect,
|
|
|
|
RescaleGamma rescaleGamma,
|
2021-01-03 02:44:59 +00:00
|
|
|
RescaleMode rescaleMode,
|
2020-06-26 17:32:09 +00:00
|
|
|
ReadPixelsCallback callback,
|
|
|
|
ReadPixelsContext context);
|
2019-10-03 09:06:25 +00:00
|
|
|
|
2019-06-11 15:38:16 +00:00
|
|
|
/**
|
|
|
|
Similar to asyncRescaleAndReadPixels but performs an additional conversion to YUV. The
|
|
|
|
RGB->YUV conversion is controlled by 'yuvColorSpace'. The YUV data is returned as three
|
|
|
|
planes ordered y, u, v. The u and v planes are half the width and height of the resized
|
2019-10-03 17:26:54 +00:00
|
|
|
rectangle. The y, u, and v values are single bytes. Currently this fails if 'dstSize'
|
|
|
|
width and height are not even. A 'srcRect' that is not contained by the bounds of the
|
|
|
|
surface causes failure.
|
2019-06-11 15:38:16 +00:00
|
|
|
|
2019-10-03 17:26:54 +00:00
|
|
|
When the pixel data is ready the caller's ReadPixelsCallback is called with a
|
|
|
|
AsyncReadResult containing the planar data. The AsyncReadResult will have count() == 3.
|
2020-06-02 15:47:26 +00:00
|
|
|
Upon failure the callback is called with nullptr for AsyncReadResult. For a GPU surface this
|
|
|
|
flushes work but a submit must occur to guarantee a finite time before the callback is
|
|
|
|
called.
|
2019-10-03 17:26:54 +00:00
|
|
|
|
|
|
|
The data is valid for the lifetime of AsyncReadResult with the exception that if the
|
2020-10-20 14:11:53 +00:00
|
|
|
SkSurface is GPU-backed the data is immediately invalidated if the context is abandoned
|
2019-10-03 17:26:54 +00:00
|
|
|
or destroyed.
|
2019-06-11 15:38:16 +00:00
|
|
|
|
|
|
|
@param yuvColorSpace The transformation from RGB to YUV. Applied to the resized image
|
|
|
|
after it is converted to dstColorSpace.
|
|
|
|
@param dstColorSpace The color space to convert the resized image to, after rescaling.
|
|
|
|
@param srcRect The portion of the surface to rescale and convert to YUV planes.
|
2019-10-03 17:26:54 +00:00
|
|
|
@param dstSize The size to rescale srcRect to
|
|
|
|
@param rescaleGamma controls whether rescaling is done in the surface's gamma or whether
|
|
|
|
the source data is transformed to a linear gamma before rescaling.
|
2021-01-03 02:44:59 +00:00
|
|
|
@param rescaleMode controls the sampling technique of the rescaling
|
2019-10-03 17:26:54 +00:00
|
|
|
@param callback function to call with the planar read result
|
|
|
|
@param context passed to callback
|
|
|
|
*/
|
|
|
|
void asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
|
|
|
|
sk_sp<SkColorSpace> dstColorSpace,
|
|
|
|
const SkIRect& srcRect,
|
|
|
|
const SkISize& dstSize,
|
|
|
|
RescaleGamma rescaleGamma,
|
2021-01-03 02:44:59 +00:00
|
|
|
RescaleMode rescaleMode,
|
2019-10-03 17:26:54 +00:00
|
|
|
ReadPixelsCallback callback,
|
2020-06-26 17:32:09 +00:00
|
|
|
ReadPixelsContext context);
|
2019-10-03 17:26:54 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Copies SkRect of pixels from the src SkPixmap to the SkSurface.
|
|
|
|
|
|
|
|
Source SkRect corners are (0, 0) and (src.width(), src.height()).
|
2018-09-13 18:08:12 +00:00
|
|
|
Destination SkRect corners are (dstX, dstY) and
|
|
|
|
(dstX + Surface width(), dstY + Surface height()).
|
2018-07-13 12:21:59 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
Copies each readable pixel intersecting both rectangles, without scaling,
|
|
|
|
converting to SkSurface colorType() and SkSurface alphaType() if required.
|
|
|
|
|
|
|
|
@param src storage for pixels to copy to SkSurface
|
2018-06-14 17:21:08 +00:00
|
|
|
@param dstX x-axis position relative to SkSurface to begin copy; may be negative
|
|
|
|
@param dstY y-axis position relative to SkSurface to begin copy; may be negative
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Surface_writePixels
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2018-02-08 19:10:40 +00:00
|
|
|
void writePixels(const SkPixmap& src, int dstX, int dstY);
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Copies SkRect of pixels from the src SkBitmap to the SkSurface.
|
|
|
|
|
|
|
|
Source SkRect corners are (0, 0) and (src.width(), src.height()).
|
2018-09-13 18:08:12 +00:00
|
|
|
Destination SkRect corners are (dstX, dstY) and
|
|
|
|
(dstX + Surface width(), dstY + Surface height()).
|
2018-07-13 12:21:59 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
Copies each readable pixel intersecting both rectangles, without scaling,
|
|
|
|
converting to SkSurface colorType() and SkSurface alphaType() if required.
|
|
|
|
|
|
|
|
@param src storage for pixels to copy to SkSurface
|
2018-06-14 17:21:08 +00:00
|
|
|
@param dstX x-axis position relative to SkSurface to begin copy; may be negative
|
|
|
|
@param dstY y-axis position relative to SkSurface to begin copy; may be negative
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Surface_writePixels_2
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2018-02-08 19:10:40 +00:00
|
|
|
void writePixels(const SkBitmap& src, int dstX, int dstY);
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Returns SkSurfaceProps for surface.
|
|
|
|
|
|
|
|
@return LCD striping orientation and setting for device independent fonts
|
|
|
|
*/
|
2014-09-22 14:29:03 +00:00
|
|
|
const SkSurfaceProps& props() const { return fProps; }
|
|
|
|
|
2020-05-13 18:07:40 +00:00
|
|
|
/** Call to ensure all reads/writes of the surface have been issued to the underlying 3D API.
|
|
|
|
Skia will correctly order its own draws and pixel operations. This must to be used to ensure
|
|
|
|
correct ordering when the surface backing store is accessed outside Skia (e.g. direct use of
|
2020-10-20 14:11:53 +00:00
|
|
|
the 3D API or a windowing system). GrDirectContext has additional flush and submit methods
|
|
|
|
that apply to all surfaces and images created from a GrDirectContext. This is equivalent to
|
|
|
|
calling SkSurface::flush with a default GrFlushInfo followed by
|
|
|
|
GrDirectContext::submit(syncCpu).
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2020-10-06 14:07:38 +00:00
|
|
|
void flushAndSubmit(bool syncCpu = false);
|
2020-05-13 18:07:40 +00:00
|
|
|
|
2019-03-01 20:24:35 +00:00
|
|
|
enum class BackendSurfaceAccess {
|
|
|
|
kNoAccess, //!< back-end object will not be used by client
|
|
|
|
kPresent, //!< back-end surface will be used for presenting to screen
|
|
|
|
};
|
|
|
|
|
2020-05-20 17:16:00 +00:00
|
|
|
/** Issues pending SkSurface commands to the GPU-backed API objects and resolves any SkSurface
|
2020-10-20 14:11:53 +00:00
|
|
|
MSAA. A call to GrDirectContext::submit is always required to ensure work is actually sent
|
|
|
|
to the gpu. Some specific API details:
|
2020-05-20 17:16:00 +00:00
|
|
|
GL: Commands are actually sent to the driver, but glFlush is never called. Thus some
|
|
|
|
sync objects from the flush will not be valid until a submission occurs.
|
|
|
|
|
|
|
|
Vulkan/Metal/D3D/Dawn: Commands are recorded to the backend APIs corresponding command
|
|
|
|
buffer or encoder objects. However, these objects are not sent to the gpu until a
|
|
|
|
submission occurs.
|
|
|
|
|
2019-03-01 20:24:35 +00:00
|
|
|
The work that is submitted to the GPU will be dependent on the BackendSurfaceAccess that is
|
|
|
|
passed in.
|
|
|
|
|
|
|
|
If BackendSurfaceAccess::kNoAccess is passed in all commands will be issued to the GPU.
|
|
|
|
|
|
|
|
If BackendSurfaceAccess::kPresent is passed in and the backend API is not Vulkan, it is
|
|
|
|
treated the same as kNoAccess. If the backend API is Vulkan, the VkImage that backs the
|
|
|
|
SkSurface will be transferred back to its original queue. If the SkSurface was created by
|
|
|
|
wrapping a VkImage, the queue will be set to the queue which was originally passed in on
|
|
|
|
the GrVkImageInfo. Additionally, if the original queue was not external or foreign the
|
|
|
|
layout of the VkImage will be set to VK_IMAGE_LAYOUT_PRESENT_SRC_KHR.
|
|
|
|
|
2019-04-17 19:26:11 +00:00
|
|
|
The GrFlushInfo describes additional options to flush. Please see documentation at
|
|
|
|
GrFlushInfo for more info.
|
2019-03-01 20:24:35 +00:00
|
|
|
|
2020-05-20 17:16:00 +00:00
|
|
|
If the return is GrSemaphoresSubmitted::kYes, only initialized GrBackendSemaphores will be
|
|
|
|
submitted to the gpu during the next submit call (it is possible Skia failed to create a
|
|
|
|
subset of the semaphores). The client should not wait on these semaphores until after submit
|
|
|
|
has been called, but must keep them alive until then. If a submit flag was passed in with
|
|
|
|
the flush these valid semaphores can we waited on immediately. If this call returns
|
|
|
|
GrSemaphoresSubmitted::kNo, the GPU backend will not submit any semaphores to be signaled on
|
|
|
|
the GPU. Thus the client should not have the GPU wait on any of the semaphores passed in
|
|
|
|
with the GrFlushInfo. Regardless of whether semaphores were submitted to the GPU or not, the
|
|
|
|
client is still responsible for deleting any initialized semaphores.
|
|
|
|
Regardleess of semaphore submission the context will still be flushed. It should be
|
|
|
|
emphasized that a return value of GrSemaphoresSubmitted::kNo does not mean the flush did not
|
|
|
|
happen. It simply means there were no semaphores submitted to the GPU. A caller should only
|
|
|
|
take this as a failure if they passed in semaphores to be submitted.
|
2019-03-01 20:24:35 +00:00
|
|
|
|
|
|
|
Pending surface commands are flushed regardless of the return result.
|
|
|
|
|
2019-04-17 19:26:11 +00:00
|
|
|
@param access type of access the call will do on the backend object after flush
|
|
|
|
@param info flush options
|
|
|
|
*/
|
|
|
|
GrSemaphoresSubmitted flush(BackendSurfaceAccess access, const GrFlushInfo& info);
|
2019-03-01 20:24:35 +00:00
|
|
|
|
2020-06-11 15:51:06 +00:00
|
|
|
/** Issues pending SkSurface commands to the GPU-backed API objects and resolves any SkSurface
|
2020-10-20 14:11:53 +00:00
|
|
|
MSAA. A call to GrDirectContext::submit is always required to ensure work is actually sent
|
|
|
|
to the gpu. Some specific API details:
|
2020-06-11 15:51:06 +00:00
|
|
|
GL: Commands are actually sent to the driver, but glFlush is never called. Thus some
|
|
|
|
sync objects from the flush will not be valid until a submission occurs.
|
|
|
|
|
|
|
|
Vulkan/Metal/D3D/Dawn: Commands are recorded to the backend APIs corresponding command
|
|
|
|
buffer or encoder objects. However, these objects are not sent to the gpu until a
|
|
|
|
submission occurs.
|
|
|
|
|
|
|
|
The GrFlushInfo describes additional options to flush. Please see documentation at
|
|
|
|
GrFlushInfo for more info.
|
|
|
|
|
|
|
|
If a GrBackendSurfaceMutableState is passed in, at the end of the flush we will transition
|
|
|
|
the surface to be in the state requested by the GrBackendSurfaceMutableState. If the surface
|
|
|
|
(or SkImage or GrBackendSurface wrapping the same backend object) is used again after this
|
|
|
|
flush the state may be changed and no longer match what is requested here. This is often
|
|
|
|
used if the surface will be used for presenting or external use and the client wants backend
|
|
|
|
object to be prepped for that use. A finishedProc or semaphore on the GrFlushInfo will also
|
|
|
|
include the work for any requested state change.
|
|
|
|
|
2020-09-21 20:02:21 +00:00
|
|
|
If the backend API is Vulkan, the caller can set the GrBackendSurfaceMutableState's
|
|
|
|
VkImageLayout to VK_IMAGE_LAYOUT_UNDEFINED or queueFamilyIndex to VK_QUEUE_FAMILY_IGNORED to
|
|
|
|
tell Skia to not change those respective states.
|
|
|
|
|
2020-06-11 15:51:06 +00:00
|
|
|
If the return is GrSemaphoresSubmitted::kYes, only initialized GrBackendSemaphores will be
|
|
|
|
submitted to the gpu during the next submit call (it is possible Skia failed to create a
|
|
|
|
subset of the semaphores). The client should not wait on these semaphores until after submit
|
|
|
|
has been called, but must keep them alive until then. If a submit flag was passed in with
|
|
|
|
the flush these valid semaphores can we waited on immediately. If this call returns
|
|
|
|
GrSemaphoresSubmitted::kNo, the GPU backend will not submit any semaphores to be signaled on
|
|
|
|
the GPU. Thus the client should not have the GPU wait on any of the semaphores passed in
|
|
|
|
with the GrFlushInfo. Regardless of whether semaphores were submitted to the GPU or not, the
|
|
|
|
client is still responsible for deleting any initialized semaphores.
|
|
|
|
Regardleess of semaphore submission the context will still be flushed. It should be
|
|
|
|
emphasized that a return value of GrSemaphoresSubmitted::kNo does not mean the flush did not
|
|
|
|
happen. It simply means there were no semaphores submitted to the GPU. A caller should only
|
|
|
|
take this as a failure if they passed in semaphores to be submitted.
|
|
|
|
|
|
|
|
Pending surface commands are flushed regardless of the return result.
|
|
|
|
|
|
|
|
@param info flush options
|
|
|
|
@param access optional state change request after flush
|
|
|
|
*/
|
|
|
|
GrSemaphoresSubmitted flush(const GrFlushInfo& info,
|
|
|
|
const GrBackendSurfaceMutableState* newState = nullptr);
|
|
|
|
|
2020-06-26 01:00:17 +00:00
|
|
|
void flush() { this->flush({}); }
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Inserts a list of GPU semaphores that the current GPU-backed API must wait on before
|
2020-07-08 15:44:25 +00:00
|
|
|
executing any more commands on the GPU for this surface. If this call returns false, then
|
|
|
|
the GPU back-end will not wait on any passed in semaphores, and the client will still own
|
|
|
|
the semaphores, regardless of the value of deleteSemaphoresAfterWait.
|
|
|
|
|
|
|
|
If deleteSemaphoresAfterWait is false then Skia will not delete the semaphores. In this case
|
|
|
|
it is the client's responsibility to not destroy or attempt to reuse the semaphores until it
|
|
|
|
knows that Skia has finished waiting on them. This can be done by using finishedProcs
|
|
|
|
on flush calls.
|
|
|
|
|
|
|
|
@param numSemaphores size of waitSemaphores array
|
|
|
|
@param waitSemaphores array of semaphore containers
|
|
|
|
@paramm deleteSemaphoresAfterWait who owns and should delete the semaphores
|
|
|
|
@return true if GPU is waiting on semaphores
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2020-07-08 15:44:25 +00:00
|
|
|
bool wait(int numSemaphores, const GrBackendSemaphore* waitSemaphores,
|
|
|
|
bool deleteSemaphoresAfterWait = true);
|
2017-06-16 13:45:32 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Initializes SkSurfaceCharacterization that can be used to perform GPU back-end
|
|
|
|
processing in a separate thread. Typically this is used to divide drawing
|
2018-10-31 14:54:50 +00:00
|
|
|
into multiple tiles. SkDeferredDisplayListRecorder records the drawing commands
|
2018-02-27 15:22:04 +00:00
|
|
|
for each tile.
|
|
|
|
|
|
|
|
Return true if SkSurface supports characterization. raster surface returns false.
|
|
|
|
|
|
|
|
@param characterization properties for parallel drawing
|
|
|
|
@return true if supported
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Surface_characterize
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2017-08-30 16:06:35 +00:00
|
|
|
bool characterize(SkSurfaceCharacterization* characterization) const;
|
|
|
|
|
2020-11-10 13:30:50 +00:00
|
|
|
/** Draws the deferred display list created via a SkDeferredDisplayListRecorder.
|
|
|
|
If the deferred display list is not compatible with this SkSurface, the draw is skipped
|
|
|
|
and false is return.
|
2018-02-27 15:22:04 +00:00
|
|
|
|
2020-11-10 13:30:50 +00:00
|
|
|
The xOffset and yOffset parameters are experimental and, if not both zero, will cause
|
|
|
|
the draw to be ignored.
|
|
|
|
When implemented, if xOffset or yOffset are non-zero, the DDL will be drawn offset by that
|
|
|
|
amount into the surface.
|
2018-02-27 15:22:04 +00:00
|
|
|
|
|
|
|
@param deferredDisplayList drawing commands
|
2020-11-10 13:30:50 +00:00
|
|
|
@param xOffset x-offset at which to draw the DDL
|
|
|
|
@param yOffset y-offset at which to draw the DDL
|
2018-02-27 15:22:04 +00:00
|
|
|
@return false if deferredDisplayList is not compatible
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Surface_draw_2
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2020-11-10 13:30:50 +00:00
|
|
|
bool draw(sk_sp<const SkDeferredDisplayList> deferredDisplayList,
|
|
|
|
int xOffset = 0,
|
|
|
|
int yOffset = 0);
|
2017-08-30 16:06:35 +00:00
|
|
|
|
2012-07-27 21:10:42 +00:00
|
|
|
protected:
|
2017-11-03 12:06:09 +00:00
|
|
|
SkSurface(int width, int height, const SkSurfaceProps* surfaceProps);
|
|
|
|
SkSurface(const SkImageInfo& imageInfo, const SkSurfaceProps* surfaceProps);
|
2012-07-27 21:10:42 +00:00
|
|
|
|
2012-08-28 12:19:02 +00:00
|
|
|
// called by subclass if their contents have changed
|
|
|
|
void dirtyGenerationID() {
|
|
|
|
fGenerationID = 0;
|
|
|
|
}
|
|
|
|
|
2012-07-27 21:10:42 +00:00
|
|
|
private:
|
2014-09-22 14:29:03 +00:00
|
|
|
const SkSurfaceProps fProps;
|
|
|
|
const int fWidth;
|
|
|
|
const int fHeight;
|
|
|
|
uint32_t fGenerationID;
|
2012-08-30 14:38:00 +00:00
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = SkRefCnt;
|
2012-07-27 21:10:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|