OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2015 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #ifndef GrDrawContext_DEFINED |
| 9 #define GrDrawContext_DEFINED |
| 10 |
| 11 #include "GrColor.h" |
| 12 #include "SkRefCnt.h" |
| 13 |
| 14 class GrBatch; |
| 15 class GrClip; |
| 16 class GrContext; |
| 17 class GrDrawTarget; |
| 18 class GrPaint; |
| 19 class GrPathProcessor; |
| 20 class GrPathRange; |
| 21 class GrPipelineBuilder; |
| 22 class GrRenderTarget; |
| 23 class GrStrokeInfo; |
| 24 class GrSurface; |
| 25 struct SkIPoint; |
| 26 struct SkIRect; |
| 27 class SkMatrix; |
| 28 class SkPath; |
| 29 struct SkPoint; |
| 30 struct SkRect; |
| 31 class SkRRect; |
| 32 |
| 33 |
| 34 /* |
| 35 * A helper object to orchestrate draws |
| 36 */ |
| 37 class SK_API GrDrawContext : public SkRefCnt { |
| 38 public: |
| 39 SK_DECLARE_INST_COUNT(GrDrawContext) |
| 40 |
| 41 void copySurface(GrRenderTarget* dst, GrSurface* src, |
| 42 const SkIRect& srcRect, const SkIPoint& dstPoint); |
| 43 |
| 44 // drawText and drawPaths are thanks to the GrAtlasTextContext and the |
| 45 // GrStencilAndCoverTextContext respectively |
| 46 // TODO: remove these two |
| 47 void drawText(GrPipelineBuilder* pipelineBuilder, GrBatch* batch); |
| 48 |
| 49 void drawPaths(GrPipelineBuilder* pipelineBuilder, |
| 50 const GrPathProcessor* pathProc, |
| 51 const GrPathRange* pathRange, |
| 52 const void* indices, |
| 53 int /*GrDrawTarget::PathIndexType*/ indexType, |
| 54 const float transformValues[], |
| 55 int /*GrDrawTarget::PathTransformType*/ transformType, |
| 56 int count, |
| 57 int /*GrPathRendering::FillType*/ fill); |
| 58 |
| 59 /** |
| 60 * Provides a perfomance hint that the render target's contents are allowed |
| 61 * to become undefined. |
| 62 */ |
| 63 void discard(GrRenderTarget*); |
| 64 |
| 65 /** |
| 66 * Clear the entire or rect of the render target, ignoring any clips. |
| 67 * @param target The render target to clear. |
| 68 * @param rect the rect to clear or the whole thing if rect is NULL. |
| 69 * @param color the color to clear to. |
| 70 * @param canIgnoreRect allows partial clears to be converted to whole |
| 71 * clears on platforms for which that is cheap |
| 72 */ |
| 73 void clear(GrRenderTarget*, const SkIRect* rect, GrColor color, bool canIgno
reRect); |
| 74 |
| 75 /** |
| 76 * Draw everywhere (respecting the clip) with the paint. |
| 77 */ |
| 78 void drawPaint(GrRenderTarget*, const GrClip&, const GrPaint&, const SkMatri
x& viewMatrix); |
| 79 |
| 80 /** |
| 81 * Draw the rect using a paint. |
| 82 * @param paint describes how to color pixels. |
| 83 * @param viewMatrix transformation matrix |
| 84 * @param strokeInfo the stroke information (width, join, cap), and. |
| 85 * the dash information (intervals, count, phase). |
| 86 * If strokeInfo == NULL, then the rect is filled. |
| 87 * Otherwise, if stroke width == 0, then the stroke |
| 88 * is always a single pixel thick, else the rect is |
| 89 * mitered/beveled stroked based on stroke width. |
| 90 * The rects coords are used to access the paint (through texture matrix) |
| 91 */ |
| 92 void drawRect(GrRenderTarget*, |
| 93 const GrClip&, |
| 94 const GrPaint& paint, |
| 95 const SkMatrix& viewMatrix, |
| 96 const SkRect&, |
| 97 const GrStrokeInfo* strokeInfo = NULL); |
| 98 |
| 99 /** |
| 100 * Maps a rectangle of shader coordinates to a rectangle and draws that rect
angle |
| 101 * |
| 102 * @param paint describes how to color pixels. |
| 103 * @param viewMatrix transformation matrix which applies to rectToDraw |
| 104 * @param rectToDraw the rectangle to draw |
| 105 * @param localRect the rectangle of shader coordinates applied to rectT
oDraw |
| 106 * @param localMatrix an optional matrix to transform the shader coordinat
es before applying |
| 107 * to rectToDraw |
| 108 */ |
| 109 void drawNonAARectToRect(GrRenderTarget*, |
| 110 const GrClip&, |
| 111 const GrPaint& paint, |
| 112 const SkMatrix& viewMatrix, |
| 113 const SkRect& rectToDraw, |
| 114 const SkRect& localRect, |
| 115 const SkMatrix* localMatrix = NULL); |
| 116 |
| 117 /** |
| 118 * Draws a non-AA rect with paint and a localMatrix |
| 119 */ |
| 120 void drawNonAARectWithLocalMatrix(GrRenderTarget* rt, |
| 121 const GrClip& clip, |
| 122 const GrPaint& paint, |
| 123 const SkMatrix& viewMatrix, |
| 124 const SkRect& rect, |
| 125 const SkMatrix& localMatrix) { |
| 126 this->drawNonAARectToRect(rt, clip, paint, viewMatrix, rect, rect, &loca
lMatrix); |
| 127 } |
| 128 |
| 129 /** |
| 130 * Draw a roundrect using a paint. |
| 131 * |
| 132 * @param paint describes how to color pixels. |
| 133 * @param viewMatrix transformation matrix |
| 134 * @param rrect the roundrect to draw |
| 135 * @param strokeInfo the stroke information (width, join, cap) and |
| 136 * the dash information (intervals, count, phase). |
| 137 */ |
| 138 void drawRRect(GrRenderTarget*, |
| 139 const GrClip&, |
| 140 const GrPaint&, |
| 141 const SkMatrix& viewMatrix, |
| 142 const SkRRect& rrect, |
| 143 const GrStrokeInfo&); |
| 144 |
| 145 /** |
| 146 * Shortcut for drawing an SkPath consisting of nested rrects using a paint
. |
| 147 * Does not support stroking. The result is undefined if outer does not con
tain |
| 148 * inner. |
| 149 * |
| 150 * @param paint describes how to color pixels. |
| 151 * @param viewMatrix transformation matrix |
| 152 * @param outer the outer roundrect |
| 153 * @param inner the inner roundrect |
| 154 */ |
| 155 void drawDRRect(GrRenderTarget*, |
| 156 const GrClip&, |
| 157 const GrPaint&, |
| 158 const SkMatrix& viewMatrix, |
| 159 const SkRRect& outer, |
| 160 const SkRRect& inner); |
| 161 |
| 162 |
| 163 /** |
| 164 * Draws a path. |
| 165 * |
| 166 * @param paint describes how to color pixels. |
| 167 * @param viewMatrix transformation matrix |
| 168 * @param path the path to draw |
| 169 * @param strokeInfo the stroke information (width, join, cap) and |
| 170 * the dash information (intervals, count, phase). |
| 171 */ |
| 172 void drawPath(GrRenderTarget*, |
| 173 const GrClip&, |
| 174 const GrPaint&, |
| 175 const SkMatrix& viewMatrix, |
| 176 const SkPath&, |
| 177 const GrStrokeInfo&); |
| 178 |
| 179 /** |
| 180 * Draws vertices with a paint. |
| 181 * |
| 182 * @param paint describes how to color pixels. |
| 183 * @param viewMatrix transformation matrix |
| 184 * @param primitiveType primitives type to draw. |
| 185 * @param vertexCount number of vertices. |
| 186 * @param positions array of vertex positions, required. |
| 187 * @param texCoords optional array of texture coordinates used |
| 188 * to access the paint. |
| 189 * @param colors optional array of per-vertex colors, supercedes |
| 190 * the paint's color field. |
| 191 * @param indices optional array of indices. If NULL vertices |
| 192 * are drawn non-indexed. |
| 193 * @param indexCount if indices is non-null then this is the |
| 194 * number of indices. |
| 195 */ |
| 196 void drawVertices(GrRenderTarget*, |
| 197 const GrClip&, |
| 198 const GrPaint& paint, |
| 199 const SkMatrix& viewMatrix, |
| 200 GrPrimitiveType primitiveType, |
| 201 int vertexCount, |
| 202 const SkPoint positions[], |
| 203 const SkPoint texs[], |
| 204 const GrColor colors[], |
| 205 const uint16_t indices[], |
| 206 int indexCount); |
| 207 |
| 208 /** |
| 209 * Draws an oval. |
| 210 * |
| 211 * @param paint describes how to color pixels. |
| 212 * @param viewMatrix transformation matrix |
| 213 * @param oval the bounding rect of the oval. |
| 214 * @param strokeInfo the stroke information (width, join, cap) and |
| 215 * the dash information (intervals, count, phase). |
| 216 */ |
| 217 void drawOval(GrRenderTarget*, |
| 218 const GrClip&, |
| 219 const GrPaint& paint, |
| 220 const SkMatrix& viewMatrix, |
| 221 const SkRect& oval, |
| 222 const GrStrokeInfo& strokeInfo); |
| 223 |
| 224 |
| 225 private: |
| 226 friend class GrContext; // for ctor |
| 227 |
| 228 GrDrawContext(GrContext* context, GrDrawTarget* drawTarget); |
| 229 |
| 230 // Sets the paint. Returns true on success; false on failure. |
| 231 bool prepareToDraw(GrPipelineBuilder*, |
| 232 GrRenderTarget* rt, |
| 233 const GrClip&, |
| 234 const GrPaint* paint); |
| 235 |
| 236 // A simpler version of the above which just returns true on success; false
on failure. |
| 237 // Clip is *NOT* set |
| 238 bool prepareToDraw(GrRenderTarget* rt); |
| 239 |
| 240 void internalDrawPath(GrDrawTarget*, |
| 241 GrPipelineBuilder*, |
| 242 const SkMatrix& viewMatrix, |
| 243 GrColor, |
| 244 bool useAA, |
| 245 const SkPath&, |
| 246 const GrStrokeInfo&); |
| 247 |
| 248 GrContext* fContext; // owning context -> no ref |
| 249 SkAutoTUnref<GrDrawTarget> fDrawTarget; |
| 250 }; |
| 251 |
| 252 #endif |
OLD | NEW |