Calculate rough approximations for nvpr path sizes

Calculates a rough approximation of the actual value for gpuMemorySize
in GrGLPath and GrGLPathRange, instead of assuming every path is the
same fixed size.

BUG=skia:
R=bsalomon@google.com, markkilgard@gmail.com

Author: cdalton@nvidia.com

Review URL: https://codereview.chromium.org/442603002
This commit is contained in:
cdalton 2014-08-05 10:58:19 -07:00 committed by Commit bot
parent 0b7127635d
commit 61bff70972
4 changed files with 27 additions and 22 deletions

View File

@ -81,10 +81,10 @@ inline GrGLenum cap_to_gl_cap(SkPaint::Cap cap) {
static const bool kIsWrapped = false; // The constructor creates the GL path object.
void GrGLPath::InitPathObject(GrGpuGL* gpu,
GrGLuint pathID,
const SkPath& skPath,
const SkStrokeRec& stroke) {
size_t GrGLPath::InitPathObject(GrGpuGL* gpu,
GrGLuint pathID,
const SkPath& skPath,
const SkStrokeRec& stroke) {
GrGLPathRendering* pr = gpu->pathRendering();
SkSTArray<16, GrGLubyte, true> pathCommands;
SkSTArray<16, SkPoint, true> pathPoints;
@ -117,6 +117,13 @@ void GrGLPath::InitPathObject(GrGpuGL* gpu,
pr->pathParameteri(pathID, GR_GL_PATH_INITIAL_END_CAP, cap);
pr->pathParameteri(pathID, GR_GL_PATH_TERMINAL_END_CAP, cap);
}
size_t approximateSize = 5 * (verbCnt + pointCnt);
if (SkStrokeRec::kStrokeAndFill_Style == stroke.getStyle()) {
// It will take approxoimately twice the memory if it has both fill *and* stroke.
approximateSize *= 2;
}
return approximateSize;
}
GrGLPath::GrGLPath(GrGpuGL* gpu, const SkPath& path, const SkStrokeRec& stroke)
@ -124,7 +131,7 @@ GrGLPath::GrGLPath(GrGpuGL* gpu, const SkPath& path, const SkStrokeRec& stroke)
fPathID(gpu->pathRendering()->genPaths(1)) {
SkASSERT(!path.isEmpty());
InitPathObject(gpu, fPathID, fSkPath, stroke);
fGpuMemorySize = InitPathObject(gpu, fPathID, fSkPath, stroke);
if (stroke.needToApply()) {
// FIXME: try to account for stroking, without rasterizing the stroke.

View File

@ -22,17 +22,20 @@ class GrGpuGL;
class GrGLPath : public GrPath {
public:
static void InitPathObject(GrGpuGL*,
GrGLuint pathID,
const SkPath&,
const SkStrokeRec&);
/**
* Initialize a GL path object with a given path and stroke.
*
* @return the approximate GPU memory size of the path object in bytes.
*/
static size_t InitPathObject(GrGpuGL*,
GrGLuint pathID,
const SkPath&,
const SkStrokeRec&);
GrGLPath(GrGpuGL* gpu, const SkPath& path, const SkStrokeRec& stroke);
virtual ~GrGLPath();
GrGLuint pathID() const { return fPathID; }
// TODO: Figure out how to get an approximate size of the path in Gpu
// memory.
virtual size_t gpuMemorySize() const SK_OVERRIDE { return 100; }
virtual size_t gpuMemorySize() const SK_OVERRIDE { return fGpuMemorySize; }
protected:
virtual void onRelease() SK_OVERRIDE;
@ -40,6 +43,7 @@ protected:
private:
GrGLuint fPathID;
size_t fGpuMemorySize;
typedef GrPath INHERITED;
};

View File

@ -14,7 +14,7 @@
GrGLPathRange::GrGLPathRange(GrGpuGL* gpu, size_t size, const SkStrokeRec& stroke)
: INHERITED(gpu, size, stroke),
fBasePathID(gpu->pathRendering()->genPaths(fSize)),
fNumDefinedPaths(0) {
fGpuMemorySize(0) {
}
GrGLPathRange::~GrGLPathRange() {
@ -30,8 +30,7 @@ void GrGLPathRange::initAt(size_t index, const SkPath& skPath) {
// Make sure the path at this index hasn't been initted already.
SkASSERT(GR_GL_FALSE == gpu->pathRendering()->isPath(fBasePathID + index));
GrGLPath::InitPathObject(gpu, fBasePathID + index, skPath, fStroke);
++fNumDefinedPaths;
fGpuMemorySize += GrGLPath::InitPathObject(gpu, fBasePathID + index, skPath, fStroke);
this->didChangeGpuMemorySize();
}

View File

@ -26,13 +26,8 @@ public:
virtual ~GrGLPathRange();
GrGLuint basePathID() const { return fBasePathID; }
virtual void initAt(size_t index, const SkPath&);
// TODO: Use a better approximation for the individual path sizes.
virtual size_t gpuMemorySize() const SK_OVERRIDE {
return 100 * fNumDefinedPaths;
}
virtual size_t gpuMemorySize() const SK_OVERRIDE { return fGpuMemorySize; }
protected:
virtual void onRelease() SK_OVERRIDE;
@ -40,7 +35,7 @@ protected:
private:
GrGLuint fBasePathID;
size_t fNumDefinedPaths;
size_t fGpuMemorySize;
typedef GrPathRange INHERITED;
};