blob: 9e2b2e73269e667d4f84c8e781bb9cedc61263fa [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"
cdalton5672da02014-08-04 11:19:11 -070011#include "GrGLPathRendering.h"
cdaltonb85a0aa2014-07-21 15:32:44 -070012#include "GrGpuGL.h"
13
cdalton5672da02014-08-04 11:19:11 -070014GrGLPathRange::GrGLPathRange(GrGpuGL* gpu, size_t size, const SkStrokeRec& stroke)
cdaltonb85a0aa2014-07-21 15:32:44 -070015 : INHERITED(gpu, size, stroke),
cdalton5672da02014-08-04 11:19:11 -070016 fBasePathID(gpu->pathRendering()->genPaths(fSize)),
cdalton61bff702014-08-05 10:58:19 -070017 fGpuMemorySize(0) {
cdaltonb85a0aa2014-07-21 15:32:44 -070018}
19
20GrGLPathRange::~GrGLPathRange() {
21 this->release();
22}
23
24void GrGLPathRange::initAt(size_t index, const SkPath& skPath) {
25 GrGpuGL* gpu = static_cast<GrGpuGL*>(this->getGpu());
26 if (NULL == gpu) {
27 return;
28 }
29
cdaltonb85a0aa2014-07-21 15:32:44 -070030 // Make sure the path at this index hasn't been initted already.
cdalton5672da02014-08-04 11:19:11 -070031 SkASSERT(GR_GL_FALSE == gpu->pathRendering()->isPath(fBasePathID + index));
cdaltonb85a0aa2014-07-21 15:32:44 -070032
cdalton61bff702014-08-05 10:58:19 -070033 fGpuMemorySize += GrGLPath::InitPathObject(gpu, fBasePathID + index, skPath, fStroke);
cdaltonb85a0aa2014-07-21 15:32:44 -070034 this->didChangeGpuMemorySize();
35}
36
37void GrGLPathRange::onRelease() {
38 SkASSERT(NULL != this->getGpu());
39
40 if (0 != fBasePathID && !this->isWrapped()) {
cdalton5672da02014-08-04 11:19:11 -070041 static_cast<GrGpuGL*>(this->getGpu())->pathRendering()->deletePaths(fBasePathID, fSize);
cdaltonb85a0aa2014-07-21 15:32:44 -070042 fBasePathID = 0;
43 }
44
45 INHERITED::onRelease();
46}
47
48void GrGLPathRange::onAbandon() {
49 fBasePathID = 0;
50
51 INHERITED::onAbandon();
52}