1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/*
2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2010 Google Inc.
3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com *
4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be
5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file.
6ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */
7ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
8ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#ifndef GrDrawTarget_DEFINED
9ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#define GrDrawTarget_DEFINED
10ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
1144701df5ce572ac3cccec785cf52103d3d5d14a5joshualitt#include "GrClip.h"
126db519c42471aaaa8a8e1a3ece314014481ab832joshualitt#include "GrClipMaskManager.h"
132a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org#include "GrContext.h"
148072caa80384292858d31ae34b7e19768875866bjoshualitt#include "GrPathProcessor.h"
158072caa80384292858d31ae34b7e19768875866bjoshualitt#include "GrPrimitiveProcessor.h"
16934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com#include "GrIndexBuffer.h"
17ccdaa0422501e5cbcba53d6bd19f2736f1beaef3kkinnunen#include "GrPathRendering.h"
188dd688b7569df569a672a8a67b2db86a9d376cfcegdaniel#include "GrPipelineBuilder.h"
192a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org#include "GrTraceMarker.h"
207eb8c7b00a5d776bebaf33a8687357df95c1aa43joshualitt#include "GrVertexBuffer.h"
21ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
228d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com#include "SkClipStack.h"
23a4de8c257ea0be8ff7081f645249b6afe5c48e7ecommit-bot@chromium.org#include "SkMatrix.h"
2412b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com#include "SkPath.h"
259b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org#include "SkStrokeRec.h"
26a2d71482db8b6d752a51c96da74768d7dfc27932robertphillips@google.com#include "SkTArray.h"
27a4de8c257ea0be8ff7081f645249b6afe5c48e7ecommit-bot@chromium.org#include "SkTLazy.h"
28a0b40280a49a8a43af7929ead3b3489951c58501commit-bot@chromium.org#include "SkTypes.h"
298d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com#include "SkXfermode.h"
3097c88c255cff3dbb8343c5d090526fdbedad6dd6Scroggo
3144701df5ce572ac3cccec785cf52103d3d5d14a5joshualittclass GrClip;
32c26d94fd7dc0b00cd6d0e42d28285f4a38aff021bsalomon@google.comclass GrDrawTargetCaps;
3364aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.comclass GrPath;
34b85a0aab6905af8b329539b7573a7555b727d5e5cdaltonclass GrPathRange;
35e36914cb205699526988127a827d1a76c9a98d39egdanielclass GrPipeline;
3612b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com
37a4de8c257ea0be8ff7081f645249b6afe5c48e7ecommit-bot@chromium.orgclass GrDrawTarget : public SkRefCnt {
38bcce8926524827775539874346dd424a9510dbc9bsalomon@google.compublic:
39bcce8926524827775539874346dd424a9510dbc9bsalomon@google.com    SK_DECLARE_INST_COUNT(GrDrawTarget)
40bcce8926524827775539874346dd424a9510dbc9bsalomon@google.com
4155b24afc178e641e17a5664beba7ab2b4982c91acdalton    typedef GrPathRange::PathIndexType PathIndexType;
4255b24afc178e641e17a5664beba7ab2b4982c91acdalton    typedef GrPathRendering::PathTransformType PathTransformType;
43ccdaa0422501e5cbcba53d6bd19f2736f1beaef3kkinnunen
44ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    ///////////////////////////////////////////////////////////////////////////
45ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
466e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com    // The context may not be fully constructed and should not be used during GrDrawTarget
476e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com    // construction.
48e40d39725908d99d255496025411e5c9ca32663erobertphillips    GrDrawTarget(GrContext* context);
49a73239a0096370221d3dfababf339dd6d3fed84fbsalomon
5072e3ae486c66871c2043eac4f08d85d419fbca2absalomon    virtual ~GrDrawTarget() {}
51ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
52ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
53a73239a0096370221d3dfababf339dd6d3fed84fbsalomon     * Empties the draw buffer of any queued up draws.
54a73239a0096370221d3dfababf339dd6d3fed84fbsalomon     */
55e40d39725908d99d255496025411e5c9ca32663erobertphillips    void reset() { this->onReset(); }
56a73239a0096370221d3dfababf339dd6d3fed84fbsalomon
57a73239a0096370221d3dfababf339dd6d3fed84fbsalomon    /**
58a73239a0096370221d3dfababf339dd6d3fed84fbsalomon     * This plays any queued up draws to its GrGpu target. It also resets this object (i.e. flushing
59a73239a0096370221d3dfababf339dd6d3fed84fbsalomon     * is destructive).
60a73239a0096370221d3dfababf339dd6d3fed84fbsalomon     */
61a73239a0096370221d3dfababf339dd6d3fed84fbsalomon    void flush();
62a73239a0096370221d3dfababf339dd6d3fed84fbsalomon
63a73239a0096370221d3dfababf339dd6d3fed84fbsalomon    /**
6418c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com     * Gets the capabilities of the draw target.
6518c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com     */
66c26d94fd7dc0b00cd6d0e42d28285f4a38aff021bsalomon@google.com    const GrDrawTargetCaps* caps() const { return fCaps.get(); }
6718c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com
6899c7c07e0f1f7b78980eb21d84bebda8b45a7178joshualitt    void drawBatch(GrPipelineBuilder*, GrBatch*);
694d8da81562852e0ff7e18b66ee1cebd50ad81ee8joshualitt
7086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com    /**
7164aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com     * Draws path into the stencil buffer. The fill must be either even/odd or
7264aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com     * winding (not inverse or hairline). It will respect the HW antialias flag
738dd688b7569df569a672a8a67b2db86a9d376cfcegdaniel     * on the GrPipelineBuilder (if possible in the 3D API).  Note, we will never have an inverse
748dd688b7569df569a672a8a67b2db86a9d376cfcegdaniel     * fill with stencil path
7564aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com     */
768dd688b7569df569a672a8a67b2db86a9d376cfcegdaniel    void stencilPath(GrPipelineBuilder*, const GrPathProcessor*, const GrPath*,
778dd688b7569df569a672a8a67b2db86a9d376cfcegdaniel                     GrPathRendering::FillType);
7864aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com
7964aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com    /**
8032184d81629e39809bb9e915286d8fe971a8ed68commit-bot@chromium.org     * Draws a path. Fill must not be a hairline. It will respect the HW
818dd688b7569df569a672a8a67b2db86a9d376cfcegdaniel     * antialias flag on the GrPipelineBuilder (if possible in the 3D API).
82c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org     */
838dd688b7569df569a672a8a67b2db86a9d376cfcegdaniel    void drawPath(GrPipelineBuilder*, const GrPathProcessor*, const GrPath*,
848dd688b7569df569a672a8a67b2db86a9d376cfcegdaniel                  GrPathRendering::FillType);
85c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org
86c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org    /**
8755b24afc178e641e17a5664beba7ab2b4982c91acdalton     * Draws the aggregate path from combining multiple. Note that this will not
8855b24afc178e641e17a5664beba7ab2b4982c91acdalton     * always be equivalent to back-to-back calls to drawPath(). It will respect
898dd688b7569df569a672a8a67b2db86a9d376cfcegdaniel     * the HW antialias flag on the GrPipelineBuilder (if possible in the 3D API).
909b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org     *
9155b24afc178e641e17a5664beba7ab2b4982c91acdalton     * @param pathRange       Source paths to draw from
9255b24afc178e641e17a5664beba7ab2b4982c91acdalton     * @param indices         Array of path indices to draw
9355b24afc178e641e17a5664beba7ab2b4982c91acdalton     * @param indexType       Data type of the array elements in indexBuffer
9455b24afc178e641e17a5664beba7ab2b4982c91acdalton     * @param transformValues Array of transforms for the individual paths
9555b24afc178e641e17a5664beba7ab2b4982c91acdalton     * @param transformType   Type of transforms in transformBuffer
9655b24afc178e641e17a5664beba7ab2b4982c91acdalton     * @param count           Number of paths to draw
97b85a0aab6905af8b329539b7573a7555b727d5e5cdalton     * @param fill            Fill type for drawing all the paths
98b85a0aab6905af8b329539b7573a7555b727d5e5cdalton     */
998dd688b7569df569a672a8a67b2db86a9d376cfcegdaniel    void drawPaths(GrPipelineBuilder*,
10056995b5cc00c9c83bd5fcf86bca9a67e939a96cbjoshualitt                   const GrPathProcessor*,
1012e3b3e369d79e78f7635d4c20e83a47ab571bdf2joshualitt                   const GrPathRange* pathRange,
10255b24afc178e641e17a5664beba7ab2b4982c91acdalton                   const void* indices,
10355b24afc178e641e17a5664beba7ab2b4982c91acdalton                   PathIndexType indexType,
10455b24afc178e641e17a5664beba7ab2b4982c91acdalton                   const float transformValues[],
10555b24afc178e641e17a5664beba7ab2b4982c91acdalton                   PathTransformType transformType,
1069853ccef19c200be93a6211f32589fa82a53067cjoshualitt                   int count,
10792e496f96abbd664888f0c8a7d546ab02e703bf7joshualitt                   GrPathRendering::FillType fill);
108b85a0aab6905af8b329539b7573a7555b727d5e5cdalton
1099b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org    /**
11072e3ae486c66871c2043eac4f08d85d419fbca2absalomon     * Helper function for drawing rects.
111044679ef8c08e1f01afadf5bc08251fe8597df81skia.committer@gmail.com     *
112c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com     * @param rect        the rect to draw
113c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com     * @param localRect   optional rect that specifies local coords to map onto
114c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com     *                    rect. If NULL then rect serves as the local coords.
1158fc6c2d82c1f30ff82274334c01f0799def6a609joshualitt     * @param localMatrix Optional local matrix. The local coordinates are specified by localRect,
1168fc6c2d82c1f30ff82274334c01f0799def6a609joshualitt     *                    or if it is NULL by rect. This matrix applies to the coordinate implied by
1178fc6c2d82c1f30ff82274334c01f0799def6a609joshualitt     *                    that rectangle before it is input to GrCoordTransforms that read local
1188fc6c2d82c1f30ff82274334c01f0799def6a609joshualitt     *                    coordinates
11986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     */
1204d8da81562852e0ff7e18b66ee1cebd50ad81ee8joshualitt    void drawRect(GrPipelineBuilder* pipelineBuilder,
1212e3b3e369d79e78f7635d4c20e83a47ab571bdf2joshualitt                  GrColor color,
1228059eb9f6e24ed609393fbda4ad71edea03ac258joshualitt                  const SkMatrix& viewMatrix,
1239853ccef19c200be93a6211f32589fa82a53067cjoshualitt                  const SkRect& rect,
124fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org                  const SkRect* localRect,
125ad17cfc8c72515176a1b191767caac48e316b43ajoshualitt                  const SkMatrix* localMatrix);
1263976825a21532e254311b90b4a9046e25717e335jvanverth@google.com
127cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com    /**
128c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com     * Helper for drawRect when the caller doesn't need separate local rects or matrices.
129cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com     */
1308dd688b7569df569a672a8a67b2db86a9d376cfcegdaniel    void drawSimpleRect(GrPipelineBuilder* ds, GrColor color, const SkMatrix& viewM,
1318dd688b7569df569a672a8a67b2db86a9d376cfcegdaniel                        const SkRect& rect) {
1328059eb9f6e24ed609393fbda4ad71edea03ac258joshualitt        this->drawRect(ds, color, viewM, rect, NULL, NULL);
133cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com    }
1348dd688b7569df569a672a8a67b2db86a9d376cfcegdaniel    void drawSimpleRect(GrPipelineBuilder* ds, GrColor color, const SkMatrix& viewM,
1358059eb9f6e24ed609393fbda4ad71edea03ac258joshualitt                        const SkIRect& irect) {
1364469938e92d779dff05e745559e67907bbf21e78reed@google.com        SkRect rect = SkRect::Make(irect);
1378059eb9f6e24ed609393fbda4ad71edea03ac258joshualitt        this->drawRect(ds, color, viewM, rect, NULL, NULL);
138cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com    }
13986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com
140934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com
141934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com    /**
1428dd688b7569df569a672a8a67b2db86a9d376cfcegdaniel     * Clear the passed in render target. Ignores the GrPipelineBuilder and clip. Clears the whole
1438dd688b7569df569a672a8a67b2db86a9d376cfcegdaniel     * thing if rect is NULL, otherwise just the rect. If canIgnoreRect is set then the entire
1448dd688b7569df569a672a8a67b2db86a9d376cfcegdaniel     * render target can be optionally cleared.
1450b335c1ac100aeacf79a4c98a052286fd46661e7bsalomon@google.com     */
1469853ccef19c200be93a6211f32589fa82a53067cjoshualitt    void clear(const SkIRect* rect,
1479853ccef19c200be93a6211f32589fa82a53067cjoshualitt               GrColor color,
1489853ccef19c200be93a6211f32589fa82a53067cjoshualitt               bool canIgnoreRect,
14963b21962867af0f98e12a3ccbe5eef76b7ecc3aabsalomon               GrRenderTarget* renderTarget);
150a9493a3c78f6eb82635ece960b4f16918b885428skia.committer@gmail.com
151e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com    /**
15289c62980c1eb50b2090f33312086c7e8c66739b4bsalomon     * Discards the contents render target.
15328361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     **/
15489c62980c1eb50b2090f33312086c7e8c66739b4bsalomon    virtual void discard(GrRenderTarget*) = 0;
15528361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org
15628361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org    /**
1572a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org     * Called at start and end of gpu trace marking
1582a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org     * GR_CREATE_GPU_TRACE_MARKER(marker_str, target) will automatically call these at the start
1592a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org     * and end of a code block respectively
160a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.org     */
1613eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel    void addGpuTraceMarker(const GrGpuTraceMarker* marker);
1623eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel    void removeGpuTraceMarker(const GrGpuTraceMarker* marker);
1633eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel
1643eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel    /**
1653eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel     * Takes the current active set of markers and stores them for later use. Any current marker
1663eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel     * in the active set is removed from the active set and the targets remove function is called.
1673eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel     * These functions do not work as a stack so you cannot call save a second time before calling
1683eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel     * restore. Also, it is assumed that when restore is called the current active set of markers
1693eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel     * is empty. When the stored markers are added back into the active set, the targets add marker
1703eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel     * is called.
1713eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel     */
1723eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel    void saveActiveTraceMarkers();
1733eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel    void restoreActiveTraceMarkers();
174a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.org
175a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.org    /**
176e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com     * Copies a pixel rectangle from one surface to another. This call may finalize
177e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com     * reserved vertex/index data (as though a draw call was made). The src pixels
178e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com     * copied are specified by srcRect. They are copied to a rect of the same
179e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com     * size in dst with top left at dstPoint. If the src rect is clipped by the
180e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com     * src bounds then  pixel values in the dst rect corresponding to area clipped
181e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com     * by the src rect are not overwritten. This method can fail and return false
182e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com     * depending on the type of surface, configs, etc, and the backend-specific
183e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com     * limitations. If rect is clipped out entirely by the src or dst bounds then
184e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com     * true is returned since there is no actual copy necessary to succeed.
185e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com     */
186f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon    bool copySurface(GrSurface* dst,
187f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon                     GrSurface* src,
188f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon                     const SkIRect& srcRect,
189f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon                     const SkIPoint& dstPoint);
190116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com    /**
191f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon     * Function that determines whether a copySurface call would succeed without actually
192116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com     * performing the copy.
193116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com     */
194f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon    bool canCopySurface(const GrSurface* dst,
195f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon                        const GrSurface* src,
196f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon                        const SkIRect& srcRect,
197f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon                        const SkIPoint& dstPoint);
198eb85117c05471e1a55ce387cbc38279f857a4584bsalomon@google.com
199eb85117c05471e1a55ce387cbc38279f857a4584bsalomon@google.com    /**
200ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com     * Release any resources that are cached but not currently in use. This
201ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com     * is intended to give an application some recourse when resources are low.
202ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com     */
203ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com    virtual void purgeResources() {};
204ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com
205a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org    ///////////////////////////////////////////////////////////////////////////
206a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org    // Draw execution tracking (for font atlases and other resources)
207a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org    class DrawToken {
208a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org    public:
209a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org        DrawToken(GrDrawTarget* drawTarget, uint32_t drawID) :
210a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org                  fDrawTarget(drawTarget), fDrawID(drawID) {}
2117475811143e190e172bf83d13c4bdba85704b604skia.committer@gmail.com
21249f085dddff10473b6ebf832a974288300224e60bsalomon        bool isIssued() { return fDrawTarget && fDrawTarget->isIssued(fDrawID); }
2137475811143e190e172bf83d13c4bdba85704b604skia.committer@gmail.com
214a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org    private:
215a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org        GrDrawTarget*  fDrawTarget;
216a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org        uint32_t       fDrawID;   // this may wrap, but we're doing direct comparison
217a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org                                  // so that should be okay
218a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org    };
2197475811143e190e172bf83d13c4bdba85704b604skia.committer@gmail.com
220a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org    virtual DrawToken getCurrentDrawToken() { return DrawToken(this, 0); }
2217475811143e190e172bf83d13c4bdba85704b604skia.committer@gmail.com
2222c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt    bool programUnitTest(int maxStages);
2232c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt
224ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comprotected:
225e46760e8b2b2fc4a11a43a3b7cc9da7166c83c46joshualitt    friend class GrCommandBuilder; // for PipelineInfo
226af242958a5daced0956d7bb3277716b8f0aeaf4bjoshualitt    friend class GrInOrderCommandBuilder; // for PipelineInfo
2273b58d75170508567436cce259384d336949407d4joshualitt    friend class GrReorderCommandBuilder; // for PipelineInfo
228dad7794dcbf205a6d0f3c5c44e251897f5256f09robertphillips    friend class GrTargetCommands; // for PipelineInfo
229dad7794dcbf205a6d0f3c5c44e251897f5256f09robertphillips
2306e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com    GrContext* getContext() { return fContext; }
2316e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com    const GrContext* getContext() const { return fContext; }
2326e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com
233a73239a0096370221d3dfababf339dd6d3fed84fbsalomon    GrGpu* getGpu() {
234a73239a0096370221d3dfababf339dd6d3fed84fbsalomon        SkASSERT(fContext && fContext->getGpu());
235a73239a0096370221d3dfababf339dd6d3fed84fbsalomon        return fContext->getGpu();
236a73239a0096370221d3dfababf339dd6d3fed84fbsalomon    }
237a73239a0096370221d3dfababf339dd6d3fed84fbsalomon    const GrGpu* getGpu() const {
238a73239a0096370221d3dfababf339dd6d3fed84fbsalomon        SkASSERT(fContext && fContext->getGpu());
239a73239a0096370221d3dfababf339dd6d3fed84fbsalomon        return fContext->getGpu();
240a73239a0096370221d3dfababf339dd6d3fed84fbsalomon    }
241a73239a0096370221d3dfababf339dd6d3fed84fbsalomon
2422a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org    const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers; }
2432a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org
244651713408c5a5d9565665967ad09981250c7a8c9joshualitt    // Makes a copy of the dst if it is necessary for the draw. Returns false if a copy is required
245651713408c5a5d9565665967ad09981250c7a8c9joshualitt    // but couldn't be made. Otherwise, returns true.  This method needs to be protected because it
246651713408c5a5d9565665967ad09981250c7a8c9joshualitt    // needs to be accessed by GLPrograms to setup a correct drawstate
24750785a3d10b53bea5beb6e18431a2449860be237bsalomon    bool setupDstReadIfNecessary(const GrPipelineBuilder&,
248e36914cb205699526988127a827d1a76c9a98d39egdaniel                                 const GrProcOptInfo& colorPOI,
249e36914cb205699526988127a827d1a76c9a98d39egdaniel                                 const GrProcOptInfo& coveragePOI,
2509853ccef19c200be93a6211f32589fa82a53067cjoshualitt                                 GrDeviceCoordTexture* dstCopy,
2519853ccef19c200be93a6211f32589fa82a53067cjoshualitt                                 const SkRect* drawBounds);
252651713408c5a5d9565665967ad09981250c7a8c9joshualitt
253e36914cb205699526988127a827d1a76c9a98d39egdaniel    struct PipelineInfo {
254e36914cb205699526988127a827d1a76c9a98d39egdaniel        PipelineInfo(GrPipelineBuilder* pipelineBuilder, GrScissorState* scissor,
25544701df5ce572ac3cccec785cf52103d3d5d14a5joshualitt                     const GrPrimitiveProcessor* primProc,
25644701df5ce572ac3cccec785cf52103d3d5d14a5joshualitt                     const SkRect* devBounds, GrDrawTarget* target);
257e36914cb205699526988127a827d1a76c9a98d39egdaniel
258e36914cb205699526988127a827d1a76c9a98d39egdaniel        PipelineInfo(GrPipelineBuilder* pipelineBuilder, GrScissorState* scissor,
25944701df5ce572ac3cccec785cf52103d3d5d14a5joshualitt                     const GrBatch* batch, const SkRect* devBounds,
26044701df5ce572ac3cccec785cf52103d3d5d14a5joshualitt                     GrDrawTarget* target);
261e36914cb205699526988127a827d1a76c9a98d39egdaniel
262e36914cb205699526988127a827d1a76c9a98d39egdaniel        bool willBlendWithDst(const GrPrimitiveProcessor* primProc) const {
263e36914cb205699526988127a827d1a76c9a98d39egdaniel            return fPipelineBuilder->willBlendWithDst(primProc);
264e36914cb205699526988127a827d1a76c9a98d39egdaniel        }
265e36914cb205699526988127a827d1a76c9a98d39egdaniel    private:
266e36914cb205699526988127a827d1a76c9a98d39egdaniel        friend class GrDrawTarget;
267e36914cb205699526988127a827d1a76c9a98d39egdaniel
268e36914cb205699526988127a827d1a76c9a98d39egdaniel        bool mustSkipDraw() const { return (NULL == fPipelineBuilder); }
269e36914cb205699526988127a827d1a76c9a98d39egdaniel
270e36914cb205699526988127a827d1a76c9a98d39egdaniel        GrPipelineBuilder*      fPipelineBuilder;
271e36914cb205699526988127a827d1a76c9a98d39egdaniel        GrScissorState*         fScissor;
272e36914cb205699526988127a827d1a76c9a98d39egdaniel        GrProcOptInfo           fColorPOI;
273e36914cb205699526988127a827d1a76c9a98d39egdaniel        GrProcOptInfo           fCoveragePOI;
274e36914cb205699526988127a827d1a76c9a98d39egdaniel        GrDeviceCoordTexture    fDstCopy;
275e36914cb205699526988127a827d1a76c9a98d39egdaniel    };
276e36914cb205699526988127a827d1a76c9a98d39egdaniel
277e36914cb205699526988127a827d1a76c9a98d39egdaniel    void setupPipeline(const PipelineInfo& pipelineInfo, GrPipeline* pipeline);
278e36914cb205699526988127a827d1a76c9a98d39egdaniel
27902ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.comprivate:
280a73239a0096370221d3dfababf339dd6d3fed84fbsalomon    virtual void onReset() = 0;
281f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon
282a73239a0096370221d3dfababf339dd6d3fed84fbsalomon    virtual void onFlush() = 0;
283f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon
284e36914cb205699526988127a827d1a76c9a98d39egdaniel    virtual void onDrawBatch(GrBatch*, const PipelineInfo&) = 0;
2858dd688b7569df569a672a8a67b2db86a9d376cfcegdaniel    virtual void onStencilPath(const GrPipelineBuilder&,
28656995b5cc00c9c83bd5fcf86bca9a67e939a96cbjoshualitt                               const GrPathProcessor*,
2879853ccef19c200be93a6211f32589fa82a53067cjoshualitt                               const GrPath*,
2883e79124a69d4806f0a1a776090bff718e1b90970bsalomon                               const GrScissorState&,
2892c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt                               const GrStencilSettings&) = 0;
290e36914cb205699526988127a827d1a76c9a98d39egdaniel    virtual void onDrawPath(const GrPathProcessor*,
2919853ccef19c200be93a6211f32589fa82a53067cjoshualitt                            const GrPath*,
2922c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt                            const GrStencilSettings&,
293e36914cb205699526988127a827d1a76c9a98d39egdaniel                            const PipelineInfo&) = 0;
294e36914cb205699526988127a827d1a76c9a98d39egdaniel    virtual void onDrawPaths(const GrPathProcessor*,
2959853ccef19c200be93a6211f32589fa82a53067cjoshualitt                             const GrPathRange*,
29655b24afc178e641e17a5664beba7ab2b4982c91acdalton                             const void* indices,
29755b24afc178e641e17a5664beba7ab2b4982c91acdalton                             PathIndexType,
29855b24afc178e641e17a5664beba7ab2b4982c91acdalton                             const float transformValues[],
2992c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt                             PathTransformType,
30055b24afc178e641e17a5664beba7ab2b4982c91acdalton                             int count,
3012c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt                             const GrStencilSettings&,
302e36914cb205699526988127a827d1a76c9a98d39egdaniel                             const PipelineInfo&) = 0;
30364aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com
30463b21962867af0f98e12a3ccbe5eef76b7ecc3aabsalomon    virtual void onClear(const SkIRect* rect, GrColor color, bool canIgnoreRect,
30563b21962867af0f98e12a3ccbe5eef76b7ecc3aabsalomon                         GrRenderTarget* renderTarget) = 0;
30663b21962867af0f98e12a3ccbe5eef76b7ecc3aabsalomon
307a73239a0096370221d3dfababf339dd6d3fed84fbsalomon    /** The subclass's copy surface implementation. It should assume that any clipping has already
308a73239a0096370221d3dfababf339dd6d3fed84fbsalomon        been performed on the rect and point and that the GrGpu supports the copy. */
309a73239a0096370221d3dfababf339dd6d3fed84fbsalomon    virtual void onCopySurface(GrSurface* dst,
310f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon                               GrSurface* src,
311f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon                               const SkIRect& srcRect,
312f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon                               const SkIPoint& dstPoint) = 0;
313f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon
314a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org    // Check to see if this set of draw commands has been sent out
315a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org    virtual bool       isIssued(uint32_t drawID) { return true; }
3169853ccef19c200be93a6211f32589fa82a53067cjoshualitt    void getPathStencilSettingsForFilltype(GrPathRendering::FillType,
3178dc7c3a839b38b73af34cc2674a06f49eb1ce527egdaniel                                           const GrStencilAttachment*,
3189853ccef19c200be93a6211f32589fa82a53067cjoshualitt                                           GrStencilSettings*);
319a702415d9e80f5631181143c293498de924e8ae4joshualitt    virtual GrClipMaskManager* clipMaskManager() = 0;
3208dd688b7569df569a672a8a67b2db86a9d376cfcegdaniel    virtual bool setupClip(GrPipelineBuilder*,
3216be6f7cb66b277e7b1ce13d09b635fb8e09a2f68bsalomon                           GrPipelineBuilder::AutoRestoreFragmentProcessors*,
3226be6f7cb66b277e7b1ce13d09b635fb8e09a2f68bsalomon                           GrPipelineBuilder::AutoRestoreStencil*,
3236be6f7cb66b277e7b1ce13d09b635fb8e09a2f68bsalomon                           GrScissorState*,
3248059eb9f6e24ed609393fbda4ad71edea03ac258joshualitt                           const SkRect* devBounds) = 0;
3257475811143e190e172bf83d13c4bdba85704b604skia.committer@gmail.com
3266e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com    // The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTarget.
3276e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com    GrContext*                                                      fContext;
328a73239a0096370221d3dfababf339dd6d3fed84fbsalomon    SkAutoTUnref<const GrDrawTargetCaps>                            fCaps;
3292a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org    // To keep track that we always have at least as many debug marker adds as removes
3302a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org    int                                                             fGpuTraceMarkerCount;
3312a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org    GrTraceMarkerSet                                                fActiveTraceMarkers;
3323eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel    GrTraceMarkerSet                                                fStoredTraceMarkers;
333a73239a0096370221d3dfababf339dd6d3fed84fbsalomon    bool                                                            fFlushing;
334fa35e3ddcc9d130ce87c927218bdf27879c38711reed@google.com
335a4de8c257ea0be8ff7081f645249b6afe5c48e7ecommit-bot@chromium.org    typedef SkRefCnt INHERITED;
336ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com};
337ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
338329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt/*
339329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt * This class is JUST for clip mask manager.  Everyone else should just use draw target above.
340329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt */
3416db519c42471aaaa8a8e1a3ece314014481ab832joshualittclass GrClipTarget : public GrDrawTarget {
3426db519c42471aaaa8a8e1a3ece314014481ab832joshualittpublic:
343e40d39725908d99d255496025411e5c9ca32663erobertphillips    GrClipTarget(GrContext* context)
344e40d39725908d99d255496025411e5c9ca32663erobertphillips        : INHERITED(context) {
345329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt        fClipMaskManager.setClipTarget(this);
346329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt    }
347329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt
348329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt    /* Clip mask manager needs access to the context.
349329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt     * TODO we only need a very small subset of context in the CMM.
350329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt     */
351329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt    GrContext* getContext() { return INHERITED::getContext(); }
352329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt    const GrContext* getContext() const { return INHERITED::getContext(); }
353329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt
3546db519c42471aaaa8a8e1a3ece314014481ab832joshualitt    /**
3556db519c42471aaaa8a8e1a3ece314014481ab832joshualitt     * Clip Mask Manager(and no one else) needs to clear private stencil bits.
3566db519c42471aaaa8a8e1a3ece314014481ab832joshualitt     * ClipTarget subclass sets clip bit in the stencil buffer. The subclass
3576db519c42471aaaa8a8e1a3ece314014481ab832joshualitt     * is free to clear the remaining bits to zero if masked clears are more
3586db519c42471aaaa8a8e1a3ece314014481ab832joshualitt     * expensive than clearing all bits.
3596db519c42471aaaa8a8e1a3ece314014481ab832joshualitt     */
3606db519c42471aaaa8a8e1a3ece314014481ab832joshualitt    virtual void clearStencilClip(const SkIRect& rect, bool insideClip, GrRenderTarget* = NULL) = 0;
3616db519c42471aaaa8a8e1a3ece314014481ab832joshualitt
3623bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt    /**
3633bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt     * Release any resources that are cached but not currently in use. This
3643bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt     * is intended to give an application some recourse when resources are low.
3653bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt     */
36636352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    void purgeResources() override {
3673bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt        // The clip mask manager can rebuild all its clip masks so just
3683bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt        // get rid of them all.
3693bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt        fClipMaskManager.purgeResources();
3703bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt    };
3713bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt
372329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualittprotected:
373329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt    GrClipMaskManager           fClipMaskManager;
374329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt
3756db519c42471aaaa8a8e1a3ece314014481ab832joshualittprivate:
37636352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    GrClipMaskManager* clipMaskManager() override { return &fClipMaskManager; }
377329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt
3788dd688b7569df569a672a8a67b2db86a9d376cfcegdaniel    virtual bool setupClip(GrPipelineBuilder*,
3796be6f7cb66b277e7b1ce13d09b635fb8e09a2f68bsalomon                           GrPipelineBuilder::AutoRestoreFragmentProcessors*,
3806be6f7cb66b277e7b1ce13d09b635fb8e09a2f68bsalomon                           GrPipelineBuilder::AutoRestoreStencil*,
3818059eb9f6e24ed609393fbda4ad71edea03ac258joshualitt                           GrScissorState* scissorState,
38236352bf5e38f45a70ee4f4fc132a38048d38206dmtklein                           const SkRect* devBounds) override;
3832c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt
3846db519c42471aaaa8a8e1a3ece314014481ab832joshualitt    typedef GrDrawTarget INHERITED;
3856db519c42471aaaa8a8e1a3ece314014481ab832joshualitt};
3866db519c42471aaaa8a8e1a3ece314014481ab832joshualitt
387ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#endif
388