blob: d7ccf1bcc74664673bb079bd2a1c34202bdf8452 [file] [log] [blame]
cdaltonb85a0aa2014-07-21 15:32:44 -07001
2/*
3 * Copyright 2014 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#include "GrGLPathRange.h"
10#include "GrGLPath.h"
cdaltonc7103a12014-08-11 14:05:05 -070011#include "GrGLPathRendering.h"
jvanverth39edf762014-12-22 11:44:19 -080012#include "GrGLGpu.h"
cdaltonb85a0aa2014-07-21 15:32:44 -070013
bsalomon861e1032014-12-16 07:33:49 -080014GrGLPathRange::GrGLPathRange(GrGLGpu* gpu, PathGenerator* pathGenerator, const SkStrokeRec& stroke)
cdalton855d83f2014-09-18 13:51:53 -070015 : INHERITED(gpu, pathGenerator, stroke),
16 fBasePathID(gpu->glPathRendering()->genPaths(this->getNumPaths())),
17 fGpuMemorySize(0) {
18 this->registerWithCache();
19}
20
bsalomon861e1032014-12-16 07:33:49 -080021GrGLPathRange::GrGLPathRange(GrGLGpu* gpu,
cdalton855d83f2014-09-18 13:51:53 -070022 GrGLuint basePathID,
23 int numPaths,
24 size_t gpuMemorySize,
25 const SkStrokeRec& stroke)
26 : INHERITED(gpu, numPaths, stroke),
27 fBasePathID(basePathID),
28 fGpuMemorySize(gpuMemorySize) {
29 this->registerWithCache();
cdaltonb85a0aa2014-07-21 15:32:44 -070030}
31
cdalton855d83f2014-09-18 13:51:53 -070032void GrGLPathRange::onInitPath(int index, const SkPath& skPath) const {
bsalomon861e1032014-12-16 07:33:49 -080033 GrGLGpu* gpu = static_cast<GrGLGpu*>(this->getGpu());
cdaltonb85a0aa2014-07-21 15:32:44 -070034 if (NULL == gpu) {
35 return;
36 }
37
cdaltonb85a0aa2014-07-21 15:32:44 -070038 // Make sure the path at this index hasn't been initted already.
kkinnunen5b653572014-08-20 04:13:27 -070039 SkDEBUGCODE(
40 GrGLboolean isPath;
41 GR_GL_CALL_RET(gpu->glInterface(), isPath, IsPath(fBasePathID + index)));
42 SkASSERT(GR_GL_FALSE == isPath);
cdaltonb85a0aa2014-07-21 15:32:44 -070043
cdalton855d83f2014-09-18 13:51:53 -070044 GrGLPath::InitPathObject(gpu, fBasePathID + index, skPath, this->getStroke());
45
46 // TODO: Use a better approximation for the individual path sizes.
47 fGpuMemorySize += 100;
cdaltonb85a0aa2014-07-21 15:32:44 -070048}
49
50void GrGLPathRange::onRelease() {
bsalomon49f085d2014-09-05 13:34:00 -070051 SkASSERT(this->getGpu());
cdaltonb85a0aa2014-07-21 15:32:44 -070052
53 if (0 != fBasePathID && !this->isWrapped()) {
bsalomon861e1032014-12-16 07:33:49 -080054 static_cast<GrGLGpu*>(this->getGpu())->glPathRendering()->deletePaths(fBasePathID,
cdalton855d83f2014-09-18 13:51:53 -070055 this->getNumPaths());
cdaltonb85a0aa2014-07-21 15:32:44 -070056 fBasePathID = 0;
57 }
58
59 INHERITED::onRelease();
60}
61
62void GrGLPathRange::onAbandon() {
63 fBasePathID = 0;
64
65 INHERITED::onAbandon();
66}