2012-06-21 21:09:06 +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 GrSurface_DEFINED
|
|
|
|
#define GrSurface_DEFINED
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkImageInfo.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/gpu/GrBackendSurface.h"
|
|
|
|
#include "include/gpu/GrGpuResource.h"
|
|
|
|
#include "include/gpu/GrTypes.h"
|
2012-06-21 21:09:06 +00:00
|
|
|
|
2014-09-30 13:58:20 +00:00
|
|
|
class GrRenderTarget;
|
2014-09-30 19:18:44 +00:00
|
|
|
class GrSurfacePriv;
|
|
|
|
class GrTexture;
|
2012-06-21 21:09:06 +00:00
|
|
|
|
2019-08-22 02:08:36 +00:00
|
|
|
class GrSurface : public GrGpuResource {
|
2012-06-21 21:09:06 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Retrieves the width of the surface.
|
|
|
|
*/
|
2017-05-19 19:45:48 +00:00
|
|
|
int width() const { return fWidth; }
|
2012-06-21 21:09:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves the height of the surface.
|
|
|
|
*/
|
2017-05-19 19:45:48 +00:00
|
|
|
int height() const { return fHeight; }
|
2012-06-21 21:09:06 +00:00
|
|
|
|
2013-08-14 21:56:37 +00:00
|
|
|
/**
|
|
|
|
* Helper that gets the width and height of the surface as a bounding rectangle.
|
|
|
|
*/
|
2016-08-31 22:06:24 +00:00
|
|
|
SkRect getBoundsRect() const { return SkRect::MakeIWH(this->width(), this->height()); }
|
2013-08-14 21:56:37 +00:00
|
|
|
|
2012-06-21 21:09:06 +00:00
|
|
|
/**
|
|
|
|
* Retrieves the pixel config specified when the surface was created.
|
|
|
|
* For render targets this can be kUnknown_GrPixelConfig
|
|
|
|
* if client asked us to render to a target that has a pixel
|
|
|
|
* config that isn't equivalent with one of our configs.
|
|
|
|
*/
|
2017-05-19 19:45:48 +00:00
|
|
|
GrPixelConfig config() const { return fConfig; }
|
2012-06-21 21:09:06 +00:00
|
|
|
|
2018-11-16 20:43:41 +00:00
|
|
|
virtual GrBackendFormat backendFormat() const = 0;
|
|
|
|
|
2019-08-22 02:08:36 +00:00
|
|
|
SK_API void setRelease(sk_sp<GrRefCntedCallback> releaseHelper) {
|
2019-02-01 19:48:10 +00:00
|
|
|
this->onSetRelease(releaseHelper);
|
|
|
|
fReleaseHelper = std::move(releaseHelper);
|
|
|
|
}
|
|
|
|
|
|
|
|
// These match the definitions in SkImage, from whence they came.
|
|
|
|
// TODO: Remove Chrome's need to call this on a GrTexture
|
|
|
|
typedef void* ReleaseCtx;
|
|
|
|
typedef void (*ReleaseProc)(ReleaseCtx);
|
2019-08-22 02:08:36 +00:00
|
|
|
SK_API void setRelease(ReleaseProc proc, ReleaseCtx ctx) {
|
2019-03-04 15:25:17 +00:00
|
|
|
sk_sp<GrRefCntedCallback> helper(new GrRefCntedCallback(proc, ctx));
|
2019-02-01 19:48:10 +00:00
|
|
|
this->setRelease(std::move(helper));
|
|
|
|
}
|
|
|
|
|
2012-06-21 21:09:06 +00:00
|
|
|
/**
|
2017-04-17 11:53:07 +00:00
|
|
|
* @return the texture associated with the surface, may be null.
|
2012-06-21 21:09:06 +00:00
|
|
|
*/
|
2017-04-17 11:53:07 +00:00
|
|
|
virtual GrTexture* asTexture() { return nullptr; }
|
|
|
|
virtual const GrTexture* asTexture() const { return nullptr; }
|
2012-06-21 21:09:06 +00:00
|
|
|
|
|
|
|
/**
|
2017-04-17 11:53:07 +00:00
|
|
|
* @return the render target underlying this surface, may be null.
|
2012-06-21 21:09:06 +00:00
|
|
|
*/
|
2017-04-17 11:53:07 +00:00
|
|
|
virtual GrRenderTarget* asRenderTarget() { return nullptr; }
|
|
|
|
virtual const GrRenderTarget* asRenderTarget() const { return nullptr; }
|
2012-06-21 21:09:06 +00:00
|
|
|
|
2014-09-30 19:18:44 +00:00
|
|
|
/** Access methods that are only to be used within Skia code. */
|
|
|
|
inline GrSurfacePriv surfacePriv();
|
|
|
|
inline const GrSurfacePriv surfacePriv() const;
|
2014-09-30 13:58:20 +00:00
|
|
|
|
2017-05-17 17:49:59 +00:00
|
|
|
static size_t ComputeSize(GrPixelConfig config, int width, int height, int colorSamplesPerPixel,
|
2019-07-11 13:03:27 +00:00
|
|
|
GrMipMapped, bool binSize = false);
|
2016-11-07 13:23:48 +00:00
|
|
|
|
2018-12-06 15:00:03 +00:00
|
|
|
/**
|
|
|
|
* The pixel values of this surface cannot be modified (e.g. doesn't support write pixels or
|
|
|
|
* MIP map level regen).
|
|
|
|
*/
|
|
|
|
bool readOnly() const { return fSurfaceFlags & GrInternalSurfaceFlags::kReadOnly; }
|
|
|
|
|
2019-06-24 14:53:09 +00:00
|
|
|
// Returns true if we are working with protected content.
|
|
|
|
bool isProtected() const { return fIsProtected == GrProtected::kYes; }
|
|
|
|
|
2014-09-30 19:18:44 +00:00
|
|
|
protected:
|
2018-04-26 20:31:38 +00:00
|
|
|
void setGLRTFBOIDIs0() {
|
2019-08-19 06:39:13 +00:00
|
|
|
SkASSERT(!this->requiresManualMSAAResolve());
|
|
|
|
SkASSERT(!this->asTexture());
|
2018-04-26 20:31:38 +00:00
|
|
|
SkASSERT(this->asRenderTarget());
|
|
|
|
fSurfaceFlags |= GrInternalSurfaceFlags::kGLRTFBOIDIs0;
|
|
|
|
}
|
|
|
|
bool glRTFBOIDis0() const {
|
|
|
|
return fSurfaceFlags & GrInternalSurfaceFlags::kGLRTFBOIDIs0;
|
|
|
|
}
|
|
|
|
|
2019-08-19 06:39:13 +00:00
|
|
|
void setRequiresManualMSAAResolve() {
|
|
|
|
SkASSERT(!this->glRTFBOIDis0());
|
|
|
|
SkASSERT(this->asRenderTarget());
|
|
|
|
fSurfaceFlags |= GrInternalSurfaceFlags::kRequiresManualMSAAResolve;
|
|
|
|
}
|
|
|
|
bool requiresManualMSAAResolve() const {
|
|
|
|
return fSurfaceFlags & GrInternalSurfaceFlags::kRequiresManualMSAAResolve;
|
|
|
|
}
|
|
|
|
|
2018-12-06 15:00:03 +00:00
|
|
|
void setReadOnly() {
|
|
|
|
SkASSERT(!this->asRenderTarget());
|
|
|
|
fSurfaceFlags |= GrInternalSurfaceFlags::kReadOnly;
|
|
|
|
}
|
|
|
|
|
2014-09-30 19:18:44 +00:00
|
|
|
// Provides access to methods that should be public within Skia code.
|
|
|
|
friend class GrSurfacePriv;
|
2014-09-22 19:21:08 +00:00
|
|
|
|
2019-08-05 16:57:09 +00:00
|
|
|
GrSurface(GrGpu* gpu, const SkISize& size, GrPixelConfig config, GrProtected isProtected)
|
2017-05-19 19:45:48 +00:00
|
|
|
: INHERITED(gpu)
|
2019-08-05 16:57:09 +00:00
|
|
|
, fConfig(config)
|
|
|
|
, fWidth(size.width())
|
|
|
|
, fHeight(size.height())
|
2019-06-24 14:53:09 +00:00
|
|
|
, fSurfaceFlags(GrInternalSurfaceFlags::kNone)
|
2019-07-19 18:24:36 +00:00
|
|
|
, fIsProtected(isProtected) {}
|
2018-03-16 20:47:25 +00:00
|
|
|
|
2019-02-01 19:48:10 +00:00
|
|
|
~GrSurface() override {
|
|
|
|
// check that invokeReleaseProc has been called (if needed)
|
|
|
|
SkASSERT(!fReleaseHelper);
|
|
|
|
}
|
2012-06-21 21:09:06 +00:00
|
|
|
|
2015-06-18 21:05:07 +00:00
|
|
|
void onRelease() override;
|
|
|
|
void onAbandon() override;
|
|
|
|
|
|
|
|
private:
|
2018-03-29 17:40:02 +00:00
|
|
|
const char* getResourceType() const override { return "Surface"; }
|
|
|
|
|
2019-03-04 15:25:42 +00:00
|
|
|
// Unmanaged backends (e.g. Vulkan) may want to specially handle the release proc in order to
|
|
|
|
// ensure it isn't called until GPU work related to the resource is completed.
|
|
|
|
virtual void onSetRelease(sk_sp<GrRefCntedCallback>) {}
|
|
|
|
|
2019-02-01 19:48:10 +00:00
|
|
|
void invokeReleaseProc() {
|
|
|
|
// Depending on the ref count of fReleaseHelper this may or may not actually trigger the
|
|
|
|
// ReleaseProc to be called.
|
|
|
|
fReleaseHelper.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
GrPixelConfig fConfig;
|
|
|
|
int fWidth;
|
|
|
|
int fHeight;
|
|
|
|
GrInternalSurfaceFlags fSurfaceFlags;
|
2019-06-24 14:53:09 +00:00
|
|
|
GrProtected fIsProtected;
|
2019-03-04 15:25:17 +00:00
|
|
|
sk_sp<GrRefCntedCallback> fReleaseHelper;
|
2017-05-19 19:45:48 +00:00
|
|
|
|
2014-07-25 15:35:45 +00:00
|
|
|
typedef GrGpuResource INHERITED;
|
2012-06-21 21:09:06 +00:00
|
|
|
};
|
|
|
|
|
2014-09-30 19:18:44 +00:00
|
|
|
#endif
|