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" |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 12 | #include "GrGpuGL.h" |
| 13 | |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 14 | GrGLPathRange::GrGLPathRange(GrGpuGL* gpu, size_t size, const SkStrokeRec& stroke) |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 15 | : INHERITED(gpu, size, stroke), |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 16 | fBasePathID(gpu->glPathRendering()->genPaths(fSize)), |
bungeman | af13c7c | 2014-08-06 11:14:31 -0400 | [diff] [blame] | 17 | fNumDefinedPaths(0) { |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | GrGLPathRange::~GrGLPathRange() { |
| 21 | this->release(); |
| 22 | } |
| 23 | |
| 24 | void GrGLPathRange::initAt(size_t index, const SkPath& skPath) { |
| 25 | GrGpuGL* gpu = static_cast<GrGpuGL*>(this->getGpu()); |
| 26 | if (NULL == gpu) { |
| 27 | return; |
| 28 | } |
| 29 | |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 30 | // Make sure the path at this index hasn't been initted already. |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 31 | SkDEBUGCODE( |
| 32 | GrGLboolean isPath; |
| 33 | GR_GL_CALL_RET(gpu->glInterface(), isPath, IsPath(fBasePathID + index))); |
| 34 | SkASSERT(GR_GL_FALSE == isPath); |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 35 | |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 36 | GrGLPath::InitPathObject(gpu, fBasePathID + index, skPath, fStroke); |
bungeman | af13c7c | 2014-08-06 11:14:31 -0400 | [diff] [blame] | 37 | ++fNumDefinedPaths; |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 38 | this->didChangeGpuMemorySize(); |
| 39 | } |
| 40 | |
| 41 | void GrGLPathRange::onRelease() { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 42 | SkASSERT(this->getGpu()); |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 43 | |
| 44 | if (0 != fBasePathID && !this->isWrapped()) { |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 45 | static_cast<GrGpuGL*>(this->getGpu())->glPathRendering()->deletePaths(fBasePathID, fSize); |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 46 | fBasePathID = 0; |
| 47 | } |
| 48 | |
| 49 | INHERITED::onRelease(); |
| 50 | } |
| 51 | |
| 52 | void GrGLPathRange::onAbandon() { |
| 53 | fBasePathID = 0; |
| 54 | |
| 55 | INHERITED::onAbandon(); |
| 56 | } |