blob: 48a073c096dae2c0904d23dd30bcea9e3c443864 [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"
cdaltonb85a0aa2014-07-21 15:32:44 -070012#include "GrGpuGL.h"
13
cdaltonc7103a12014-08-11 14:05:05 -070014GrGLPathRange::GrGLPathRange(GrGpuGL* gpu, size_t size, const SkStrokeRec& stroke)
cdaltonb85a0aa2014-07-21 15:32:44 -070015 : INHERITED(gpu, size, stroke),
kkinnunenccdaa042014-08-20 01:36:23 -070016 fBasePathID(gpu->glPathRendering()->genPaths(fSize)),
bungemanaf13c7c2014-08-06 11:14:31 -040017 fNumDefinedPaths(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.
kkinnunen5b653572014-08-20 04:13:27 -070031 SkDEBUGCODE(
32 GrGLboolean isPath;
33 GR_GL_CALL_RET(gpu->glInterface(), isPath, IsPath(fBasePathID + index)));
34 SkASSERT(GR_GL_FALSE == isPath);
cdaltonb85a0aa2014-07-21 15:32:44 -070035
cdaltonc7103a12014-08-11 14:05:05 -070036 GrGLPath::InitPathObject(gpu, fBasePathID + index, skPath, fStroke);
bungemanaf13c7c2014-08-06 11:14:31 -040037 ++fNumDefinedPaths;
cdaltonb85a0aa2014-07-21 15:32:44 -070038 this->didChangeGpuMemorySize();
39}
40
41void GrGLPathRange::onRelease() {
bsalomon49f085d2014-09-05 13:34:00 -070042 SkASSERT(this->getGpu());
cdaltonb85a0aa2014-07-21 15:32:44 -070043
44 if (0 != fBasePathID && !this->isWrapped()) {
kkinnunenccdaa042014-08-20 01:36:23 -070045 static_cast<GrGpuGL*>(this->getGpu())->glPathRendering()->deletePaths(fBasePathID, fSize);
cdaltonb85a0aa2014-07-21 15:32:44 -070046 fBasePathID = 0;
47 }
48
49 INHERITED::onRelease();
50}
51
52void GrGLPathRange::onAbandon() {
53 fBasePathID = 0;
54
55 INHERITED::onAbandon();
56}