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 "GrGpuGL.h" 13 14GrGLPathRange::GrGLPathRange(GrGpuGL* 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 21GrGLPathRange::GrGLPathRange(GrGpuGL* 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 32GrGLPathRange::~GrGLPathRange() { 33 this->release(); 34} 35 36void GrGLPathRange::onInitPath(int index, const SkPath& skPath) const { 37 GrGpuGL* gpu = static_cast<GrGpuGL*>(this->getGpu()); 38 if (NULL == gpu) { 39 return; 40 } 41 42 // Make sure the path at this index hasn't been initted already. 43 SkDEBUGCODE( 44 GrGLboolean isPath; 45 GR_GL_CALL_RET(gpu->glInterface(), isPath, IsPath(fBasePathID + index))); 46 SkASSERT(GR_GL_FALSE == isPath); 47 48 GrGLPath::InitPathObject(gpu, fBasePathID + index, skPath, this->getStroke()); 49 50 // TODO: Use a better approximation for the individual path sizes. 51 fGpuMemorySize += 100; 52} 53 54void GrGLPathRange::onRelease() { 55 SkASSERT(this->getGpu()); 56 57 if (0 != fBasePathID && !this->isWrapped()) { 58 static_cast<GrGpuGL*>(this->getGpu())->glPathRendering()->deletePaths(fBasePathID, 59 this->getNumPaths()); 60 fBasePathID = 0; 61 } 62 63 INHERITED::onRelease(); 64} 65 66void GrGLPathRange::onAbandon() { 67 fBasePathID = 0; 68 69 INHERITED::onAbandon(); 70} 71