GrRenderTargetContext.h revision b726d58efc91c4eefa5cea0881a823ee108db8fd
1ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips/*
2ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips * Copyright 2015 Google Inc.
3ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips *
4ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips * Use of this source code is governed by a BSD-style license that can be
5ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips * found in the LICENSE file.
6ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips */
7ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips
81105224f9701e57ec5ce0354d6a380b664f5c638Brian Osman#ifndef GrRenderTargetContext_DEFINED
91105224f9701e57ec5ce0354d6a380b664f5c638Brian Osman#define GrRenderTargetContext_DEFINED
10ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips
11ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips#include "GrColor.h"
12faf8203ea7588dcdca82f69f5a5447b3eb53a849bsalomon#include "GrContext.h"
13ecbc12b1c1c72de0cf7bba4a3f6a7cce4f43bf41csmartdalton#include "GrPaint.h"
1445580d3e3024c1536e8e1b2017b704805442b634Brian Osman#include "GrSurfaceContext.h"
15467921e5e6479fe9cebba125657d8e33d89004aeBrian Salomon#include "GrXferProcessor.h"
16ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips#include "SkRefCnt.h"
17fcf7829b67b798aff4c41c4688daa9c7381991e6robertphillips#include "SkSurfaceProps.h"
18a7f29640f6ab4eb50962a9d9f12d01ac2ce8b471csmartdalton#include "../private/GrInstancedPipelineInfo.h"
19c7635fa374b87711e5ccd8222957a8fbdc772f7bRobert Phillips#include "../private/GrRenderTargetProxy.h"
20ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips
21ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillipsclass GrClip;
2277a2e52c7d5c77de73ecab5fec79072ee4460706robertphillipsclass GrDrawingManager;
239afd371a8a66f992f98eb2a3fc75ae64bddc730bBrian Salomonclass GrDrawOp;
2429df76096fd30941086324902a82656df2d8becdcsmartdaltonclass GrFixedClip;
25ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillipsclass GrPipelineBuilder;
26649a3411f99a8aea3c46e4ef1f495f61b9801164Brian Salomonclass GrMeshDrawOp;
27ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillipsclass GrRenderTarget;
2845580d3e3024c1536e8e1b2017b704805442b634Brian Osmanclass GrRenderTargetContextPriv;
29f2361d2d93c200cd4555b5e8ecea4531801abaaaRobert Phillipsclass GrRenderTargetOpList;
306663acff010ce752e4bf778da81fa97448c9db31bsalomonclass GrStyle;
31ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillipsclass GrSurface;
32eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillipsclass GrTextureProxy;
33443023975e335e3630191227dbc21fa72c436af3robertphillipsstruct GrUserStencilSettings;
342334fb655f8d4ef5915770d32bf845c88d3627f4robertphillipsclass SkDrawFilter;
35ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillipsstruct SkIPoint;
36ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillipsstruct SkIRect;
3710e3d9bf59bdec92c05367ae0b71e1ce1ee4a690msarettclass SkLatticeIter;
38ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillipsclass SkMatrix;
392334fb655f8d4ef5915770d32bf845c88d3627f4robertphillipsclass SkPaint;
40ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillipsclass SkPath;
41ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillipsstruct SkPoint;
42ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillipsstruct SkRect;
4345580d3e3024c1536e8e1b2017b704805442b634Brian Osmanclass SkRegion;
44ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillipsclass SkRRect;
4531ff762dc8bfcd86eb4af92b18fdad36913a04e5jvanverthstruct SkRSXform;
462334fb655f8d4ef5915770d32bf845c88d3627f4robertphillipsclass SkTextBlob;
47199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomonclass SkVertices;
48ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips
4945580d3e3024c1536e8e1b2017b704805442b634Brian Osman/**
5045580d3e3024c1536e8e1b2017b704805442b634Brian Osman * A helper object to orchestrate commands (draws, etc...) for GrSurfaces that are GrRenderTargets.
51ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips */
5245580d3e3024c1536e8e1b2017b704805442b634Brian Osmanclass SK_API GrRenderTargetContext : public GrSurfaceContext {
53ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillipspublic:
541105224f9701e57ec5ce0354d6a380b664f5c638Brian Osman    ~GrRenderTargetContext() override;
552334fb655f8d4ef5915770d32bf845c88d3627f4robertphillips
566f1d36cc54dc635f5e4d0f925ef79c14914342bbBrian Salomon    // We use SkPaint rather than GrPaint here for two reasons:
576f1d36cc54dc635f5e4d0f925ef79c14914342bbBrian Salomon    //    * The SkPaint carries extra text settings. If these were extracted to a lighter object
586f1d36cc54dc635f5e4d0f925ef79c14914342bbBrian Salomon    //      we could use GrPaint except that
596f1d36cc54dc635f5e4d0f925ef79c14914342bbBrian Salomon    //    * SkPaint->GrPaint conversion depends upon whether the glyphs are color or grayscale and
606f1d36cc54dc635f5e4d0f925ef79c14914342bbBrian Salomon    //      this can vary within a text run.
616f1d36cc54dc635f5e4d0f925ef79c14914342bbBrian Salomon    virtual void drawText(const GrClip&, const SkPaint&, const SkMatrix& viewMatrix,
6282f44319159bb98dcacdbbec7ea643dde5ed024bBrian Salomon                          const char text[], size_t byteLength, SkScalar x, SkScalar y,
6382f44319159bb98dcacdbbec7ea643dde5ed024bBrian Salomon                          const SkIRect& clipBounds);
646f1d36cc54dc635f5e4d0f925ef79c14914342bbBrian Salomon    virtual void drawPosText(const GrClip&, const SkPaint&, const SkMatrix& viewMatrix,
6582f44319159bb98dcacdbbec7ea643dde5ed024bBrian Salomon                             const char text[], size_t byteLength, const SkScalar pos[],
6682f44319159bb98dcacdbbec7ea643dde5ed024bBrian Salomon                             int scalarsPerPosition, const SkPoint& offset,
6782f44319159bb98dcacdbbec7ea643dde5ed024bBrian Salomon                             const SkIRect& clipBounds);
6896880d9e366d58e5960aa0ee6aa67260797679ebjoshualitt    virtual void drawTextBlob(const GrClip&, const SkPaint&,
6996880d9e366d58e5960aa0ee6aa67260797679ebjoshualitt                              const SkMatrix& viewMatrix, const SkTextBlob*,
7096880d9e366d58e5960aa0ee6aa67260797679ebjoshualitt                              SkScalar x, SkScalar y,
7196880d9e366d58e5960aa0ee6aa67260797679ebjoshualitt                              SkDrawFilter*, const SkIRect& clipBounds);
72ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips
73ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips    /**
74ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     * Provides a perfomance hint that the render target's contents are allowed
75ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     * to become undefined.
76ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     */
772e1e51f04985f7c258b96f0decc190456f5dd74drobertphillips    void discard();
78ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips
79ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips    /**
80ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     * Clear the entire or rect of the render target, ignoring any clips.
81ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     * @param rect  the rect to clear or the whole thing if rect is NULL.
82ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     * @param color the color to clear to.
83ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     * @param canIgnoreRect allows partial clears to be converted to whole
84ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     *                      clears on platforms for which that is cheap
85ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     */
862e1e51f04985f7c258b96f0decc190456f5dd74drobertphillips    void clear(const SkIRect* rect, GrColor color, bool canIgnoreRect);
87ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips
88ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips    /**
89ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     *  Draw everywhere (respecting the clip) with the paint.
90ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     */
9182f44319159bb98dcacdbbec7ea643dde5ed024bBrian Salomon    void drawPaint(const GrClip&, GrPaint&&, const SkMatrix& viewMatrix);
92ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips
93ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips    /**
940e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * Draw the rect using a paint.
950e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param paint        describes how to color pixels.
960e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param GrAA         Controls whether rect is antialiased
970e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param viewMatrix   transformation matrix
980e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param style        The style to apply. Null means fill. Currently path effects are not
990e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     *                     allowed.
1000e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * The rects coords are used to access the paint (through texture matrix)
101ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     */
1022e1e51f04985f7c258b96f0decc190456f5dd74drobertphillips    void drawRect(const GrClip&,
10382f44319159bb98dcacdbbec7ea643dde5ed024bBrian Salomon                  GrPaint&& paint,
1040e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon                  GrAA,
105ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips                  const SkMatrix& viewMatrix,
106ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips                  const SkRect&,
10782f44319159bb98dcacdbbec7ea643dde5ed024bBrian Salomon                  const GrStyle* style = nullptr);
108ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips
109ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips    /**
110a2e69fcdedbd9a7762620e0e9dcdd86596369cffbsalomon     * Maps a rectangle of shader coordinates to a rectangle and fills that rectangle.
111ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     *
1120e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param paint        describes how to color pixels.
1130e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param GrAA         Controls whether rect is antialiased
1140e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param viewMatrix   transformation matrix which applies to rectToDraw
1150e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param rectToDraw   the rectangle to draw
1160e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param localRect    the rectangle of shader coordinates applied to rectToDraw
117ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     */
118a2e69fcdedbd9a7762620e0e9dcdd86596369cffbsalomon    void fillRectToRect(const GrClip&,
11982f44319159bb98dcacdbbec7ea643dde5ed024bBrian Salomon                        GrPaint&& paint,
1200e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon                        GrAA,
121a2e69fcdedbd9a7762620e0e9dcdd86596369cffbsalomon                        const SkMatrix& viewMatrix,
122a2e69fcdedbd9a7762620e0e9dcdd86596369cffbsalomon                        const SkRect& rectToDraw,
123a2e69fcdedbd9a7762620e0e9dcdd86596369cffbsalomon                        const SkRect& localRect);
124ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips
125ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips    /**
126a2e69fcdedbd9a7762620e0e9dcdd86596369cffbsalomon     * Fills a rect with a paint and a localMatrix.
127ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     */
128a2e69fcdedbd9a7762620e0e9dcdd86596369cffbsalomon    void fillRectWithLocalMatrix(const GrClip& clip,
12982f44319159bb98dcacdbbec7ea643dde5ed024bBrian Salomon                                 GrPaint&& paint,
1300e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon                                 GrAA,
131a2e69fcdedbd9a7762620e0e9dcdd86596369cffbsalomon                                 const SkMatrix& viewMatrix,
132a2e69fcdedbd9a7762620e0e9dcdd86596369cffbsalomon                                 const SkRect& rect,
133a2e69fcdedbd9a7762620e0e9dcdd86596369cffbsalomon                                 const SkMatrix& localMatrix);
134ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips
135ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips    /**
1360e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * Draw a roundrect using a paint.
137ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     *
1380e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param paint       describes how to color pixels.
1390e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param GrAA        Controls whether rrect is antialiased.
1400e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param viewMatrix  transformation matrix
1410e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param rrect       the roundrect to draw
1420e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param style       style to apply to the rrect. Currently path effects are not allowed.
143ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     */
1442e1e51f04985f7c258b96f0decc190456f5dd74drobertphillips    void drawRRect(const GrClip&,
14582f44319159bb98dcacdbbec7ea643dde5ed024bBrian Salomon                   GrPaint&&,
1460e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon                   GrAA,
147ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips                   const SkMatrix& viewMatrix,
148ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips                   const SkRRect& rrect,
1496663acff010ce752e4bf778da81fa97448c9db31bsalomon                   const GrStyle& style);
150ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips
151ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips    /**
1520e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * Draw a roundrect using a paint and a shadow shader. This is separate from drawRRect
1530e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * because it uses different underlying geometry and GeometryProcessor
154c59034145862bf6dc0c503cb1e47eecd321ffa8cJim Van Verth     *
1550e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param paint        describes how to color pixels.
1560e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param viewMatrix   transformation matrix
1570e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param rrect        the roundrect to draw
1580e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param blurRadius   amount of shadow blur to apply (in device space)
1590e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param style        style to apply to the rrect. Currently path effects are not allowed.
160c59034145862bf6dc0c503cb1e47eecd321ffa8cJim Van Verth     */
161c59034145862bf6dc0c503cb1e47eecd321ffa8cJim Van Verth    void drawShadowRRect(const GrClip&,
16282f44319159bb98dcacdbbec7ea643dde5ed024bBrian Salomon                         GrPaint&&,
163c59034145862bf6dc0c503cb1e47eecd321ffa8cJim Van Verth                         const SkMatrix& viewMatrix,
164c59034145862bf6dc0c503cb1e47eecd321ffa8cJim Van Verth                         const SkRRect& rrect,
165c59034145862bf6dc0c503cb1e47eecd321ffa8cJim Van Verth                         SkScalar blurRadius,
166c59034145862bf6dc0c503cb1e47eecd321ffa8cJim Van Verth                         const GrStyle& style);
167c59034145862bf6dc0c503cb1e47eecd321ffa8cJim Van Verth
168c59034145862bf6dc0c503cb1e47eecd321ffa8cJim Van Verth    /**
1690e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * Shortcut for filling a SkPath consisting of nested rrects using a paint. The result is
1700e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * undefined if outer does not contain inner.
171000958973f4b514cddbfdcc01ec167437b66de2crobertphillips     *
1720e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param paint        describes how to color pixels.
1730e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param GrAA         Controls whether rrects edges are antialiased
1740e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param viewMatrix   transformation matrix
1750e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param outer        the outer roundrect
1760e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param inner        the inner roundrect
177000958973f4b514cddbfdcc01ec167437b66de2crobertphillips     */
178000958973f4b514cddbfdcc01ec167437b66de2crobertphillips    void drawDRRect(const GrClip&,
17982f44319159bb98dcacdbbec7ea643dde5ed024bBrian Salomon                    GrPaint&&,
1800e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon                    GrAA,
181000958973f4b514cddbfdcc01ec167437b66de2crobertphillips                    const SkMatrix& viewMatrix,
182000958973f4b514cddbfdcc01ec167437b66de2crobertphillips                    const SkRRect& outer,
183000958973f4b514cddbfdcc01ec167437b66de2crobertphillips                    const SkRRect& inner);
184000958973f4b514cddbfdcc01ec167437b66de2crobertphillips
185000958973f4b514cddbfdcc01ec167437b66de2crobertphillips    /**
186ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     * Draws a path.
187ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     *
188ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     * @param paint         describes how to color pixels.
1890e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param GrAA          Controls whether the path is antialiased.
190ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     * @param viewMatrix    transformation matrix
191ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     * @param path          the path to draw
1926663acff010ce752e4bf778da81fa97448c9db31bsalomon     * @param style         style to apply to the path.
193ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     */
1942e1e51f04985f7c258b96f0decc190456f5dd74drobertphillips    void drawPath(const GrClip&,
19582f44319159bb98dcacdbbec7ea643dde5ed024bBrian Salomon                  GrPaint&&,
1960e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon                  GrAA,
197ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips                  const SkMatrix& viewMatrix,
198ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips                  const SkPath&,
1996663acff010ce752e4bf778da81fa97448c9db31bsalomon                  const GrStyle& style);
200ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips
2013de0aee181b8fe0013b15100cba7381eb0468db4Brian Salomon    enum class ColorArrayType {
2023de0aee181b8fe0013b15100cba7381eb0468db4Brian Salomon        kPremulGrColor,
2033de0aee181b8fe0013b15100cba7381eb0468db4Brian Salomon        kSkColor,
2043de0aee181b8fe0013b15100cba7381eb0468db4Brian Salomon    };
205ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips    /**
206ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     * Draws vertices with a paint.
207ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     *
208ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     * @param   paint           describes how to color pixels.
209ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     * @param   viewMatrix      transformation matrix
210ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     * @param   primitiveType   primitives type to draw.
211ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     * @param   vertexCount     number of vertices.
212ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     * @param   positions       array of vertex positions, required.
213ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     * @param   texCoords       optional array of texture coordinates used
214ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     *                          to access the paint.
215ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     * @param   colors          optional array of per-vertex colors, supercedes
216ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     *                          the paint's color field.
217ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     * @param   indices         optional array of indices. If NULL vertices
218ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     *                          are drawn non-indexed.
219ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     * @param   indexCount      if indices is non-null then this is the
220ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     *                          number of indices.
2213de0aee181b8fe0013b15100cba7381eb0468db4Brian Salomon     * @param   ColorArrayType  Determines how the color array should be interpreted.
222ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     */
2232e1e51f04985f7c258b96f0decc190456f5dd74drobertphillips    void drawVertices(const GrClip&,
22482f44319159bb98dcacdbbec7ea643dde5ed024bBrian Salomon                      GrPaint&& paint,
225ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips                      const SkMatrix& viewMatrix,
226ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips                      GrPrimitiveType primitiveType,
227ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips                      int vertexCount,
228ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips                      const SkPoint positions[],
229ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips                      const SkPoint texs[],
2303de0aee181b8fe0013b15100cba7381eb0468db4Brian Salomon                      const uint32_t colors[],
231ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips                      const uint16_t indices[],
2323de0aee181b8fe0013b15100cba7381eb0468db4Brian Salomon                      int indexCount,
2333de0aee181b8fe0013b15100cba7381eb0468db4Brian Salomon                      ColorArrayType = ColorArrayType::kPremulGrColor);
234ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips
235ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips    /**
236199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon     * Draws vertices with a paint.
237199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon     *
238199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon     * @param   paint           describes how to color pixels.
239199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon     * @param   viewMatrix      transformation matrix
240199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon     * @param   veritces        specifies the mesh to draw.
241199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon     * @param   flags           A bitfield of options specified by SkCanvas::VerticesFlags.
242199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon     */
243199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon    void drawVertices(const GrClip&,
244199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon                      GrPaint&& paint,
245199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon                      const SkMatrix& viewMatrix,
246199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon                      sk_sp<SkVertices> vertices,
247199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon                      uint32_t flags);
248199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon
249199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon    /**
2500e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * Draws textured sprites from an atlas with a paint. This currently does not support AA for the
2510e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * sprite rectangle edges.
25231ff762dc8bfcd86eb4af92b18fdad36913a04e5jvanverth     *
25331ff762dc8bfcd86eb4af92b18fdad36913a04e5jvanverth     * @param   paint           describes how to color pixels.
25431ff762dc8bfcd86eb4af92b18fdad36913a04e5jvanverth     * @param   viewMatrix      transformation matrix
25531ff762dc8bfcd86eb4af92b18fdad36913a04e5jvanverth     * @param   spriteCount     number of sprites.
25631ff762dc8bfcd86eb4af92b18fdad36913a04e5jvanverth     * @param   xform           array of compressed transformation data, required.
25731ff762dc8bfcd86eb4af92b18fdad36913a04e5jvanverth     * @param   texRect         array of texture rectangles used to access the paint.
25831ff762dc8bfcd86eb4af92b18fdad36913a04e5jvanverth     * @param   colors          optional array of per-sprite colors, supercedes
25931ff762dc8bfcd86eb4af92b18fdad36913a04e5jvanverth     *                          the paint's color field.
26031ff762dc8bfcd86eb4af92b18fdad36913a04e5jvanverth     */
2612e1e51f04985f7c258b96f0decc190456f5dd74drobertphillips    void drawAtlas(const GrClip&,
26282f44319159bb98dcacdbbec7ea643dde5ed024bBrian Salomon                   GrPaint&& paint,
26331ff762dc8bfcd86eb4af92b18fdad36913a04e5jvanverth                   const SkMatrix& viewMatrix,
26431ff762dc8bfcd86eb4af92b18fdad36913a04e5jvanverth                   int spriteCount,
26531ff762dc8bfcd86eb4af92b18fdad36913a04e5jvanverth                   const SkRSXform xform[],
26631ff762dc8bfcd86eb4af92b18fdad36913a04e5jvanverth                   const SkRect texRect[],
26731ff762dc8bfcd86eb4af92b18fdad36913a04e5jvanverth                   const SkColor colors[]);
268cc319b95a58ae15e88c3c028b8726e7cab9121ffmsarett
269cc319b95a58ae15e88c3c028b8726e7cab9121ffmsarett    /**
270cc319b95a58ae15e88c3c028b8726e7cab9121ffmsarett     * Draws a region.
271cc319b95a58ae15e88c3c028b8726e7cab9121ffmsarett     *
272cc319b95a58ae15e88c3c028b8726e7cab9121ffmsarett     * @param paint         describes how to color pixels
273cc319b95a58ae15e88c3c028b8726e7cab9121ffmsarett     * @param viewMatrix    transformation matrix
2740e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param aa            should the rects of the region be antialiased.
275cc319b95a58ae15e88c3c028b8726e7cab9121ffmsarett     * @param region        the region to be drawn
276cc319b95a58ae15e88c3c028b8726e7cab9121ffmsarett     * @param style         style to apply to the region
277cc319b95a58ae15e88c3c028b8726e7cab9121ffmsarett     */
278cc319b95a58ae15e88c3c028b8726e7cab9121ffmsarett    void drawRegion(const GrClip&,
27982f44319159bb98dcacdbbec7ea643dde5ed024bBrian Salomon                    GrPaint&& paint,
2800e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon                    GrAA aa,
281cc319b95a58ae15e88c3c028b8726e7cab9121ffmsarett                    const SkMatrix& viewMatrix,
282cc319b95a58ae15e88c3c028b8726e7cab9121ffmsarett                    const SkRegion& region,
283cc319b95a58ae15e88c3c028b8726e7cab9121ffmsarett                    const GrStyle& style);
284cc319b95a58ae15e88c3c028b8726e7cab9121ffmsarett
28531ff762dc8bfcd86eb4af92b18fdad36913a04e5jvanverth    /**
286ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     * Draws an oval.
287ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     *
288ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     * @param paint         describes how to color pixels.
2890e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param GrAA          Controls whether the oval is antialiased.
290ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     * @param viewMatrix    transformation matrix
291ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     * @param oval          the bounding rect of the oval.
2926663acff010ce752e4bf778da81fa97448c9db31bsalomon     * @param style         style to apply to the oval. Currently path effects are not allowed.
293ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips     */
2942e1e51f04985f7c258b96f0decc190456f5dd74drobertphillips    void drawOval(const GrClip&,
29582f44319159bb98dcacdbbec7ea643dde5ed024bBrian Salomon                  GrPaint&& paint,
2960e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon                  GrAA,
297ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips                  const SkMatrix& viewMatrix,
298ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips                  const SkRect& oval,
2996663acff010ce752e4bf778da81fa97448c9db31bsalomon                  const GrStyle& style);
3000e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon    /**
3010e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * Draws a partial arc of an oval.
3020e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     *
3030e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param paint         describes how to color pixels.
3049950408c5f20148d5b726421454db718860077deBrian Salomon     * @param GrGrAA        Controls whether the arc is antialiased.
3050e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param viewMatrix    transformation matrix.
3060e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param oval          the bounding rect of the oval.
3070e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param startAngle    starting angle in degrees.
3080e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param sweepAngle    angle to sweep in degrees. Must be in (-360, 360)
3090e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param useCenter     true means that the implied path begins at the oval center, connects as
3100e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     *                      a line to the point indicated by the start contains the arc indicated by
3110e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     *                      the sweep angle. If false the line beginning at the center point is
3120e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     *                      omitted.
3130e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     * @param style         style to apply to the oval.
3140e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon     */
3154f3a0ca85d28a8fc7fcc1ac5c4a1864c66bdea14bsalomon    void drawArc(const GrClip&,
31682f44319159bb98dcacdbbec7ea643dde5ed024bBrian Salomon                 GrPaint&& paint,
3170e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon                 GrAA,
3184f3a0ca85d28a8fc7fcc1ac5c4a1864c66bdea14bsalomon                 const SkMatrix& viewMatrix,
3194f3a0ca85d28a8fc7fcc1ac5c4a1864c66bdea14bsalomon                 const SkRect& oval,
3204f3a0ca85d28a8fc7fcc1ac5c4a1864c66bdea14bsalomon                 SkScalar startAngle,
3214f3a0ca85d28a8fc7fcc1ac5c4a1864c66bdea14bsalomon                 SkScalar sweepAngle,
3224f3a0ca85d28a8fc7fcc1ac5c4a1864c66bdea14bsalomon                 bool useCenter,
3234f3a0ca85d28a8fc7fcc1ac5c4a1864c66bdea14bsalomon                 const GrStyle& style);
324ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips
32533a5fce6126dc5d3927a71fdc6c35af6f5893fd5joshualitt    /**
3264f3a0ca85d28a8fc7fcc1ac5c4a1864c66bdea14bsalomon     * Draw the image as a set of rects, specified by |iter|.
32733a5fce6126dc5d3927a71fdc6c35af6f5893fd5joshualitt     */
32810e3d9bf59bdec92c05367ae0b71e1ce1ee4a690msarett    void drawImageLattice(const GrClip&,
32982f44319159bb98dcacdbbec7ea643dde5ed024bBrian Salomon                          GrPaint&& paint,
33010e3d9bf59bdec92c05367ae0b71e1ce1ee4a690msarett                          const SkMatrix& viewMatrix,
33110e3d9bf59bdec92c05367ae0b71e1ce1ee4a690msarett                          int imageWidth,
33210e3d9bf59bdec92c05367ae0b71e1ce1ee4a690msarett                          int imageHeight,
33310e3d9bf59bdec92c05367ae0b71e1ce1ee4a690msarett                          std::unique_ptr<SkLatticeIter> iter,
33410e3d9bf59bdec92c05367ae0b71e1ce1ee4a690msarett                          const SkRect& dst);
335ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips
3368c523e0f3ffa66eefd70f893e9f863b7d9ea3dc9robertphillips    /**
3378c523e0f3ffa66eefd70f893e9f863b7d9ea3dc9robertphillips     * After this returns any pending surface IO will be issued to the backend 3D API and
3388c523e0f3ffa66eefd70f893e9f863b7d9ea3dc9robertphillips     * if the surface has MSAA it will be resolved.
3398c523e0f3ffa66eefd70f893e9f863b7d9ea3dc9robertphillips     */
3408c523e0f3ffa66eefd70f893e9f863b7d9ea3dc9robertphillips    void prepareForExternalIO();
3418c523e0f3ffa66eefd70f893e9f863b7d9ea3dc9robertphillips
342976f5f0dc5e907d1ca50685fad117bd15d7fc87brobertphillips    bool isStencilBufferMultisampled() const {
343c7635fa374b87711e5ccd8222957a8fbdc772f7bRobert Phillips        return fRenderTargetProxy->isStencilBufferMultisampled();
344976f5f0dc5e907d1ca50685fad117bd15d7fc87brobertphillips    }
345c7635fa374b87711e5ccd8222957a8fbdc772f7bRobert Phillips    bool isUnifiedMultisampled() const { return fRenderTargetProxy->isUnifiedMultisampled(); }
346c7635fa374b87711e5ccd8222957a8fbdc772f7bRobert Phillips    bool hasMixedSamples() const { return fRenderTargetProxy->isMixedSampled(); }
34782ec6e59b8b694c128adcf8590667d37327dd1c4robertphillips
348faf8203ea7588dcdca82f69f5a5447b3eb53a849bsalomon    const GrCaps* caps() const { return fContext->caps(); }
349c7635fa374b87711e5ccd8222957a8fbdc772f7bRobert Phillips    const GrSurfaceDesc& desc() const { return fRenderTargetProxy->desc(); }
350c7635fa374b87711e5ccd8222957a8fbdc772f7bRobert Phillips    int width() const { return fRenderTargetProxy->width(); }
351c7635fa374b87711e5ccd8222957a8fbdc772f7bRobert Phillips    int height() const { return fRenderTargetProxy->height(); }
352c7635fa374b87711e5ccd8222957a8fbdc772f7bRobert Phillips    GrPixelConfig config() const { return fRenderTargetProxy->config(); }
353c7635fa374b87711e5ccd8222957a8fbdc772f7bRobert Phillips    int numColorSamples() const { return fRenderTargetProxy->numColorSamples(); }
354ca6eafc0f7e59ed89f03a9891b9fdf7de64f1f35robertphillips    const SkSurfaceProps& surfaceProps() const { return fSurfaceProps; }
355c71a9b7f53938b4f33f36f48e867b8b72cc1cc61msarett    GrColorSpaceXform* getColorXformFromSRGB() const { return fColorXformFromSRGB.get(); }
356c7635fa374b87711e5ccd8222957a8fbdc772f7bRobert Phillips    GrSurfaceOrigin origin() const { return fRenderTargetProxy->origin(); }
3577bceedc550513b13e0065aca66e55204a2ba3e1frobertphillips
3587761d61876ea479dd9672b684fd5c7601932a767robertphillips    bool wasAbandoned() const;
3597761d61876ea479dd9672b684fd5c7601932a767robertphillips
360eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips    GrRenderTarget* instantiate();
361eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips
362c7635fa374b87711e5ccd8222957a8fbdc772f7bRobert Phillips    GrRenderTarget* accessRenderTarget() {
363c7635fa374b87711e5ccd8222957a8fbdc772f7bRobert Phillips        // TODO: usage of this entry point needs to be reduced and potentially eliminated
364c7635fa374b87711e5ccd8222957a8fbdc772f7bRobert Phillips        // since it ends the deferral of the GrRenderTarget's allocation
36532342f032e1dfd133040324f851f0365f9d4cb51Brian Osman        return fRenderTargetProxy->instantiate(fContext->resourceProvider());
366c7635fa374b87711e5ccd8222957a8fbdc772f7bRobert Phillips    }
3676c7e325236b7fbb9c9b14ebb4715f88a59718695robertphillips
368f200a90f3e58ce20753420cadced850d7d00dca1Robert Phillips    GrSurfaceProxy* asSurfaceProxy() override { return fRenderTargetProxy.get(); }
369f200a90f3e58ce20753420cadced850d7d00dca1Robert Phillips    const GrSurfaceProxy* asSurfaceProxy() const override { return fRenderTargetProxy.get(); }
370f200a90f3e58ce20753420cadced850d7d00dca1Robert Phillips    sk_sp<GrSurfaceProxy> asSurfaceProxyRef() override { return fRenderTargetProxy; }
371f200a90f3e58ce20753420cadced850d7d00dca1Robert Phillips
372f200a90f3e58ce20753420cadced850d7d00dca1Robert Phillips    GrTextureProxy* asTextureProxy() override;
373f200a90f3e58ce20753420cadced850d7d00dca1Robert Phillips    sk_sp<GrTextureProxy> asTextureProxyRef() override;
374f200a90f3e58ce20753420cadced850d7d00dca1Robert Phillips
375f200a90f3e58ce20753420cadced850d7d00dca1Robert Phillips    GrRenderTargetProxy* asRenderTargetProxy() override { return fRenderTargetProxy.get(); }
376f200a90f3e58ce20753420cadced850d7d00dca1Robert Phillips    sk_sp<GrRenderTargetProxy> asRenderTargetProxyRef() override { return fRenderTargetProxy; }
377eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips
378d46697ac36d5cb3b58571c6129cb5b26fe9d25d7Robert Phillips    GrRenderTargetContext* asRenderTargetContext() override { return this; }
379d46697ac36d5cb3b58571c6129cb5b26fe9d25d7Robert Phillips
380c7635fa374b87711e5ccd8222957a8fbdc772f7bRobert Phillips    sk_sp<GrTexture> asTexture() {
381e60ad620fe236ce4c1e85a31bd53ed0c848da8c3Robert Phillips        if (!this->accessRenderTarget()) {
382e60ad620fe236ce4c1e85a31bd53ed0c848da8c3Robert Phillips            return nullptr;
383e60ad620fe236ce4c1e85a31bd53ed0c848da8c3Robert Phillips        }
384e60ad620fe236ce4c1e85a31bd53ed0c848da8c3Robert Phillips
385c7635fa374b87711e5ccd8222957a8fbdc772f7bRobert Phillips        // TODO: usage of this entry point needs to be reduced and potentially eliminated
386c7635fa374b87711e5ccd8222957a8fbdc772f7bRobert Phillips        // since it ends the deferral of the GrRenderTarget's allocation
387f200a90f3e58ce20753420cadced850d7d00dca1Robert Phillips        // It's usage should migrate to asTextureProxyRef
388c7635fa374b87711e5ccd8222957a8fbdc772f7bRobert Phillips        return sk_ref_sp(this->accessRenderTarget()->asTexture());
389c7635fa374b87711e5ccd8222957a8fbdc772f7bRobert Phillips    }
390433625e67c61c3acce4fd95b3881493c9f4f2c7frobertphillips
391391395dcfbff09a83f8f0e9d3e02d38c855ae2e9robertphillips    // Provides access to functions that aren't part of the public API.
392693a540272a771c6b0830094c461397cb77543b1Brian Osman    GrRenderTargetContextPriv priv();
393693a540272a771c6b0830094c461397cb77543b1Brian Osman    const GrRenderTargetContextPriv priv() const;
394f5883a6d75a18c581507214d3057b5c721ed1ffcjoshualitt
395eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips    bool isWrapped_ForTesting() const;
396eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips
39796880d9e366d58e5960aa0ee6aa67260797679ebjoshualittprotected:
398c7635fa374b87711e5ccd8222957a8fbdc772f7bRobert Phillips    GrRenderTargetContext(GrContext*, GrDrawingManager*, sk_sp<GrRenderTargetProxy>,
3992c86249465c28a532c8be55b6ba497021e3110ecRobert Phillips                          sk_sp<SkColorSpace>, const SkSurfaceProps*, GrAuditTrail*,
400c7635fa374b87711e5ccd8222957a8fbdc772f7bRobert Phillips                          GrSingleOwner*);
401ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips
4022e1e51f04985f7c258b96f0decc190456f5dd74drobertphillips    SkDEBUGCODE(void validate() const;)
403ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips
40496880d9e366d58e5960aa0ee6aa67260797679ebjoshualittprivate:
4050e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon    inline GrAAType decideAAType(GrAA aa, bool allowMixedSamples = false) {
4060e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon        if (GrAA::kNo == aa) {
4070e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon            return GrAAType::kNone;
4080e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon        }
4090e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon        if (this->isUnifiedMultisampled()) {
4100e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon            return GrAAType::kMSAA;
4110e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon        }
4120e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon        if (allowMixedSamples && this->isStencilBufferMultisampled()) {
4130e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon            return GrAAType::kMixedSamples;
4140e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon        }
4150e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon        return GrAAType::kCoverage;
4160e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon    }
4170e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon
418649a3411f99a8aea3c46e4ef1f495f61b9801164Brian Salomon    friend class GrAtlasTextBlob;               // for access to add[Mesh]DrawOp
419649a3411f99a8aea3c46e4ef1f495f61b9801164Brian Salomon    friend class GrStencilAndCoverTextContext;  // for access to add[Mesh]DrawOp
42055fdcccf01d49173bc731024b4283d3a3ea9150arobertphillips
42196880d9e366d58e5960aa0ee6aa67260797679ebjoshualitt    friend class GrDrawingManager; // for ctor
4221105224f9701e57ec5ce0354d6a380b664f5c638Brian Osman    friend class GrRenderTargetContextPriv;
423649a3411f99a8aea3c46e4ef1f495f61b9801164Brian Salomon    friend class GrSWMaskHelper;  // for access to add[Mesh]DrawOp
42442521e891081a7a85db4390a457074054649f194Brian Salomon
42542521e891081a7a85db4390a457074054649f194Brian Salomon    // All the path renderers currently make their own ops
426649a3411f99a8aea3c46e4ef1f495f61b9801164Brian Salomon    friend class GrSoftwarePathRenderer;             // for access to add[Mesh]DrawOp
427649a3411f99a8aea3c46e4ef1f495f61b9801164Brian Salomon    friend class GrAAConvexPathRenderer;             // for access to add[Mesh]DrawOp
428649a3411f99a8aea3c46e4ef1f495f61b9801164Brian Salomon    friend class GrDashLinePathRenderer;             // for access to add[Mesh]DrawOp
429649a3411f99a8aea3c46e4ef1f495f61b9801164Brian Salomon    friend class GrAAHairLinePathRenderer;           // for access to add[Mesh]DrawOp
430649a3411f99a8aea3c46e4ef1f495f61b9801164Brian Salomon    friend class GrAALinearizingConvexPathRenderer;  // for access to add[Mesh]DrawOp
431649a3411f99a8aea3c46e4ef1f495f61b9801164Brian Salomon    friend class GrAADistanceFieldPathRenderer;      // for access to add[Mesh]DrawOp
432649a3411f99a8aea3c46e4ef1f495f61b9801164Brian Salomon    friend class GrDefaultPathRenderer;              // for access to add[Mesh]DrawOp
433649a3411f99a8aea3c46e4ef1f495f61b9801164Brian Salomon    friend class GrMSAAPathRenderer;                 // for access to add[Mesh]DrawOp
434649a3411f99a8aea3c46e4ef1f495f61b9801164Brian Salomon    friend class GrStencilAndCoverPathRenderer;      // for access to add[Mesh]DrawOp
435649a3411f99a8aea3c46e4ef1f495f61b9801164Brian Salomon    friend class GrTessellatingPathRenderer;         // for access to add[Mesh]DrawOp
4365d4cd9ea8818f65bb4878c050dbdb9dcd48505adBrian Salomon    // for a unit test
43730f9bc69cfc506075e1fce8e7934f941c0203023Robert Phillips    friend void test_draw_op(GrContext*, GrRenderTargetContext*,
43830f9bc69cfc506075e1fce8e7934f941c0203023Robert Phillips                             sk_sp<GrFragmentProcessor>, sk_sp<GrTextureProxy>);
439ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips
44029df76096fd30941086324902a82656df2d8becdcsmartdalton    void internalClear(const GrFixedClip&, const GrColor, bool canIgnoreClip);
44129df76096fd30941086324902a82656df2d8becdcsmartdalton
44282f44319159bb98dcacdbbec7ea643dde5ed024bBrian Salomon    // Only consumes the GrPaint if successful.
443000958973f4b514cddbfdcc01ec167437b66de2crobertphillips    bool drawFilledDRRect(const GrClip& clip,
44482f44319159bb98dcacdbbec7ea643dde5ed024bBrian Salomon                          GrPaint&& paint,
4450e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon                          GrAA,
446000958973f4b514cddbfdcc01ec167437b66de2crobertphillips                          const SkMatrix& viewMatrix,
447000958973f4b514cddbfdcc01ec167437b66de2crobertphillips                          const SkRRect& origOuter,
448000958973f4b514cddbfdcc01ec167437b66de2crobertphillips                          const SkRRect& origInner);
449000958973f4b514cddbfdcc01ec167437b66de2crobertphillips
45082f44319159bb98dcacdbbec7ea643dde5ed024bBrian Salomon    // Only consumes the GrPaint if successful.
451443023975e335e3630191227dbc21fa72c436af3robertphillips    bool drawFilledRect(const GrClip& clip,
45282f44319159bb98dcacdbbec7ea643dde5ed024bBrian Salomon                        GrPaint&& paint,
4530e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon                        GrAA,
454443023975e335e3630191227dbc21fa72c436af3robertphillips                        const SkMatrix& viewMatrix,
455443023975e335e3630191227dbc21fa72c436af3robertphillips                        const SkRect& rect,
456443023975e335e3630191227dbc21fa72c436af3robertphillips                        const GrUserStencilSettings* ss);
457443023975e335e3630191227dbc21fa72c436af3robertphillips
458443023975e335e3630191227dbc21fa72c436af3robertphillips    void drawNonAAFilledRect(const GrClip&,
45982f44319159bb98dcacdbbec7ea643dde5ed024bBrian Salomon                             GrPaint&&,
460443023975e335e3630191227dbc21fa72c436af3robertphillips                             const SkMatrix& viewMatrix,
461443023975e335e3630191227dbc21fa72c436af3robertphillips                             const SkRect& rect,
462443023975e335e3630191227dbc21fa72c436af3robertphillips                             const SkRect* localRect,
463443023975e335e3630191227dbc21fa72c436af3robertphillips                             const SkMatrix* localMatrix,
46434ee0c950e1aa24818632084acdb382514f98c08csmartdalton                             const GrUserStencilSettings* ss,
4650e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon                             GrAAType hwOrNoneAAType);
4660e8fc8b9e6a138cf4a66b421fb824679df717329Brian Salomon
46782f44319159bb98dcacdbbec7ea643dde5ed024bBrian Salomon    void internalDrawPath(
46882f44319159bb98dcacdbbec7ea643dde5ed024bBrian Salomon            const GrClip&, GrPaint&&, GrAA, const SkMatrix&, const SkPath&, const GrStyle&);
469ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips
470e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips    bool onCopy(GrSurfaceProxy* src, const SkIRect& srcRect, const SkIPoint& dstPoint) override;
4712c86249465c28a532c8be55b6ba497021e3110ecRobert Phillips    bool onReadPixels(const SkImageInfo& dstInfo, void* dstBuffer,
472b726d58efc91c4eefa5cea0881a823ee108db8fdRobert Phillips                      size_t dstRowBytes, int x, int y, uint32_t flags) override;
4732c86249465c28a532c8be55b6ba497021e3110ecRobert Phillips    bool onWritePixels(const SkImageInfo& srcInfo, const void* srcBuffer,
47430f9bc69cfc506075e1fce8e7934f941c0203023Robert Phillips                       size_t srcRowBytes, int x, int y, uint32_t flags) override;
475e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips
476649a3411f99a8aea3c46e4ef1f495f61b9801164Brian Salomon    // These perform processing specific to Gr[Mesh]DrawOp-derived ops before recording them into
477649a3411f99a8aea3c46e4ef1f495f61b9801164Brian Salomon    // the op list. They return the id of the opList to which the op was added, or 0, if it was
478c01389271162d08303088732c30f419807f25d33Robert Phillips    // dropped (e.g., due to clipping).
479c01389271162d08303088732c30f419807f25d33Robert Phillips    uint32_t addDrawOp(const GrPipelineBuilder&, const GrClip&, std::unique_ptr<GrDrawOp>);
480649a3411f99a8aea3c46e4ef1f495f61b9801164Brian Salomon    uint32_t addMeshDrawOp(const GrPipelineBuilder&, const GrClip&,
481649a3411f99a8aea3c46e4ef1f495f61b9801164Brian Salomon                           std::unique_ptr<GrMeshDrawOp> op);
4822334fb655f8d4ef5915770d32bf845c88d3627f4robertphillips
483467921e5e6479fe9cebba125657d8e33d89004aeBrian Salomon    // Makes a copy of the dst if it is necessary for the draw and returns the texture that should
484467921e5e6479fe9cebba125657d8e33d89004aeBrian Salomon    // be used by GrXferProcessor to access the destination color. If the texture is nullptr then
485467921e5e6479fe9cebba125657d8e33d89004aeBrian Salomon    // a texture copy could not be made.
486467921e5e6479fe9cebba125657d8e33d89004aeBrian Salomon    void setupDstTexture(GrRenderTarget*, const GrClip&, const SkRect& opBounds,
487467921e5e6479fe9cebba125657d8e33d89004aeBrian Salomon                         GrXferProcessor::DstTexture*);
488467921e5e6479fe9cebba125657d8e33d89004aeBrian Salomon
489467921e5e6479fe9cebba125657d8e33d89004aeBrian Salomon
490f2361d2d93c200cd4555b5e8ecea4531801abaaaRobert Phillips    GrRenderTargetOpList* getOpList();
491a106c627532ad669cf7d879955ae8ea6a53233c1robertphillips
492c7635fa374b87711e5ccd8222957a8fbdc772f7bRobert Phillips    sk_sp<GrRenderTargetProxy>        fRenderTargetProxy;
493a106c627532ad669cf7d879955ae8ea6a53233c1robertphillips
4941105224f9701e57ec5ce0354d6a380b664f5c638Brian Osman    // In MDB-mode the GrOpList can be closed by some other renderTargetContext that has picked
495f2361d2d93c200cd4555b5e8ecea4531801abaaaRobert Phillips    // it up. For this reason, the GrOpList should only ever be accessed via 'getOpList'.
496f2361d2d93c200cd4555b5e8ecea4531801abaaaRobert Phillips    GrRenderTargetOpList*             fOpList;
497c71a9b7f53938b4f33f36f48e867b8b72cc1cc61msarett    GrInstancedPipelineInfo           fInstancedPipelineInfo;
4982334fb655f8d4ef5915770d32bf845c88d3627f4robertphillips
499c71a9b7f53938b4f33f36f48e867b8b72cc1cc61msarett    sk_sp<GrColorSpaceXform>          fColorXformFromSRGB;
500c71a9b7f53938b4f33f36f48e867b8b72cc1cc61msarett    SkSurfaceProps                    fSurfaceProps;
501e305cc1f2a44e47d6a0dcc0ff34e2692349aed5dRobert Phillips
502e305cc1f2a44e47d6a0dcc0ff34e2692349aed5dRobert Phillips    typedef GrSurfaceContext INHERITED;
503ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips};
504ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips
505ea4615034498aca2f9ca1753fb9a1ef10508d8ccrobertphillips#endif
506