cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 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" |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 11 | #include "GrGLPathRendering.h" |
jvanverth | 39edf76 | 2014-12-22 11:44:19 -0800 | [diff] [blame] | 12 | #include "GrGLGpu.h" |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 13 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 14 | GrGLPathRange::GrGLPathRange(GrGLGpu* gpu, PathGenerator* pathGenerator, const SkStrokeRec& stroke) |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 15 | : INHERITED(gpu, pathGenerator, stroke), |
| 16 | fBasePathID(gpu->glPathRendering()->genPaths(this->getNumPaths())), |
| 17 | fGpuMemorySize(0) { |
| 18 | this->registerWithCache(); |
| 19 | } |
| 20 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 21 | GrGLPathRange::GrGLPathRange(GrGLGpu* gpu, |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 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(); |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 30 | } |
| 31 | |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 32 | void GrGLPathRange::onInitPath(int index, const SkPath& skPath) const { |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 33 | GrGLGpu* gpu = static_cast<GrGLGpu*>(this->getGpu()); |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 34 | if (NULL == gpu) { |
| 35 | return; |
| 36 | } |
| 37 | |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 38 | // Make sure the path at this index hasn't been initted already. |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 39 | SkDEBUGCODE( |
| 40 | GrGLboolean isPath; |
| 41 | GR_GL_CALL_RET(gpu->glInterface(), isPath, IsPath(fBasePathID + index))); |
| 42 | SkASSERT(GR_GL_FALSE == isPath); |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 43 | |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 44 | GrGLPath::InitPathObject(gpu, fBasePathID + index, skPath, this->getStroke()); |
| 45 | |
| 46 | // TODO: Use a better approximation for the individual path sizes. |
| 47 | fGpuMemorySize += 100; |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | void GrGLPathRange::onRelease() { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 51 | SkASSERT(this->getGpu()); |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 52 | |
| 53 | if (0 != fBasePathID && !this->isWrapped()) { |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 54 | static_cast<GrGLGpu*>(this->getGpu())->glPathRendering()->deletePaths(fBasePathID, |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 55 | this->getNumPaths()); |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 56 | fBasePathID = 0; |
| 57 | } |
| 58 | |
| 59 | INHERITED::onRelease(); |
| 60 | } |
| 61 | |
| 62 | void GrGLPathRange::onAbandon() { |
| 63 | fBasePathID = 0; |
| 64 | |
| 65 | INHERITED::onAbandon(); |
| 66 | } |