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
|
|
|
|
|
|
|
|
#include "GrTypes.h"
|
2018-11-16 20:43:41 +00:00
|
|
|
#include "GrBackendSurface.h"
|
2014-07-25 15:35:45 +00:00
|
|
|
#include "GrGpuResource.h"
|
2014-09-30 19:18:44 +00:00
|
|
|
#include "SkImageInfo.h"
|
2013-08-14 21:56:37 +00:00
|
|
|
#include "SkRect.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
|
|
|
|
2015-07-08 14:53:10 +00:00
|
|
|
class SK_API 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;
|
|
|
|
|
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
|
|
|
|
2016-11-17 19:43:51 +00:00
|
|
|
static size_t WorstCaseSize(const GrSurfaceDesc& desc, bool useNextPow2 = false);
|
2017-05-17 17:49:59 +00:00
|
|
|
static size_t ComputeSize(GrPixelConfig config, int width, int height, int colorSamplesPerPixel,
|
2017-10-23 20:05:23 +00:00
|
|
|
GrMipMapped, bool useNextPow2 = 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; }
|
|
|
|
|
2014-09-30 19:18:44 +00:00
|
|
|
protected:
|
2018-03-16 20:47:25 +00:00
|
|
|
void setHasMixedSamples() {
|
|
|
|
SkASSERT(this->asRenderTarget());
|
|
|
|
fSurfaceFlags |= GrInternalSurfaceFlags::kMixedSampled;
|
|
|
|
}
|
|
|
|
bool hasMixedSamples() const { return fSurfaceFlags & GrInternalSurfaceFlags::kMixedSampled; }
|
|
|
|
|
|
|
|
void setSupportsWindowRects() {
|
|
|
|
SkASSERT(this->asRenderTarget());
|
|
|
|
fSurfaceFlags |= GrInternalSurfaceFlags::kWindowRectsSupport;
|
|
|
|
}
|
|
|
|
bool supportsWindowRects() const {
|
|
|
|
return fSurfaceFlags & GrInternalSurfaceFlags::kWindowRectsSupport;
|
|
|
|
}
|
|
|
|
|
2018-04-26 20:31:38 +00:00
|
|
|
void setGLRTFBOIDIs0() {
|
|
|
|
SkASSERT(this->asRenderTarget());
|
|
|
|
fSurfaceFlags |= GrInternalSurfaceFlags::kGLRTFBOIDIs0;
|
|
|
|
}
|
|
|
|
bool glRTFBOIDis0() const {
|
|
|
|
return fSurfaceFlags & GrInternalSurfaceFlags::kGLRTFBOIDIs0;
|
|
|
|
}
|
|
|
|
|
2018-12-06 15:00:03 +00:00
|
|
|
void setReadOnly() {
|
|
|
|
SkASSERT(!this->asRenderTarget());
|
|
|
|
fSurfaceFlags |= GrInternalSurfaceFlags::kReadOnly;
|
|
|
|
}
|
|
|
|
|
2014-09-30 19:18:44 +00:00
|
|
|
// Methods made available via GrSurfacePriv
|
2014-09-22 19:21:08 +00:00
|
|
|
bool hasPendingRead() const;
|
|
|
|
bool hasPendingWrite() const;
|
|
|
|
bool hasPendingIO() const;
|
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
|
|
|
|
Refactor to separate backend object lifecycle and GpuResource budget decision
Refactor GrGpuResource to contain two different pieces of state:
a) instance is budgeted or not budgeted
b) instance references wrapped backend objects or not
The "object lifecycle" was also attached to backend object
handles (ids), which made the code a bit unclear. Backend objects
would be associated with GrGpuResource::LifeCycle, even though
GrGpuResource::LifeCycle refers to the GpuResource, and individual
backend objects in one GpuResource might be governed with different
"lifecycle".
Mark the budgeted/not budgeted with SkBudgeted::kYes, SkBudgeted::kNo.
This was previously GrGpuResource::kCached_LifeCycle,
GrGpuResource::kUncached_LifeCycle.
Mark the "references wrapped object" with boolean. This was previously
GrGpuResource::kBorrowed_LifeCycle,
GrGpuResource::kAdopted_LifeCycle for GrGpuResource.
Associate the backend object ownership status with
GrBackendObjectOwnership for the backend object handles.
The resource type leaf constuctors, such has GrGLTexture or
GrGLTextureRenderTarget take "budgeted" parameter. This parameter
is passed to GrGpuResource::registerWithCache().
The resource type intermediary constructors, such as GrGLTexture
constructors for class GrGLTextureRenderTarget do not take "budgeted"
parameters, intermediary construtors do not call registerWithCache.
Removes the need for tagging GrGpuResource -derived subclass
constructors with "Derived" parameter.
Makes instances that wrap backend objects be registered with
a new function GrGpuResource::registerWithCacheWrapped().
Removes "budgeted" parameter from classes such as StencilAttahment, as
they are always cached and never wrap any external backend objects.
Removes the use of concept "external" from the member function names.
The API refers to the objects as "wrapped", so make all related
functions use the term consistently.
No change in functionality. Resources referencing wrapped objects are
always inserted to the cache with budget decision kNo.
BUG=594928
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1862043002
Review URL: https://codereview.chromium.org/1862043002
2016-04-22 08:48:29 +00:00
|
|
|
GrSurface(GrGpu* gpu, const GrSurfaceDesc& desc)
|
2017-05-19 19:45:48 +00:00
|
|
|
: INHERITED(gpu)
|
|
|
|
, fConfig(desc.fConfig)
|
|
|
|
, fWidth(desc.fWidth)
|
2018-03-16 20:47:25 +00:00
|
|
|
, fHeight(desc.fHeight)
|
|
|
|
, fSurfaceFlags(GrInternalSurfaceFlags::kNone) {
|
|
|
|
}
|
|
|
|
|
2017-04-21 15:52:27 +00:00
|
|
|
~GrSurface() override {}
|
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"; }
|
|
|
|
|
2018-03-16 20:47:25 +00:00
|
|
|
GrPixelConfig fConfig;
|
|
|
|
int fWidth;
|
|
|
|
int fHeight;
|
|
|
|
GrInternalSurfaceFlags fSurfaceFlags;
|
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
|