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
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;
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)
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.
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;
private:
GrGLuint fPathID;
+ size_t fGpuMemorySize;
typedef GrPath INHERITED;
};
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() {
// 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();
}
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;
private:
GrGLuint fBasePathID;
- size_t fNumDefinedPaths;
+ size_t fGpuMemorySize;
typedef GrPathRange INHERITED;
};