13008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com 23008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com/* 33008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com * Copyright 2011 Google Inc. 43008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com * 53008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com * Use of this source code is governed by a BSD-style license that can be 63008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com * found in the LICENSE file. 73008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com */ 83008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com 93008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com 103008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com#include "GrPathRendererChain.h" 113008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com 123008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com#include "GrContext.h" 133008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com#include "GrDefaultPathRenderer.h" 14c26d94fd7dc0b00cd6d0e42d28285f4a38aff021bsalomon@google.com#include "GrDrawTargetCaps.h" 153008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com#include "GrGpu.h" 163008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com 1745a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.comGrPathRendererChain::GrPathRendererChain(GrContext* context) 183008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com : fInit(false) 1945a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com , fOwner(context) { 203008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com} 21b27a8d5c8a8c4c0ff6892eebe324ca08a3e6dc09bsalomon@google.com 223008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.comGrPathRendererChain::~GrPathRendererChain() { 233008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com for (int i = 0; i < fChain.count(); ++i) { 243008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com fChain[i]->unref(); 253008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com } 263008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com} 273008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com 283008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.comGrPathRenderer* GrPathRendererChain::addPathRenderer(GrPathRenderer* pr) { 293008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com fChain.push_back() = pr; 303008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com pr->ref(); 313008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com return pr; 323008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com} 333008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com 34c2099d2707abcc94e139627399aed4b8894b69bbbsalomon@google.comGrPathRenderer* GrPathRendererChain::getPathRenderer(const SkPath& path, 355f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com const SkStrokeRec& stroke, 36c2099d2707abcc94e139627399aed4b8894b69bbbsalomon@google.com const GrDrawTarget* target, 3745a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com DrawType drawType, 3845a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com StencilSupport* stencilSupport) { 393008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com if (!fInit) { 403008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com this->init(); 413008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com } 4245a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com bool antiAlias = (kColorAntiAlias_DrawType == drawType || 4345a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com kStencilAndColorAntiAlias_DrawType == drawType); 4445a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com 4545a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com GR_STATIC_ASSERT(GrPathRenderer::kNoSupport_StencilSupport < 4645a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com GrPathRenderer::kStencilOnly_StencilSupport); 4745a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com GR_STATIC_ASSERT(GrPathRenderer::kStencilOnly_StencilSupport < 4845a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com GrPathRenderer::kNoRestriction_StencilSupport); 4945a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com GrPathRenderer::StencilSupport minStencilSupport; 5045a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com if (kStencilOnly_DrawType == drawType) { 5145a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport; 5245a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com } else if (kStencilAndColor_DrawType == drawType || 5345a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com kStencilAndColorAntiAlias_DrawType == drawType) { 5445a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport; 5545a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com } else { 5645a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport; 5745a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com } 5845a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com 59e79f320ed6c5ec9f6164ba84be1ff586532e6517robertphillips@google.com 603008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com for (int i = 0; i < fChain.count(); ++i) { 61e79f320ed6c5ec9f6164ba84be1ff586532e6517robertphillips@google.com if (fChain[i]->canDrawPath(path, stroke, target, antiAlias)) { 6245a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) { 63e79f320ed6c5ec9f6164ba84be1ff586532e6517robertphillips@google.com GrPathRenderer::StencilSupport support = fChain[i]->getStencilSupport(path, 64e79f320ed6c5ec9f6164ba84be1ff586532e6517robertphillips@google.com stroke, 6545a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com target); 6645a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com if (support < minStencilSupport) { 6745a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com continue; 6849f085dddff10473b6ebf832a974288300224e60bsalomon } else if (stencilSupport) { 6945a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com *stencilSupport = support; 7045a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com } 7145a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com } 72289533ada623f2238a83771eec977f204f75994fbsalomon@google.com return fChain[i]; 733008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com } 743008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com } 75289533ada623f2238a83771eec977f204f75994fbsalomon@google.com return NULL; 763008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com} 773008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com 783008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.comvoid GrPathRendererChain::init() { 79f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(!fInit); 803008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com GrGpu* gpu = fOwner->getGpu(); 81bcce8926524827775539874346dd424a9510dbc9bsalomon@google.com bool twoSided = gpu->caps()->twoSidedStencilSupport(); 82bcce8926524827775539874346dd424a9510dbc9bsalomon@google.com bool wrapOp = gpu->caps()->stencilWrapOpsSupport(); 8345a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com GrPathRenderer::AddPathRenderers(fOwner, this); 84c377baf406996aed18d82d328029c82dbc3b8ddatomhudson@google.com this->addPathRenderer(SkNEW_ARGS(GrDefaultPathRenderer, 85c377baf406996aed18d82d328029c82dbc3b8ddatomhudson@google.com (twoSided, wrapOp)))->unref(); 863008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com fInit = true; 873008519e9f977cd60194841d558a4f45c28e9833bsalomon@google.com} 88