1 
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"
11 #include "GrGLPathRendering.h"
12 #include "GrGLGpu.h"
13 
GrGLPathRange(GrGLGpu * gpu,PathGenerator * pathGenerator,const SkStrokeRec & stroke)14 GrGLPathRange::GrGLPathRange(GrGLGpu* gpu, PathGenerator* pathGenerator, const SkStrokeRec& stroke)
15     : INHERITED(gpu, pathGenerator, stroke),
16       fBasePathID(gpu->glPathRendering()->genPaths(this->getNumPaths())),
17       fGpuMemorySize(0) {
18     this->registerWithCache();
19 }
20 
GrGLPathRange(GrGLGpu * gpu,GrGLuint basePathID,int numPaths,size_t gpuMemorySize,const SkStrokeRec & stroke)21 GrGLPathRange::GrGLPathRange(GrGLGpu* gpu,
22                              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();
30 }
31 
onInitPath(int index,const SkPath & skPath) const32 void GrGLPathRange::onInitPath(int index, const SkPath& skPath) const {
33     GrGLGpu* gpu = static_cast<GrGLGpu*>(this->getGpu());
34     if (NULL == gpu) {
35         return;
36     }
37 
38     // Make sure the path at this index hasn't been initted already.
39     SkDEBUGCODE(
40         GrGLboolean isPath;
41         GR_GL_CALL_RET(gpu->glInterface(), isPath, IsPath(fBasePathID + index)));
42     SkASSERT(GR_GL_FALSE == isPath);
43 
44     GrGLPath::InitPathObject(gpu, fBasePathID + index, skPath, this->getStroke());
45 
46     // TODO: Use a better approximation for the individual path sizes.
47     fGpuMemorySize += 100;
48 }
49 
onRelease()50 void GrGLPathRange::onRelease() {
51     SkASSERT(this->getGpu());
52 
53     if (0 != fBasePathID && !this->isWrapped()) {
54         static_cast<GrGLGpu*>(this->getGpu())->glPathRendering()->deletePaths(fBasePathID,
55                                                                               this->getNumPaths());
56         fBasePathID = 0;
57     }
58 
59     INHERITED::onRelease();
60 }
61 
onAbandon()62 void GrGLPathRange::onAbandon() {
63     fBasePathID = 0;
64 
65     INHERITED::onAbandon();
66 }
67