| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "gl/GrGLPathRendering.h" | 8 #include "gl/GrGLPathRendering.h" |
| 9 #include "gl/GrGLNameAllocator.h" | 9 #include "gl/GrGLNameAllocator.h" |
| 10 #include "gl/GrGLUtil.h" | 10 #include "gl/GrGLUtil.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 return GR_GL_COUNT_UP; | 56 return GR_GL_COUNT_UP; |
| 57 case kInvert_StencilOp: | 57 case kInvert_StencilOp: |
| 58 return GR_GL_INVERT; | 58 return GR_GL_INVERT; |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 | 61 |
| 62 GrGLPathRendering::GrGLPathRendering(GrGLGpu* gpu) | 62 GrGLPathRendering::GrGLPathRendering(GrGLGpu* gpu) |
| 63 : GrPathRendering(gpu) { | 63 : GrPathRendering(gpu) { |
| 64 const GrGLInterface* glInterface = gpu->glInterface(); | 64 const GrGLInterface* glInterface = gpu->glInterface(); |
| 65 fCaps.bindFragmentInputSupport = | 65 fCaps.bindFragmentInputSupport = |
| 66 NULL != glInterface->fFunctions.fBindFragmentInputLocation; | 66 nullptr != glInterface->fFunctions.fBindFragmentInputLocation; |
| 67 } | 67 } |
| 68 | 68 |
| 69 GrGLPathRendering::~GrGLPathRendering() { | 69 GrGLPathRendering::~GrGLPathRendering() { |
| 70 } | 70 } |
| 71 | 71 |
| 72 void GrGLPathRendering::abandonGpuResources() { | 72 void GrGLPathRendering::abandonGpuResources() { |
| 73 fPathNameAllocator.reset(NULL); | 73 fPathNameAllocator.reset(nullptr); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void GrGLPathRendering::resetContext() { | 76 void GrGLPathRendering::resetContext() { |
| 77 fHWProjectionMatrixState.invalidate(); | 77 fHWProjectionMatrixState.invalidate(); |
| 78 // we don't use the model view matrix. | 78 // we don't use the model view matrix. |
| 79 GL_CALL(MatrixLoadIdentity(GR_GL_PATH_MODELVIEW)); | 79 GL_CALL(MatrixLoadIdentity(GR_GL_PATH_MODELVIEW)); |
| 80 | 80 |
| 81 fHWPathStencilSettings.invalidate(); | 81 fHWPathStencilSettings.invalidate(); |
| 82 } | 82 } |
| 83 | 83 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 94 GrGLGpu* gpu = this->gpu(); | 94 GrGLGpu* gpu = this->gpu(); |
| 95 SkASSERT(gpu->caps()->shaderCaps()->pathRenderingSupport()); | 95 SkASSERT(gpu->caps()->shaderCaps()->pathRenderingSupport()); |
| 96 gpu->flushColorWrite(false); | 96 gpu->flushColorWrite(false); |
| 97 gpu->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace); | 97 gpu->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace); |
| 98 | 98 |
| 99 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(args.fRenderTarget); | 99 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(args.fRenderTarget); |
| 100 SkISize size = SkISize::Make(rt->width(), rt->height()); | 100 SkISize size = SkISize::Make(rt->width(), rt->height()); |
| 101 this->setProjectionMatrix(*args.fViewMatrix, size, rt->origin()); | 101 this->setProjectionMatrix(*args.fViewMatrix, size, rt->origin()); |
| 102 gpu->flushScissor(*args.fScissor, rt->getViewport(), rt->origin()); | 102 gpu->flushScissor(*args.fScissor, rt->getViewport(), rt->origin()); |
| 103 gpu->flushHWAAState(rt, args.fUseHWAA); | 103 gpu->flushHWAAState(rt, args.fUseHWAA); |
| 104 gpu->flushRenderTarget(rt, NULL); | 104 gpu->flushRenderTarget(rt, nullptr); |
| 105 | 105 |
| 106 const GrGLPath* glPath = static_cast<const GrGLPath*>(path); | 106 const GrGLPath* glPath = static_cast<const GrGLPath*>(path); |
| 107 | 107 |
| 108 this->flushPathStencilSettings(*args.fStencil); | 108 this->flushPathStencilSettings(*args.fStencil); |
| 109 SkASSERT(!fHWPathStencilSettings.isTwoSided()); | 109 SkASSERT(!fHWPathStencilSettings.isTwoSided()); |
| 110 | 110 |
| 111 GrGLenum fillMode = gr_stencil_op_to_gl_path_rendering_fill_mode( | 111 GrGLenum fillMode = gr_stencil_op_to_gl_path_rendering_fill_mode( |
| 112 fHWPathStencilSettings.passOp(GrStencilSettings::kFront_Face)); | 112 fHWPathStencilSettings.passOp(GrStencilSettings::kFront_Face)); |
| 113 GrGLint writeMask = fHWPathStencilSettings.writeMask(GrStencilSettings::kFro
nt_Face); | 113 GrGLint writeMask = fHWPathStencilSettings.writeMask(GrStencilSettings::kFro
nt_Face); |
| 114 | 114 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 GL_CALL(MatrixLoadf(GR_GL_PATH_PROJECTION, glMatrix)); | 229 GL_CALL(MatrixLoadf(GR_GL_PATH_PROJECTION, glMatrix)); |
| 230 } | 230 } |
| 231 | 231 |
| 232 GrGLuint GrGLPathRendering::genPaths(GrGLsizei range) { | 232 GrGLuint GrGLPathRendering::genPaths(GrGLsizei range) { |
| 233 if (range > 1) { | 233 if (range > 1) { |
| 234 GrGLuint name; | 234 GrGLuint name; |
| 235 GL_CALL_RET(name, GenPaths(range)); | 235 GL_CALL_RET(name, GenPaths(range)); |
| 236 return name; | 236 return name; |
| 237 } | 237 } |
| 238 | 238 |
| 239 if (NULL == fPathNameAllocator.get()) { | 239 if (nullptr == fPathNameAllocator.get()) { |
| 240 static const int range = 65536; | 240 static const int range = 65536; |
| 241 GrGLuint firstName; | 241 GrGLuint firstName; |
| 242 GL_CALL_RET(firstName, GenPaths(range)); | 242 GL_CALL_RET(firstName, GenPaths(range)); |
| 243 fPathNameAllocator.reset(new GrGLNameAllocator(firstName, firstName + ra
nge)); | 243 fPathNameAllocator.reset(new GrGLNameAllocator(firstName, firstName + ra
nge)); |
| 244 } | 244 } |
| 245 | 245 |
| 246 // When allocating names one at a time, pull from a client-side pool of | 246 // When allocating names one at a time, pull from a client-side pool of |
| 247 // available names in order to save a round trip to the GL server. | 247 // available names in order to save a round trip to the GL server. |
| 248 GrGLuint name = fPathNameAllocator->allocateName(); | 248 GrGLuint name = fPathNameAllocator->allocateName(); |
| 249 | 249 |
| 250 if (0 == name) { | 250 if (0 == name) { |
| 251 // Our reserved path names are all in use. Fall back on GenPaths. | 251 // Our reserved path names are all in use. Fall back on GenPaths. |
| 252 GL_CALL_RET(name, GenPaths(1)); | 252 GL_CALL_RET(name, GenPaths(1)); |
| 253 } | 253 } |
| 254 | 254 |
| 255 return name; | 255 return name; |
| 256 } | 256 } |
| 257 | 257 |
| 258 void GrGLPathRendering::deletePaths(GrGLuint path, GrGLsizei range) { | 258 void GrGLPathRendering::deletePaths(GrGLuint path, GrGLsizei range) { |
| 259 if (range > 1) { | 259 if (range > 1) { |
| 260 // It is not supported to delete names in ranges that were allocated | 260 // It is not supported to delete names in ranges that were allocated |
| 261 // individually using GrGLPathNameAllocator. | 261 // individually using GrGLPathNameAllocator. |
| 262 SkASSERT(NULL == fPathNameAllocator.get() || | 262 SkASSERT(nullptr == fPathNameAllocator.get() || |
| 263 path + range <= fPathNameAllocator->firstName() || | 263 path + range <= fPathNameAllocator->firstName() || |
| 264 path >= fPathNameAllocator->endName()); | 264 path >= fPathNameAllocator->endName()); |
| 265 GL_CALL(DeletePaths(path, range)); | 265 GL_CALL(DeletePaths(path, range)); |
| 266 return; | 266 return; |
| 267 } | 267 } |
| 268 | 268 |
| 269 if (NULL == fPathNameAllocator.get() || | 269 if (nullptr == fPathNameAllocator.get() || |
| 270 path < fPathNameAllocator->firstName() || | 270 path < fPathNameAllocator->firstName() || |
| 271 path >= fPathNameAllocator->endName()) { | 271 path >= fPathNameAllocator->endName()) { |
| 272 // If we aren't inside fPathNameAllocator's range then this name was | 272 // If we aren't inside fPathNameAllocator's range then this name was |
| 273 // generated by the GenPaths fallback (or else was never allocated). | 273 // generated by the GenPaths fallback (or else was never allocated). |
| 274 GL_CALL(DeletePaths(path, 1)); | 274 GL_CALL(DeletePaths(path, 1)); |
| 275 return; | 275 return; |
| 276 } | 276 } |
| 277 | 277 |
| 278 // Make the path empty to save memory, but don't free the name in the driver
. | 278 // Make the path empty to save memory, but don't free the name in the driver
. |
| 279 GL_CALL(PathCommands(path, 0, NULL, 0, GR_GL_FLOAT, NULL)); | 279 GL_CALL(PathCommands(path, 0, nullptr, 0, GR_GL_FLOAT, nullptr)); |
| 280 fPathNameAllocator->free(path); | 280 fPathNameAllocator->free(path); |
| 281 } | 281 } |
| 282 | 282 |
| 283 void GrGLPathRendering::flushPathStencilSettings(const GrStencilSettings& stenci
lSettings) { | 283 void GrGLPathRendering::flushPathStencilSettings(const GrStencilSettings& stenci
lSettings) { |
| 284 if (fHWPathStencilSettings != stencilSettings) { | 284 if (fHWPathStencilSettings != stencilSettings) { |
| 285 // Just the func, ref, and mask is set here. The op and write mask are p
arams to the call | 285 // Just the func, ref, and mask is set here. The op and write mask are p
arams to the call |
| 286 // that draws the path to the SB (glStencilFillPath) | 286 // that draws the path to the SB (glStencilFillPath) |
| 287 GrGLenum func = | 287 GrGLenum func = |
| 288 GrToGLStencilFunc(stencilSettings.func(GrStencilSettings::kFront_Fac
e)); | 288 GrToGLStencilFunc(stencilSettings.func(GrStencilSettings::kFront_Fac
e)); |
| 289 GL_CALL(PathStencilFunc(func, stencilSettings.funcRef(GrStencilSettings:
:kFront_Face), | 289 GL_CALL(PathStencilFunc(func, stencilSettings.funcRef(GrStencilSettings:
:kFront_Face), |
| 290 stencilSettings.funcMask(GrStencilSettings::kFro
nt_Face))); | 290 stencilSettings.funcMask(GrStencilSettings::kFro
nt_Face))); |
| 291 | 291 |
| 292 fHWPathStencilSettings = stencilSettings; | 292 fHWPathStencilSettings = stencilSettings; |
| 293 } | 293 } |
| 294 } | 294 } |
| 295 | 295 |
| 296 inline GrGLGpu* GrGLPathRendering::gpu() { | 296 inline GrGLGpu* GrGLPathRendering::gpu() { |
| 297 return static_cast<GrGLGpu*>(fGpu); | 297 return static_cast<GrGLGpu*>(fGpu); |
| 298 } | 298 } |
| OLD | NEW |