145a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com/*
245a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com * Copyright 2011 Google Inc.
345a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com *
445a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com * Use of this source code is governed by a BSD-style license that can be
545a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com * found in the LICENSE file.
645a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com */
745a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com
845a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com#ifndef GrPathRendererChain_DEFINED
945a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com#define GrPathRendererChain_DEFINED
1045a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com
11a4de8c257ea0be8ff7081f645249b6afe5c48e7ecommit-bot@chromium.org#include "SkRefCnt.h"
1245a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com#include "SkTArray.h"
1345a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com
1445a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.comclass GrContext;
1545a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.comclass GrDrawTarget;
1645a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.comclass GrPathRenderer;
1745a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.comclass SkPath;
185f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.comclass SkStrokeRec;
1945a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com
2045a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com/**
2145a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com * Keeps track of an ordered list of path renderers. When a path needs to be
2245a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com * drawn this list is scanned to find the most preferred renderer. To add your
2345a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com * path renderer to the list implement the GrPathRenderer::AddPathRenderers
2445a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com * function.
2545a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com */
2645a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.comclass GrPathRendererChain : public SkRefCnt {
2745a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.compublic:
2845a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com    // See comments in GrPathRenderer.h
2945a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com    enum StencilSupport {
3045a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com        kNoSupport_StencilSupport,
3145a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com        kStencilOnly_StencilSupport,
3245a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com        kNoRestriction_StencilSupport,
3345a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com    };
3445a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com
3545a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com    SK_DECLARE_INST_COUNT(GrPathRendererChain)
3645a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com
3745a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com    GrPathRendererChain(GrContext* context);
3845a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com
3945a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com    ~GrPathRendererChain();
4045a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com
4145a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com    // takes a ref and unrefs in destructor
4245a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com    GrPathRenderer* addPathRenderer(GrPathRenderer* pr);
4345a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com
4445a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com    /** Documents how the caller plans to use a GrPathRenderer to draw a path. It affects the PR
4545a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com        returned by getPathRenderer */
4645a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com    enum DrawType {
4745a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com        kColor_DrawType,                    // draw to the color buffer, no AA
4845a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com        kColorAntiAlias_DrawType,           // draw to color buffer, with partial coverage AA
4945a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com        kStencilOnly_DrawType,              // draw just to the stencil buffer
5045a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com        kStencilAndColor_DrawType,          // draw the stencil and color buffer, no AA
5145a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com        kStencilAndColorAntiAlias_DrawType  // draw the stencil and color buffer, with partial
5245a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com                                            // coverage AA.
5345a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com    };
5445a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com    /** Returns a GrPathRenderer compatible with the request if one is available. If the caller
5545a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com        is drawing the path to the stencil buffer then stencilSupport can be used to determine
5645a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com        whether the path can be rendered with arbitrary stencil rules or not. See comments on
57c7b4be7f110bc7b487c3c3f28d82877584e74c2fskia.committer@gmail.com        StencilSupport in GrPathRenderer.h. */
5845a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com    GrPathRenderer* getPathRenderer(const SkPath& path,
595f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com                                    const SkStrokeRec& rec,
6045a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com                                    const GrDrawTarget* target,
6145a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com                                    DrawType drawType,
6245a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com                                    StencilSupport* stencilSupport);
6345a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com
6445a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.comprivate:
6545a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com    GrPathRendererChain();
6645a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com
6745a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com    void init();
6845a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com
6945a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com    enum {
7045a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com        kPreAllocCount = 8,
7145a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com    };
7245a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com    bool fInit;
7345a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com    GrContext*                                          fOwner;
7445a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com    SkSTArray<kPreAllocCount, GrPathRenderer*, true>    fChain;
7545a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com
7645a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com    typedef SkRefCnt INHERITED;
7745a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com};
7845a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com
7945a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com#endif
80