2015-05-26 18:38:03 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GrDrawContext_DEFINED
|
|
|
|
#define GrDrawContext_DEFINED
|
|
|
|
|
|
|
|
#include "GrColor.h"
|
2015-12-01 20:51:26 +00:00
|
|
|
#include "GrRenderTarget.h"
|
2015-05-26 18:38:03 +00:00
|
|
|
#include "SkRefCnt.h"
|
2015-06-19 18:49:52 +00:00
|
|
|
#include "SkSurfaceProps.h"
|
2016-01-06 16:26:09 +00:00
|
|
|
#include "../private/GrSingleOwner.h"
|
2015-05-26 18:38:03 +00:00
|
|
|
|
2016-02-16 19:09:25 +00:00
|
|
|
class GrAtlasTextContext;
|
2016-01-13 14:45:40 +00:00
|
|
|
class GrAuditTrail;
|
2015-05-26 18:38:03 +00:00
|
|
|
class GrClip;
|
|
|
|
class GrContext;
|
2015-08-13 20:34:48 +00:00
|
|
|
class GrDrawBatch;
|
2015-12-08 18:20:32 +00:00
|
|
|
class GrDrawPathBatchBase;
|
2015-10-17 14:43:27 +00:00
|
|
|
class GrDrawingManager;
|
2015-05-26 18:38:03 +00:00
|
|
|
class GrDrawTarget;
|
|
|
|
class GrPaint;
|
|
|
|
class GrPathProcessor;
|
|
|
|
class GrPipelineBuilder;
|
|
|
|
class GrRenderTarget;
|
|
|
|
class GrStrokeInfo;
|
|
|
|
class GrSurface;
|
2015-06-17 12:43:33 +00:00
|
|
|
class SkDrawFilter;
|
2015-05-26 18:38:03 +00:00
|
|
|
struct SkIPoint;
|
|
|
|
struct SkIRect;
|
|
|
|
class SkMatrix;
|
2015-06-17 12:43:33 +00:00
|
|
|
class SkPaint;
|
2015-05-26 18:38:03 +00:00
|
|
|
class SkPath;
|
|
|
|
struct SkPoint;
|
|
|
|
struct SkRect;
|
|
|
|
class SkRRect;
|
2015-08-07 17:09:28 +00:00
|
|
|
struct SkRSXform;
|
2015-06-17 12:43:33 +00:00
|
|
|
class SkTextBlob;
|
2015-05-26 18:38:03 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* A helper object to orchestrate draws
|
|
|
|
*/
|
|
|
|
class SK_API GrDrawContext : public SkRefCnt {
|
|
|
|
public:
|
2015-06-17 12:43:33 +00:00
|
|
|
~GrDrawContext() override;
|
|
|
|
|
2016-02-16 15:34:17 +00:00
|
|
|
bool copySurface(GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint);
|
2015-05-26 18:38:03 +00:00
|
|
|
|
2015-06-17 12:43:33 +00:00
|
|
|
// TODO: it is odd that we need both the SkPaint in the following 3 methods.
|
|
|
|
// We should extract the text parameters from SkPaint and pass them separately
|
|
|
|
// akin to GrStrokeInfo (GrTextInfo?)
|
2016-02-16 18:36:53 +00:00
|
|
|
virtual void drawText(const GrClip&, const GrPaint&, const SkPaint&,
|
|
|
|
const SkMatrix& viewMatrix, const char text[], size_t byteLength,
|
|
|
|
SkScalar x, SkScalar y, const SkIRect& clipBounds);
|
|
|
|
virtual void drawPosText(const GrClip&, const GrPaint&, const SkPaint&,
|
|
|
|
const SkMatrix& viewMatrix, const char text[], size_t byteLength,
|
|
|
|
const SkScalar pos[], int scalarsPerPosition,
|
|
|
|
const SkPoint& offset, const SkIRect& clipBounds);
|
|
|
|
virtual void drawTextBlob(const GrClip&, const SkPaint&,
|
|
|
|
const SkMatrix& viewMatrix, const SkTextBlob*,
|
|
|
|
SkScalar x, SkScalar y,
|
|
|
|
SkDrawFilter*, const SkIRect& clipBounds);
|
2015-05-26 18:38:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Provides a perfomance hint that the render target's contents are allowed
|
|
|
|
* to become undefined.
|
|
|
|
*/
|
2015-10-15 15:01:48 +00:00
|
|
|
void discard();
|
2015-05-26 18:38:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear the entire or rect of the render target, ignoring any clips.
|
|
|
|
* @param rect the rect to clear or the whole thing if rect is NULL.
|
|
|
|
* @param color the color to clear to.
|
|
|
|
* @param canIgnoreRect allows partial clears to be converted to whole
|
|
|
|
* clears on platforms for which that is cheap
|
|
|
|
*/
|
2015-10-15 15:01:48 +00:00
|
|
|
void clear(const SkIRect* rect, GrColor color, bool canIgnoreRect);
|
2015-05-26 18:38:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw everywhere (respecting the clip) with the paint.
|
|
|
|
*/
|
2015-10-15 15:01:48 +00:00
|
|
|
void drawPaint(const GrClip&, const GrPaint&, const SkMatrix& viewMatrix);
|
2015-05-26 18:38:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw the rect using a paint.
|
|
|
|
* @param paint describes how to color pixels.
|
|
|
|
* @param viewMatrix transformation matrix
|
|
|
|
* @param strokeInfo the stroke information (width, join, cap), and.
|
|
|
|
* the dash information (intervals, count, phase).
|
|
|
|
* If strokeInfo == NULL, then the rect is filled.
|
|
|
|
* Otherwise, if stroke width == 0, then the stroke
|
|
|
|
* is always a single pixel thick, else the rect is
|
|
|
|
* mitered/beveled stroked based on stroke width.
|
|
|
|
* The rects coords are used to access the paint (through texture matrix)
|
|
|
|
*/
|
2015-10-15 15:01:48 +00:00
|
|
|
void drawRect(const GrClip&,
|
2015-05-26 18:38:03 +00:00
|
|
|
const GrPaint& paint,
|
|
|
|
const SkMatrix& viewMatrix,
|
|
|
|
const SkRect&,
|
2016-02-25 21:43:16 +00:00
|
|
|
const GrStrokeInfo* strokeInfo = NULL);
|
2015-05-26 18:38:03 +00:00
|
|
|
|
|
|
|
/**
|
2015-11-05 18:41:43 +00:00
|
|
|
* Maps a rectangle of shader coordinates to a rectangle and fills that rectangle.
|
2015-05-26 18:38:03 +00:00
|
|
|
*
|
|
|
|
* @param paint describes how to color pixels.
|
|
|
|
* @param viewMatrix transformation matrix which applies to rectToDraw
|
|
|
|
* @param rectToDraw the rectangle to draw
|
|
|
|
* @param localRect the rectangle of shader coordinates applied to rectToDraw
|
|
|
|
*/
|
2015-11-05 18:41:43 +00:00
|
|
|
void fillRectToRect(const GrClip&,
|
|
|
|
const GrPaint& paint,
|
|
|
|
const SkMatrix& viewMatrix,
|
|
|
|
const SkRect& rectToDraw,
|
|
|
|
const SkRect& localRect);
|
2015-05-26 18:38:03 +00:00
|
|
|
|
|
|
|
/**
|
2015-11-05 18:41:43 +00:00
|
|
|
* Fills a rect with a paint and a localMatrix.
|
2015-05-26 18:38:03 +00:00
|
|
|
*/
|
2015-11-05 18:41:43 +00:00
|
|
|
void fillRectWithLocalMatrix(const GrClip& clip,
|
|
|
|
const GrPaint& paint,
|
|
|
|
const SkMatrix& viewMatrix,
|
|
|
|
const SkRect& rect,
|
|
|
|
const SkMatrix& localMatrix);
|
2015-05-26 18:38:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw a roundrect using a paint.
|
|
|
|
*
|
|
|
|
* @param paint describes how to color pixels.
|
|
|
|
* @param viewMatrix transformation matrix
|
|
|
|
* @param rrect the roundrect to draw
|
|
|
|
* @param strokeInfo the stroke information (width, join, cap) and
|
|
|
|
* the dash information (intervals, count, phase).
|
|
|
|
*/
|
2015-10-15 15:01:48 +00:00
|
|
|
void drawRRect(const GrClip&,
|
2015-05-26 18:38:03 +00:00
|
|
|
const GrPaint&,
|
|
|
|
const SkMatrix& viewMatrix,
|
|
|
|
const SkRRect& rrect,
|
|
|
|
const GrStrokeInfo&);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws a path.
|
|
|
|
*
|
|
|
|
* @param paint describes how to color pixels.
|
|
|
|
* @param viewMatrix transformation matrix
|
|
|
|
* @param path the path to draw
|
|
|
|
* @param strokeInfo the stroke information (width, join, cap) and
|
|
|
|
* the dash information (intervals, count, phase).
|
|
|
|
*/
|
2015-10-15 15:01:48 +00:00
|
|
|
void drawPath(const GrClip&,
|
2015-05-26 18:38:03 +00:00
|
|
|
const GrPaint&,
|
|
|
|
const SkMatrix& viewMatrix,
|
|
|
|
const SkPath&,
|
|
|
|
const GrStrokeInfo&);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws vertices with a paint.
|
|
|
|
*
|
|
|
|
* @param paint describes how to color pixels.
|
|
|
|
* @param viewMatrix transformation matrix
|
|
|
|
* @param primitiveType primitives type to draw.
|
|
|
|
* @param vertexCount number of vertices.
|
|
|
|
* @param positions array of vertex positions, required.
|
|
|
|
* @param texCoords optional array of texture coordinates used
|
|
|
|
* to access the paint.
|
|
|
|
* @param colors optional array of per-vertex colors, supercedes
|
|
|
|
* the paint's color field.
|
|
|
|
* @param indices optional array of indices. If NULL vertices
|
|
|
|
* are drawn non-indexed.
|
|
|
|
* @param indexCount if indices is non-null then this is the
|
|
|
|
* number of indices.
|
|
|
|
*/
|
2015-10-15 15:01:48 +00:00
|
|
|
void drawVertices(const GrClip&,
|
2015-05-26 18:38:03 +00:00
|
|
|
const GrPaint& paint,
|
|
|
|
const SkMatrix& viewMatrix,
|
|
|
|
GrPrimitiveType primitiveType,
|
|
|
|
int vertexCount,
|
|
|
|
const SkPoint positions[],
|
|
|
|
const SkPoint texs[],
|
|
|
|
const GrColor colors[],
|
|
|
|
const uint16_t indices[],
|
|
|
|
int indexCount);
|
|
|
|
|
2015-08-07 17:09:28 +00:00
|
|
|
/**
|
|
|
|
* Draws textured sprites from an atlas with a paint.
|
|
|
|
*
|
|
|
|
* @param paint describes how to color pixels.
|
|
|
|
* @param viewMatrix transformation matrix
|
|
|
|
* @param spriteCount number of sprites.
|
|
|
|
* @param xform array of compressed transformation data, required.
|
|
|
|
* @param texRect array of texture rectangles used to access the paint.
|
|
|
|
* @param colors optional array of per-sprite colors, supercedes
|
|
|
|
* the paint's color field.
|
|
|
|
*/
|
2015-10-15 15:01:48 +00:00
|
|
|
void drawAtlas(const GrClip&,
|
2015-08-07 17:09:28 +00:00
|
|
|
const GrPaint& paint,
|
|
|
|
const SkMatrix& viewMatrix,
|
|
|
|
int spriteCount,
|
|
|
|
const SkRSXform xform[],
|
|
|
|
const SkRect texRect[],
|
|
|
|
const SkColor colors[]);
|
|
|
|
|
2015-05-26 18:38:03 +00:00
|
|
|
/**
|
|
|
|
* Draws an oval.
|
|
|
|
*
|
|
|
|
* @param paint describes how to color pixels.
|
|
|
|
* @param viewMatrix transformation matrix
|
|
|
|
* @param oval the bounding rect of the oval.
|
|
|
|
* @param strokeInfo the stroke information (width, join, cap) and
|
|
|
|
* the dash information (intervals, count, phase).
|
|
|
|
*/
|
2015-10-15 15:01:48 +00:00
|
|
|
void drawOval(const GrClip&,
|
2015-05-26 18:38:03 +00:00
|
|
|
const GrPaint& paint,
|
|
|
|
const SkMatrix& viewMatrix,
|
|
|
|
const SkRect& oval,
|
|
|
|
const GrStrokeInfo& strokeInfo);
|
|
|
|
|
2015-11-18 21:28:51 +00:00
|
|
|
/**
|
|
|
|
* Draw the image stretched differentially to fit into dst.
|
|
|
|
* center is a rect within the image, and logically divides the image
|
|
|
|
* into 9 sections (3x3). For example, if the middle pixel of a [5x5]
|
|
|
|
* image is the "center", then the center-rect should be [2, 2, 3, 3].
|
|
|
|
*
|
|
|
|
* If the dst is >= the image size, then...
|
|
|
|
* - The 4 corners are not stretched at all.
|
|
|
|
* - The sides are stretched in only one axis.
|
|
|
|
* - The center is stretched in both axes.
|
|
|
|
* Else, for each axis where dst < image,
|
|
|
|
* - The corners shrink proportionally
|
|
|
|
* - The sides (along the shrink axis) and center are not drawn
|
|
|
|
*/
|
|
|
|
void drawImageNine(const GrClip&,
|
|
|
|
const GrPaint& paint,
|
|
|
|
const SkMatrix& viewMatrix,
|
|
|
|
int imageWidth,
|
|
|
|
int imageHeight,
|
|
|
|
const SkIRect& center,
|
|
|
|
const SkRect& dst);
|
2015-05-26 18:38:03 +00:00
|
|
|
|
2015-08-10 18:59:02 +00:00
|
|
|
/**
|
|
|
|
* Draws a batch
|
|
|
|
*
|
|
|
|
* @param paint describes how to color pixels.
|
|
|
|
* @param batch the batch to draw
|
|
|
|
*/
|
2015-10-15 15:01:48 +00:00
|
|
|
void drawBatch(const GrClip&, const GrPaint&, GrDrawBatch*);
|
2015-08-10 18:59:02 +00:00
|
|
|
|
2015-12-08 18:20:32 +00:00
|
|
|
/**
|
|
|
|
* Draws a path batch. This needs to be separate from drawBatch because we install path stencil
|
|
|
|
* settings late.
|
|
|
|
*
|
|
|
|
* TODO: Figure out a better model that allows us to roll this method into drawBatch.
|
|
|
|
*/
|
|
|
|
void drawPathBatch(const GrPipelineBuilder&, GrDrawPathBatchBase*);
|
|
|
|
|
2015-12-01 20:51:26 +00:00
|
|
|
int width() const { return fRenderTarget->width(); }
|
|
|
|
int height() const { return fRenderTarget->height(); }
|
|
|
|
int numColorSamples() const { return fRenderTarget->numColorSamples(); }
|
|
|
|
|
2015-12-04 14:58:16 +00:00
|
|
|
GrRenderTarget* accessRenderTarget() { return fRenderTarget; }
|
|
|
|
|
2016-01-13 15:47:38 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Functions intended for internal use only.
|
|
|
|
void internal_drawBatch(const GrPipelineBuilder& pipelineBuilder, GrDrawBatch* batch);
|
|
|
|
|
2016-02-16 18:36:53 +00:00
|
|
|
protected:
|
|
|
|
GrDrawContext(GrContext*, GrDrawingManager*, GrRenderTarget*,
|
|
|
|
const SkSurfaceProps* surfaceProps, GrAuditTrail*, GrSingleOwner*);
|
2015-05-26 18:38:03 +00:00
|
|
|
|
2016-02-16 18:36:53 +00:00
|
|
|
GrDrawingManager* drawingManager() { return fDrawingManager; }
|
|
|
|
GrAuditTrail* auditTrail() { return fAuditTrail; }
|
|
|
|
const SkSurfaceProps& surfaceProps() const { return fSurfaceProps; }
|
|
|
|
|
|
|
|
SkDEBUGCODE(GrSingleOwner* singleOwner() { return fSingleOwner; })
|
2015-10-15 15:01:48 +00:00
|
|
|
SkDEBUGCODE(void validate() const;)
|
2015-05-26 18:38:03 +00:00
|
|
|
|
2016-02-16 18:36:53 +00:00
|
|
|
private:
|
|
|
|
friend class GrAtlasTextBlob; // for access to drawBatch
|
|
|
|
friend class GrDrawingManager; // for ctor
|
2015-05-26 18:38:03 +00:00
|
|
|
|
2016-02-25 21:43:16 +00:00
|
|
|
void internalDrawPath(GrPipelineBuilder*,
|
2015-05-26 18:38:03 +00:00
|
|
|
const SkMatrix& viewMatrix,
|
2016-02-25 21:43:16 +00:00
|
|
|
GrColor,
|
|
|
|
bool useAA,
|
|
|
|
const SkPath&,
|
|
|
|
const GrStrokeInfo&);
|
2015-05-26 18:38:03 +00:00
|
|
|
|
2015-06-17 12:43:33 +00:00
|
|
|
// This entry point allows the GrTextContext-derived classes to add their batches to
|
|
|
|
// the drawTarget.
|
2015-08-13 20:34:48 +00:00
|
|
|
void drawBatch(GrPipelineBuilder* pipelineBuilder, GrDrawBatch* batch);
|
2015-06-17 12:43:33 +00:00
|
|
|
|
2015-10-16 16:07:06 +00:00
|
|
|
GrDrawTarget* getDrawTarget();
|
|
|
|
|
2016-02-17 13:40:00 +00:00
|
|
|
GrDrawingManager* fDrawingManager;
|
|
|
|
GrRenderTarget* fRenderTarget;
|
2015-10-16 16:07:06 +00:00
|
|
|
|
|
|
|
// In MDB-mode the drawTarget can be closed by some other drawContext that has picked
|
|
|
|
// it up. For this reason, the drawTarget should only ever be accessed via 'getDrawTarget'.
|
2016-02-17 13:40:00 +00:00
|
|
|
GrDrawTarget* fDrawTarget;
|
|
|
|
SkAutoTDelete<GrAtlasTextContext> fAtlasTextContext;
|
|
|
|
GrContext* fContext;
|
2015-06-17 12:43:33 +00:00
|
|
|
|
2016-02-17 13:40:00 +00:00
|
|
|
SkSurfaceProps fSurfaceProps;
|
|
|
|
GrAuditTrail* fAuditTrail;
|
2016-01-06 16:26:09 +00:00
|
|
|
|
|
|
|
// In debug builds we guard against improper thread handling
|
2016-01-11 16:27:48 +00:00
|
|
|
SkDEBUGCODE(mutable GrSingleOwner* fSingleOwner;)
|
2015-05-26 18:38:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|