GrRenderTargetContext.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  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. #ifndef GrRenderTargetContext_DEFINED
  8. #define GrRenderTargetContext_DEFINED
  9. #include "include/core/SkCanvas.h"
  10. #include "include/core/SkDrawable.h"
  11. #include "include/core/SkRefCnt.h"
  12. #include "include/core/SkSurface.h"
  13. #include "include/core/SkSurfaceProps.h"
  14. #include "include/private/GrTypesPriv.h"
  15. #include "src/gpu/GrPaint.h"
  16. #include "src/gpu/GrRenderTargetOpList.h"
  17. #include "src/gpu/GrRenderTargetProxy.h"
  18. #include "src/gpu/GrSurfaceContext.h"
  19. #include "src/gpu/GrXferProcessor.h"
  20. #include "src/gpu/geometry/GrQuad.h"
  21. #include "src/gpu/text/GrTextTarget.h"
  22. class GrBackendSemaphore;
  23. class GrClip;
  24. class GrColorSpaceXform;
  25. class GrCoverageCountingPathRenderer;
  26. class GrDrawingManager;
  27. class GrDrawOp;
  28. class GrFixedClip;
  29. class GrOp;
  30. class GrRenderTarget;
  31. class GrRenderTargetContextPriv;
  32. class GrShape;
  33. class GrStyle;
  34. class GrTextureProxy;
  35. struct GrUserStencilSettings;
  36. struct SkDrawShadowRec;
  37. class SkGlyphRunList;
  38. struct SkIPoint;
  39. struct SkIRect;
  40. class SkLatticeIter;
  41. class SkMatrix;
  42. class SkPaint;
  43. class SkPath;
  44. struct SkPoint;
  45. struct SkRect;
  46. class SkRegion;
  47. class SkRRect;
  48. struct SkRSXform;
  49. class SkTextBlob;
  50. class SkVertices;
  51. /**
  52. * A helper object to orchestrate commands (draws, etc...) for GrSurfaces that are GrRenderTargets.
  53. */
  54. class SK_API GrRenderTargetContext : public GrSurfaceContext {
  55. public:
  56. ~GrRenderTargetContext() override;
  57. virtual void drawGlyphRunList(const GrClip&, const SkMatrix& viewMatrix, const SkGlyphRunList&);
  58. /**
  59. * Provides a perfomance hint that the render target's contents are allowed
  60. * to become undefined.
  61. */
  62. void discard();
  63. enum class CanClearFullscreen : bool {
  64. kNo = false,
  65. kYes = true
  66. };
  67. /**
  68. * Clear the entire or rect of the render target, ignoring any clips.
  69. * @param rect the rect to clear or the whole thing if rect is NULL.
  70. * @param color the color to clear to.
  71. * @param CanClearFullscreen allows partial clears to be converted to fullscreen clears on
  72. * tiling platforms where that is an optimization.
  73. */
  74. void clear(const SkIRect* rect, const SkPMColor4f& color, CanClearFullscreen);
  75. /**
  76. * Draw everywhere (respecting the clip) with the paint.
  77. */
  78. void drawPaint(const GrClip&, GrPaint&&, const SkMatrix& viewMatrix);
  79. /**
  80. * Draw the rect using a paint.
  81. * @param paint describes how to color pixels.
  82. * @param GrAA Controls whether rect is antialiased
  83. * @param viewMatrix transformation matrix
  84. * @param style The style to apply. Null means fill. Currently path effects are not
  85. * allowed.
  86. * The rects coords are used to access the paint (through texture matrix)
  87. */
  88. void drawRect(const GrClip&,
  89. GrPaint&& paint,
  90. GrAA,
  91. const SkMatrix& viewMatrix,
  92. const SkRect&,
  93. const GrStyle* style = nullptr);
  94. /**
  95. * Maps a rectangle of shader coordinates to a rectangle and fills that rectangle.
  96. *
  97. * @param paint describes how to color pixels.
  98. * @param GrAA Controls whether rect is antialiased
  99. * @param viewMatrix transformation matrix which applies to rectToDraw
  100. * @param rectToDraw the rectangle to draw
  101. * @param localRect the rectangle of shader coordinates applied to rectToDraw
  102. */
  103. void fillRectToRect(const GrClip& clip,
  104. GrPaint&& paint,
  105. GrAA aa,
  106. const SkMatrix& viewMatrix,
  107. const SkRect& rectToDraw,
  108. const SkRect& localRect) {
  109. this->drawFilledQuad(clip, std::move(paint), aa,
  110. aa == GrAA::kYes ? GrQuadAAFlags::kAll : GrQuadAAFlags::kNone,
  111. GrQuad::MakeFromRect(rectToDraw, viewMatrix), GrQuad(localRect));
  112. }
  113. /**
  114. * Fills a rect with a paint and a localMatrix.
  115. */
  116. void fillRectWithLocalMatrix(const GrClip& clip,
  117. GrPaint&& paint,
  118. GrAA aa,
  119. const SkMatrix& viewMatrix,
  120. const SkRect& rect,
  121. const SkMatrix& localMatrix) {
  122. this->drawFilledQuad(clip, std::move(paint), aa,
  123. aa == GrAA::kYes ? GrQuadAAFlags::kAll : GrQuadAAFlags::kNone,
  124. GrQuad::MakeFromRect(rect, viewMatrix),
  125. GrQuad::MakeFromRect(rect, localMatrix));
  126. }
  127. /**
  128. * Creates an op that draws a fill rect with per-edge control over anti-aliasing.
  129. *
  130. * This is a specialized version of fillQuadWithEdgeAA, but is kept separate since knowing
  131. * the geometry is a rectangle affords more optimizations.
  132. */
  133. void fillRectWithEdgeAA(const GrClip& clip, GrPaint&& paint, GrAA aa, GrQuadAAFlags edgeAA,
  134. const SkMatrix& viewMatrix, const SkRect& rect,
  135. const SkRect* optionalLocalRect = nullptr) {
  136. const SkRect& localRect = optionalLocalRect ? *optionalLocalRect : rect;
  137. this->drawFilledQuad(clip, std::move(paint), aa, edgeAA,
  138. GrQuad::MakeFromRect(rect, viewMatrix), GrQuad(localRect));
  139. }
  140. /**
  141. * Similar to fillRectWithEdgeAA but draws an arbitrary 2D convex quadrilateral transformed
  142. * by 'viewMatrix', with per-edge control over anti-aliasing. The quad should follow the
  143. * ordering used by SkRect::toQuad(), which determines how the edge AA is applied:
  144. * - "top" = points [0] and [1]
  145. * - "right" = points[1] and [2]
  146. * - "bottom" = points[2] and [3]
  147. * - "left" = points[3] and [0]
  148. *
  149. * The last argument, 'optionalLocalQuad', can be null if no separate local coordinates are
  150. * necessary.
  151. */
  152. void fillQuadWithEdgeAA(const GrClip& clip, GrPaint&& paint, GrAA aa, GrQuadAAFlags edgeAA,
  153. const SkMatrix& viewMatrix, const SkPoint quad[4],
  154. const SkPoint optionalLocalQuad[4]) {
  155. const SkPoint* localQuad = optionalLocalQuad ? optionalLocalQuad : quad;
  156. this->drawFilledQuad(clip, std::move(paint), aa, edgeAA,
  157. GrQuad::MakeFromSkQuad(quad, viewMatrix),
  158. GrQuad::MakeFromSkQuad(localQuad, SkMatrix::I()));
  159. }
  160. /** Used with drawQuadSet */
  161. struct QuadSetEntry {
  162. SkRect fRect;
  163. SkPMColor4f fColor; // Overrides any color on the GrPaint
  164. SkMatrix fLocalMatrix;
  165. GrQuadAAFlags fAAFlags;
  166. };
  167. // TODO(michaelludwig) - remove if the bulk API is not useful for SkiaRenderer
  168. void drawQuadSet(const GrClip& clip, GrPaint&& paint, GrAA aa, const SkMatrix& viewMatrix,
  169. const QuadSetEntry[], int cnt);
  170. /**
  171. * Creates an op that draws a subrectangle of a texture. The passed color is modulated by the
  172. * texture's color. 'srcRect' specifies the rectangle of the texture to draw. 'dstRect'
  173. * specifies the rectangle to draw in local coords which will be transformed by 'viewMatrix' to
  174. * device space.
  175. */
  176. void drawTexture(const GrClip& clip, sk_sp<GrTextureProxy> proxy, GrSamplerState::Filter filter,
  177. SkBlendMode mode, const SkPMColor4f& color, const SkRect& srcRect,
  178. const SkRect& dstRect, GrAA aa, GrQuadAAFlags edgeAA,
  179. SkCanvas::SrcRectConstraint constraint, const SkMatrix& viewMatrix,
  180. sk_sp<GrColorSpaceXform> texXform) {
  181. const SkRect* domain = constraint == SkCanvas::kStrict_SrcRectConstraint ?
  182. &srcRect : nullptr;
  183. this->drawTexturedQuad(clip, std::move(proxy), std::move(texXform), filter,
  184. color, mode, aa, edgeAA, GrQuad::MakeFromRect(dstRect, viewMatrix),
  185. GrQuad(srcRect), domain);
  186. }
  187. /**
  188. * Variant of drawTexture that instead draws the texture applied to 'dstQuad' transformed by
  189. * 'viewMatrix', using the 'srcQuad' texture coordinates clamped to the optional 'domain'. If
  190. * 'domain' is null, it's equivalent to using the fast src rect constraint. If 'domain' is
  191. * provided, the strict src rect constraint is applied using 'domain'.
  192. */
  193. void drawTextureQuad(const GrClip& clip, sk_sp<GrTextureProxy> proxy,
  194. GrSamplerState::Filter filter, SkBlendMode mode, const SkPMColor4f& color,
  195. const SkPoint srcQuad[4], const SkPoint dstQuad[4], GrAA aa,
  196. GrQuadAAFlags edgeAA, const SkRect* domain, const SkMatrix& viewMatrix,
  197. sk_sp<GrColorSpaceXform> texXform) {
  198. this->drawTexturedQuad(clip, std::move(proxy), std::move(texXform), filter, color, mode,
  199. aa, edgeAA, GrQuad::MakeFromSkQuad(dstQuad, viewMatrix),
  200. GrQuad::MakeFromSkQuad(srcQuad, SkMatrix::I()), domain);
  201. }
  202. /** Used with drawTextureSet */
  203. struct TextureSetEntry {
  204. sk_sp<GrTextureProxy> fProxy;
  205. SkRect fSrcRect;
  206. SkRect fDstRect;
  207. const SkPoint* fDstClipQuad; // Must be null, or point to an array of 4 points
  208. const SkMatrix* fPreViewMatrix; // If not null, entry's CTM is 'viewMatrix' * fPreViewMatrix
  209. float fAlpha;
  210. GrQuadAAFlags fAAFlags;
  211. };
  212. /**
  213. * Draws a set of textures with a shared filter, color, view matrix, color xform, and
  214. * texture color xform. The textures must all have the same GrTextureType and GrConfig.
  215. *
  216. * If any entries provide a non-null fDstClip array, it will be read from immediately based on
  217. * fDstClipCount, so the pointer can become invalid after this returns.
  218. */
  219. void drawTextureSet(const GrClip&, const TextureSetEntry[], int cnt, GrSamplerState::Filter,
  220. SkBlendMode mode, GrAA aa, SkCanvas::SrcRectConstraint,
  221. const SkMatrix& viewMatrix, sk_sp<GrColorSpaceXform> texXform);
  222. /**
  223. * Draw a roundrect using a paint.
  224. *
  225. * @param paint describes how to color pixels.
  226. * @param GrAA Controls whether rrect is antialiased.
  227. * @param viewMatrix transformation matrix
  228. * @param rrect the roundrect to draw
  229. * @param style style to apply to the rrect. Currently path effects are not allowed.
  230. */
  231. void drawRRect(const GrClip&,
  232. GrPaint&&,
  233. GrAA,
  234. const SkMatrix& viewMatrix,
  235. const SkRRect& rrect,
  236. const GrStyle& style);
  237. /**
  238. * Use a fast method to render the ambient and spot shadows for a path.
  239. * Will return false if not possible for the given path.
  240. *
  241. * @param viewMatrix transformation matrix
  242. * @param path the path to shadow
  243. * @param rec parameters for shadow rendering
  244. */
  245. bool drawFastShadow(const GrClip&,
  246. const SkMatrix& viewMatrix,
  247. const SkPath& path,
  248. const SkDrawShadowRec& rec);
  249. /**
  250. * Shortcut for filling a SkPath consisting of nested rrects using a paint. The result is
  251. * undefined if outer does not contain inner.
  252. *
  253. * @param paint describes how to color pixels.
  254. * @param GrAA Controls whether rrects edges are antialiased
  255. * @param viewMatrix transformation matrix
  256. * @param outer the outer roundrect
  257. * @param inner the inner roundrect
  258. */
  259. void drawDRRect(const GrClip&,
  260. GrPaint&&,
  261. GrAA,
  262. const SkMatrix& viewMatrix,
  263. const SkRRect& outer,
  264. const SkRRect& inner);
  265. /**
  266. * Draws a path.
  267. *
  268. * @param paint describes how to color pixels.
  269. * @param GrAA Controls whether the path is antialiased.
  270. * @param viewMatrix transformation matrix
  271. * @param path the path to draw
  272. * @param style style to apply to the path.
  273. */
  274. void drawPath(const GrClip&,
  275. GrPaint&&,
  276. GrAA,
  277. const SkMatrix& viewMatrix,
  278. const SkPath&,
  279. const GrStyle&);
  280. /**
  281. * Draws a shape.
  282. *
  283. * @param paint describes how to color pixels.
  284. * @param GrAA Controls whether the path is antialiased.
  285. * @param viewMatrix transformation matrix
  286. * @param shape the shape to draw
  287. */
  288. void drawShape(const GrClip&,
  289. GrPaint&&,
  290. GrAA,
  291. const SkMatrix& viewMatrix,
  292. const GrShape&);
  293. /**
  294. * Draws vertices with a paint.
  295. *
  296. * @param paint describes how to color pixels.
  297. * @param viewMatrix transformation matrix
  298. * @param vertices specifies the mesh to draw.
  299. * @param bones bone deformation matrices.
  300. * @param boneCount number of bone matrices.
  301. * @param overridePrimType primitive type to draw. If NULL, derive prim type from vertices.
  302. */
  303. void drawVertices(const GrClip&,
  304. GrPaint&& paint,
  305. const SkMatrix& viewMatrix,
  306. sk_sp<SkVertices> vertices,
  307. const SkVertices::Bone bones[],
  308. int boneCount,
  309. GrPrimitiveType* overridePrimType = nullptr);
  310. /**
  311. * Draws textured sprites from an atlas with a paint. This currently does not support AA for the
  312. * sprite rectangle edges.
  313. *
  314. * @param paint describes how to color pixels.
  315. * @param viewMatrix transformation matrix
  316. * @param spriteCount number of sprites.
  317. * @param xform array of compressed transformation data, required.
  318. * @param texRect array of texture rectangles used to access the paint.
  319. * @param colors optional array of per-sprite colors, supercedes
  320. * the paint's color field.
  321. */
  322. void drawAtlas(const GrClip&,
  323. GrPaint&& paint,
  324. const SkMatrix& viewMatrix,
  325. int spriteCount,
  326. const SkRSXform xform[],
  327. const SkRect texRect[],
  328. const SkColor colors[]);
  329. /**
  330. * Draws a region.
  331. *
  332. * @param paint describes how to color pixels
  333. * @param viewMatrix transformation matrix
  334. * @param aa should the rects of the region be antialiased.
  335. * @param region the region to be drawn
  336. * @param style style to apply to the region
  337. */
  338. void drawRegion(const GrClip&,
  339. GrPaint&& paint,
  340. GrAA aa,
  341. const SkMatrix& viewMatrix,
  342. const SkRegion& region,
  343. const GrStyle& style,
  344. const GrUserStencilSettings* ss = nullptr);
  345. /**
  346. * Draws an oval.
  347. *
  348. * @param paint describes how to color pixels.
  349. * @param GrAA Controls whether the oval is antialiased.
  350. * @param viewMatrix transformation matrix
  351. * @param oval the bounding rect of the oval.
  352. * @param style style to apply to the oval. Currently path effects are not allowed.
  353. */
  354. void drawOval(const GrClip&,
  355. GrPaint&& paint,
  356. GrAA,
  357. const SkMatrix& viewMatrix,
  358. const SkRect& oval,
  359. const GrStyle& style);
  360. /**
  361. * Draws a partial arc of an oval.
  362. *
  363. * @param paint describes how to color pixels.
  364. * @param GrGrAA Controls whether the arc is antialiased.
  365. * @param viewMatrix transformation matrix.
  366. * @param oval the bounding rect of the oval.
  367. * @param startAngle starting angle in degrees.
  368. * @param sweepAngle angle to sweep in degrees. Must be in (-360, 360)
  369. * @param useCenter true means that the implied path begins at the oval center, connects as
  370. * a line to the point indicated by the start contains the arc indicated by
  371. * the sweep angle. If false the line beginning at the center point is
  372. * omitted.
  373. * @param style style to apply to the oval.
  374. */
  375. void drawArc(const GrClip&,
  376. GrPaint&& paint,
  377. GrAA,
  378. const SkMatrix& viewMatrix,
  379. const SkRect& oval,
  380. SkScalar startAngle,
  381. SkScalar sweepAngle,
  382. bool useCenter,
  383. const GrStyle& style);
  384. /**
  385. * Draw the image as a set of rects, specified by |iter|.
  386. */
  387. void drawImageLattice(const GrClip&,
  388. GrPaint&&,
  389. const SkMatrix& viewMatrix,
  390. sk_sp<GrTextureProxy>,
  391. sk_sp<GrColorSpaceXform>,
  392. GrSamplerState::Filter,
  393. std::unique_ptr<SkLatticeIter>,
  394. const SkRect& dst);
  395. /**
  396. * Draws the src texture with no matrix. The dstRect is the dstPoint with the width and height
  397. * of the srcRect. The srcRect and dstRect are clipped to the bounds of the src and dst surfaces
  398. * respectively.
  399. */
  400. bool blitTexture(GrTextureProxy* src, const SkIRect& srcRect, const SkIPoint& dstPoint);
  401. /**
  402. * Adds the necessary signal and wait semaphores and adds the passed in SkDrawable to the
  403. * command stream.
  404. */
  405. void drawDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler>, const SkRect& bounds);
  406. using ReadPixelsCallback = SkSurface::ReadPixelsCallback;
  407. using ReadPixelsCallbackYUV420 = SkSurface::ReadPixelsCallbackYUV420;
  408. using ReadPixelsContext = SkSurface::ReadPixelsContext;
  409. using RescaleGamma = SkSurface::RescaleGamma;
  410. // GPU implementation for SkSurface::asyncRescaleAndReadPixels.
  411. void asyncRescaleAndReadPixels(const SkImageInfo& info, const SkIRect& srcRect,
  412. RescaleGamma rescaleGamma, SkFilterQuality rescaleQuality,
  413. ReadPixelsCallback callback, ReadPixelsContext context);
  414. // GPU implementation for SkSurface::asyncRescaleAndReadPixelsYUV420.
  415. void asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
  416. sk_sp<SkColorSpace> dstColorSpace, const SkIRect& srcRect,
  417. int dstW, int dstH, RescaleGamma rescaleGamma,
  418. SkFilterQuality rescaleQuality,
  419. ReadPixelsCallbackYUV420 callback,
  420. ReadPixelsContext context);
  421. /**
  422. * After this returns any pending surface IO will be issued to the backend 3D API and
  423. * if the surface has MSAA it will be resolved.
  424. */
  425. GrSemaphoresSubmitted flush(SkSurface::BackendSurfaceAccess access, const GrFlushInfo&);
  426. /**
  427. * The next time this GrRenderTargetContext is flushed, the gpu will wait on the passed in
  428. * semaphores before executing any commands.
  429. */
  430. bool waitOnSemaphores(int numSemaphores, const GrBackendSemaphore waitSemaphores[]);
  431. void insertEventMarker(const SkString&);
  432. const GrCaps* caps() const;
  433. const GrRenderTargetProxy* proxy() const { return fRenderTargetProxy.get(); }
  434. int width() const { return fRenderTargetProxy->width(); }
  435. int height() const { return fRenderTargetProxy->height(); }
  436. int numSamples() const { return fRenderTargetProxy->numSamples(); }
  437. const SkSurfaceProps& surfaceProps() const { return fSurfaceProps; }
  438. GrSurfaceOrigin origin() const { return fRenderTargetProxy->origin(); }
  439. bool wrapsVkSecondaryCB() const { return fRenderTargetProxy->wrapsVkSecondaryCB(); }
  440. GrMipMapped mipMapped() const;
  441. // This entry point should only be called if the backing GPU object is known to be
  442. // instantiated.
  443. GrRenderTarget* accessRenderTarget() { return fRenderTargetProxy->peekRenderTarget(); }
  444. GrSurfaceProxy* asSurfaceProxy() override { return fRenderTargetProxy.get(); }
  445. const GrSurfaceProxy* asSurfaceProxy() const override { return fRenderTargetProxy.get(); }
  446. sk_sp<GrSurfaceProxy> asSurfaceProxyRef() override { return fRenderTargetProxy; }
  447. GrTextureProxy* asTextureProxy() override;
  448. const GrTextureProxy* asTextureProxy() const override;
  449. sk_sp<GrTextureProxy> asTextureProxyRef() override;
  450. GrRenderTargetProxy* asRenderTargetProxy() override { return fRenderTargetProxy.get(); }
  451. sk_sp<GrRenderTargetProxy> asRenderTargetProxyRef() override { return fRenderTargetProxy; }
  452. GrRenderTargetContext* asRenderTargetContext() override { return this; }
  453. // Provides access to functions that aren't part of the public API.
  454. GrRenderTargetContextPriv priv();
  455. const GrRenderTargetContextPriv priv() const;
  456. GrTextTarget* textTarget() { return fTextTarget.get(); }
  457. #if GR_TEST_UTILS
  458. bool testingOnly_IsInstantiated() const { return fRenderTargetProxy->isInstantiated(); }
  459. void testingOnly_SetPreserveOpsOnFullClear() { fPreserveOpsOnFullClear_TestingOnly = true; }
  460. #endif
  461. protected:
  462. GrRenderTargetContext(GrRecordingContext*, sk_sp<GrRenderTargetProxy>, GrColorType,
  463. sk_sp<SkColorSpace>, const SkSurfaceProps*, bool managedOpList = true);
  464. SkDEBUGCODE(void validate() const override;)
  465. private:
  466. class TextTarget;
  467. enum class QuadOptimization;
  468. GrAAType chooseAAType(GrAA);
  469. friend class GrAtlasTextBlob; // for access to add[Mesh]DrawOp
  470. friend class GrClipStackClip; // for access to getOpList
  471. friend class GrDrawingManager; // for ctor
  472. friend class GrRenderTargetContextPriv;
  473. // All the path renderers currently make their own ops
  474. friend class GrSoftwarePathRenderer; // for access to add[Mesh]DrawOp
  475. friend class GrAAConvexPathRenderer; // for access to add[Mesh]DrawOp
  476. friend class GrDashLinePathRenderer; // for access to add[Mesh]DrawOp
  477. friend class GrAAHairLinePathRenderer; // for access to add[Mesh]DrawOp
  478. friend class GrAALinearizingConvexPathRenderer; // for access to add[Mesh]DrawOp
  479. friend class GrSmallPathRenderer; // for access to add[Mesh]DrawOp
  480. friend class GrDefaultPathRenderer; // for access to add[Mesh]DrawOp
  481. friend class GrStencilAndCoverPathRenderer; // for access to add[Mesh]DrawOp
  482. friend class GrTessellatingPathRenderer; // for access to add[Mesh]DrawOp
  483. friend class GrCCPerFlushResources; // for access to addDrawOp
  484. friend class GrCoverageCountingPathRenderer; // for access to addDrawOp
  485. // for a unit test
  486. friend void test_draw_op(GrContext*,
  487. GrRenderTargetContext*,
  488. std::unique_ptr<GrFragmentProcessor>,
  489. sk_sp<GrTextureProxy>);
  490. GrRenderTargetOpList::CanDiscardPreviousOps canDiscardPreviousOpsOnFullClear() const;
  491. void setNeedsStencil(bool multisampled);
  492. void internalClear(const GrFixedClip&, const SkPMColor4f&, CanClearFullscreen);
  493. void internalStencilClear(const GrFixedClip&, bool insideStencilMask);
  494. // Only consumes the GrPaint if successful.
  495. bool drawFilledDRRect(const GrClip& clip,
  496. GrPaint&& paint,
  497. GrAA,
  498. const SkMatrix& viewMatrix,
  499. const SkRRect& origOuter,
  500. const SkRRect& origInner);
  501. // If the drawn quad's paint is a const blended color, provide it as a non-null pointer to
  502. // 'constColor', which enables the draw-as-clear optimization. Otherwise it is assumed the paint
  503. // requires some form of shading that invalidates using a clear op.
  504. //
  505. // The non-const pointers should be the original draw request on input, and will be updated as
  506. // appropriate depending on the returned optimization level.
  507. //
  508. // 'stencilSettings' are provided merely for decision making purposes; When non-null,
  509. // optimization strategies that submit special ops are avoided.
  510. QuadOptimization attemptQuadOptimization(const GrClip& clip,
  511. const SkPMColor4f* constColor,
  512. const GrUserStencilSettings* stencilSettings,
  513. GrAA* aa,
  514. GrQuadAAFlags* edgeFlags,
  515. GrQuad* deviceQuad,
  516. GrQuad* localQuad);
  517. // If stencil settings, 'ss', are non-null, AA controls MSAA or no AA. If they are null, then AA
  518. // can choose between coverage, MSAA as per chooseAAType(). This will always attempt to apply
  519. // quad optimizations, so all quad/rect public APIs should rely on this function for consistent
  520. // clipping behavior.
  521. void drawFilledQuad(const GrClip& clip,
  522. GrPaint&& paint,
  523. GrAA aa,
  524. GrQuadAAFlags edgeFlags,
  525. const GrQuad& deviceQuad,
  526. const GrQuad& localQuad,
  527. const GrUserStencilSettings* ss = nullptr);
  528. // Like drawFilledQuad but does not require using a GrPaint or FP for texturing
  529. void drawTexturedQuad(const GrClip& clip,
  530. sk_sp<GrTextureProxy> proxy,
  531. sk_sp<GrColorSpaceXform> textureXform,
  532. GrSamplerState::Filter filter,
  533. const SkPMColor4f& color,
  534. SkBlendMode blendMode,
  535. GrAA aa,
  536. GrQuadAAFlags edgeFlags,
  537. const GrQuad& deviceQuad,
  538. const GrQuad& localQuad,
  539. const SkRect* domain = nullptr);
  540. void drawShapeUsingPathRenderer(const GrClip&, GrPaint&&, GrAA, const SkMatrix&,
  541. const GrShape&);
  542. // Allows caller of addDrawOp to know which op list an op will be added to.
  543. using WillAddOpFn = void(GrOp*, uint32_t opListID);
  544. // These perform processing specific to GrDrawOp-derived ops before recording them into an
  545. // op list. Before adding the op to an op list the WillAddOpFn is called. Note that it
  546. // will not be called in the event that the op is discarded. Moreover, the op may merge into
  547. // another op after the function is called (either before addDrawOp returns or some time later).
  548. void addDrawOp(const GrClip&, std::unique_ptr<GrDrawOp>,
  549. const std::function<WillAddOpFn>& = std::function<WillAddOpFn>());
  550. // Makes a copy of the proxy if it is necessary for the draw and places the texture that should
  551. // be used by GrXferProcessor to access the destination color in 'result'. If the return
  552. // value is false then a texture copy could not be made.
  553. bool SK_WARN_UNUSED_RESULT setupDstProxy(GrRenderTargetProxy*,
  554. const GrClip&,
  555. const GrOp& op,
  556. GrXferProcessor::DstProxy* result);
  557. // The async read step of asyncRescaleAndReadPixels()
  558. void asyncReadPixels(const SkIRect& rect, SkColorType colorType, ReadPixelsCallback callback,
  559. ReadPixelsContext context);
  560. // Inserts a transfer, part of the implementation of asyncReadPixels and
  561. // asyncRescaleAndReadPixelsYUV420().
  562. struct PixelTransferResult {
  563. using ConversionSignature = void(void* dst, const void* mappedBuffer);
  564. // If null then the transfer could not be performed. Otherwise this buffer will contain
  565. // the pixel data when the transfer is complete.
  566. sk_sp<GrGpuBuffer> fTransferBuffer;
  567. // If this is null then the transfer buffer will contain the data in the requested
  568. // color type. Otherwise, when the transfer is done this must be called to convert
  569. // from the transfer buffer's color type to the requested color type.
  570. std::function<ConversionSignature> fPixelConverter;
  571. };
  572. // Inserts a transfer of rect to a buffer that this call will create.
  573. PixelTransferResult transferPixels(GrColorType colorType, const SkIRect& rect);
  574. GrRenderTargetOpList* getRTOpList();
  575. GrOpList* getOpList() override;
  576. std::unique_ptr<GrTextTarget> fTextTarget;
  577. sk_sp<GrRenderTargetProxy> fRenderTargetProxy;
  578. // In MDB-mode the GrOpList can be closed by some other renderTargetContext that has picked
  579. // it up. For this reason, the GrOpList should only ever be accessed via 'getOpList'.
  580. sk_sp<GrRenderTargetOpList> fOpList;
  581. SkSurfaceProps fSurfaceProps;
  582. bool fManagedOpList;
  583. int fNumStencilSamples = 0;
  584. #if GR_TEST_UTILS
  585. bool fPreserveOpsOnFullClear_TestingOnly = false;
  586. #endif
  587. typedef GrSurfaceContext INHERITED;
  588. };
  589. #endif