| OLD | NEW |
| (Empty) |
| 1 | |
| 2 /* | |
| 3 * Copyright 2010 Google Inc. | |
| 4 * | |
| 5 * Use of this source code is governed by a BSD-style license that can be | |
| 6 * found in the LICENSE file. | |
| 7 */ | |
| 8 | |
| 9 | |
| 10 | |
| 11 #ifndef SkGpuDevice_DEFINED | |
| 12 #define SkGpuDevice_DEFINED | |
| 13 | |
| 14 #include "SkGr.h" | |
| 15 #include "SkBitmap.h" | |
| 16 #include "SkDevice.h" | |
| 17 #include "SkPicture.h" | |
| 18 #include "SkRegion.h" | |
| 19 #include "GrContext.h" | |
| 20 | |
| 21 struct SkDrawProcs; | |
| 22 struct GrSkDrawProcs; | |
| 23 | |
| 24 class GrAccelData; | |
| 25 struct GrCachedLayer; | |
| 26 class GrTextContext; | |
| 27 | |
| 28 /** | |
| 29 * Subclass of SkBaseDevice, which directs all drawing to the GrGpu owned by th
e | |
| 30 * canvas. | |
| 31 */ | |
| 32 class SK_API SkGpuDevice : public SkBaseDevice { | |
| 33 public: | |
| 34 enum Flags { | |
| 35 kNeedClear_Flag = 1 << 0, //!< Surface requires an initial clear | |
| 36 kCached_Flag = 1 << 1, //!< Surface is cached and needs to be unlock
ed when released | |
| 37 kDFFonts_Flag = 1 << 2, //!< Surface should render fonts using signed
distance fields | |
| 38 }; | |
| 39 | |
| 40 /** | |
| 41 * Creates an SkGpuDevice from a GrSurface. This will fail if the surface is
not a render | |
| 42 * target. The caller owns a ref on the returned device. If the surface is c
ached, | |
| 43 * the kCached_Flag should be specified to make the device responsible for u
nlocking | |
| 44 * the surface when it is released. | |
| 45 */ | |
| 46 static SkGpuDevice* Create(GrSurface* surface, unsigned flags = 0); | |
| 47 | |
| 48 /** | |
| 49 * New device that will create an offscreen renderTarget based on the | |
| 50 * ImageInfo and sampleCount. The device's storage will not | |
| 51 * count against the GrContext's texture cache budget. The device's pixels | |
| 52 * will be uninitialized. On failure, returns NULL. | |
| 53 */ | |
| 54 static SkGpuDevice* Create(GrContext*, const SkImageInfo&, int sampleCount); | |
| 55 | |
| 56 virtual ~SkGpuDevice(); | |
| 57 | |
| 58 GrContext* context() const { return fContext; } | |
| 59 | |
| 60 virtual GrRenderTarget* accessRenderTarget() SK_OVERRIDE; | |
| 61 | |
| 62 virtual SkImageInfo imageInfo() const SK_OVERRIDE { | |
| 63 return fRenderTarget ? fRenderTarget->info() : SkImageInfo::MakeUnknown(
); | |
| 64 } | |
| 65 | |
| 66 virtual void clear(SkColor color) SK_OVERRIDE; | |
| 67 virtual void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE; | |
| 68 virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t coun
t, | |
| 69 const SkPoint[], const SkPaint& paint) SK_OVERRIDE; | |
| 70 virtual void drawRect(const SkDraw&, const SkRect& r, | |
| 71 const SkPaint& paint) SK_OVERRIDE; | |
| 72 virtual void drawRRect(const SkDraw&, const SkRRect& r, | |
| 73 const SkPaint& paint) SK_OVERRIDE; | |
| 74 virtual void drawDRRect(const SkDraw& draw, const SkRRect& outer, | |
| 75 const SkRRect& inner, const SkPaint& paint) SK_OVERR
IDE; | |
| 76 virtual void drawOval(const SkDraw&, const SkRect& oval, | |
| 77 const SkPaint& paint) SK_OVERRIDE; | |
| 78 virtual void drawPath(const SkDraw&, const SkPath& path, | |
| 79 const SkPaint& paint, const SkMatrix* prePathMatrix, | |
| 80 bool pathIsMutable) SK_OVERRIDE; | |
| 81 virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap, | |
| 82 const SkMatrix&, const SkPaint&) SK_OVERRIDE; | |
| 83 virtual void drawBitmapRect(const SkDraw&, const SkBitmap&, | |
| 84 const SkRect* srcOrNull, const SkRect& dst, | |
| 85 const SkPaint& paint, | |
| 86 SkCanvas::DrawBitmapRectFlags flags) SK_OVERRIDE
; | |
| 87 virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap, | |
| 88 int x, int y, const SkPaint& paint); | |
| 89 virtual void drawText(const SkDraw&, const void* text, size_t len, | |
| 90 SkScalar x, SkScalar y, const SkPaint&) SK_OVERRIDE; | |
| 91 virtual void drawPosText(const SkDraw&, const void* text, size_t len, | |
| 92 const SkScalar pos[], SkScalar constY, | |
| 93 int scalarsPerPos, const SkPaint&) SK_OVERRIDE; | |
| 94 virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len, | |
| 95 const SkPath& path, const SkMatrix* matrix, | |
| 96 const SkPaint&) SK_OVERRIDE; | |
| 97 virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCou
nt, | |
| 98 const SkPoint verts[], const SkPoint texs[], | |
| 99 const SkColor colors[], SkXfermode* xmode, | |
| 100 const uint16_t indices[], int indexCount, | |
| 101 const SkPaint&) SK_OVERRIDE; | |
| 102 virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, | |
| 103 const SkPaint&) SK_OVERRIDE; | |
| 104 virtual bool filterTextFlags(const SkPaint&, TextFlags*) SK_OVERRIDE; | |
| 105 | |
| 106 virtual void flush() SK_OVERRIDE; | |
| 107 | |
| 108 virtual void onAttachToCanvas(SkCanvas* canvas) SK_OVERRIDE; | |
| 109 virtual void onDetachFromCanvas() SK_OVERRIDE; | |
| 110 | |
| 111 virtual const SkBitmap& onAccessBitmap() SK_OVERRIDE; | |
| 112 | |
| 113 virtual bool canHandleImageFilter(const SkImageFilter*) SK_OVERRIDE; | |
| 114 virtual bool filterImage(const SkImageFilter*, const SkBitmap&, | |
| 115 const SkImageFilter::Context&, | |
| 116 SkBitmap*, SkIPoint*) SK_OVERRIDE; | |
| 117 | |
| 118 class SkAutoCachedTexture; // used internally | |
| 119 | |
| 120 | |
| 121 protected: | |
| 122 virtual bool onReadPixels(const SkImageInfo&, void*, size_t, int, int) SK_OV
ERRIDE; | |
| 123 virtual bool onWritePixels(const SkImageInfo&, const void*, size_t, int, int
) SK_OVERRIDE; | |
| 124 | |
| 125 /** PRIVATE / EXPERIMENTAL -- do not call */ | |
| 126 virtual void EXPERIMENTAL_optimize(const SkPicture* picture) SK_OVERRIDE; | |
| 127 /** PRIVATE / EXPERIMENTAL -- do not call */ | |
| 128 virtual bool EXPERIMENTAL_drawPicture(SkCanvas* canvas, const SkPicture* pic
ture, | |
| 129 const SkMatrix*, const SkPaint*) SK_OV
ERRIDE; | |
| 130 | |
| 131 private: | |
| 132 GrContext* fContext; | |
| 133 | |
| 134 GrSkDrawProcs* fDrawProcs; | |
| 135 | |
| 136 GrClipData fClipData; | |
| 137 | |
| 138 GrTextContext* fMainTextContext; | |
| 139 GrTextContext* fFallbackTextContext; | |
| 140 | |
| 141 // state for our render-target | |
| 142 GrRenderTarget* fRenderTarget; | |
| 143 bool fNeedClear; | |
| 144 | |
| 145 // remove when our clients don't rely on accessBitmap() | |
| 146 SkBitmap fLegacyBitmap; | |
| 147 | |
| 148 SkGpuDevice(GrSurface*, unsigned flags = 0); | |
| 149 | |
| 150 virtual SkBaseDevice* onCreateDevice(const SkImageInfo&, Usage) SK_OVERRIDE; | |
| 151 | |
| 152 virtual SkSurface* newSurface(const SkImageInfo&) SK_OVERRIDE; | |
| 153 | |
| 154 virtual SkImageFilter::Cache* getImageFilterCache() SK_OVERRIDE; | |
| 155 | |
| 156 // temporarily change the return to false, until we understand the issues wi
th filters and persp | |
| 157 virtual bool forceConservativeRasterClip() const SK_OVERRIDE { return false;
} | |
| 158 | |
| 159 // sets the render target, clip, and matrix on GrContext. Use forceIdenity t
o override | |
| 160 // SkDraw's matrix and draw in device coords. | |
| 161 void prepareDraw(const SkDraw&, bool forceIdentity); | |
| 162 | |
| 163 /** | |
| 164 * Implementation for both drawBitmap and drawBitmapRect. | |
| 165 */ | |
| 166 void drawBitmapCommon(const SkDraw&, | |
| 167 const SkBitmap& bitmap, | |
| 168 const SkRect* srcRectPtr, | |
| 169 const SkSize* dstSizePtr, // ignored iff srcRectP
tr == NULL | |
| 170 const SkPaint&, | |
| 171 SkCanvas::DrawBitmapRectFlags flags); | |
| 172 | |
| 173 /** | |
| 174 * Helper functions called by drawBitmapCommon. By the time these are called
the SkDraw's | |
| 175 * matrix, clip, and the device's render target has already been set on GrCo
ntext. | |
| 176 */ | |
| 177 | |
| 178 // The tileSize and clippedSrcRect will be valid only if true is returned. | |
| 179 bool shouldTileBitmap(const SkBitmap& bitmap, | |
| 180 const GrTextureParams& sampler, | |
| 181 const SkRect* srcRectPtr, | |
| 182 int maxTileSize, | |
| 183 int* tileSize, | |
| 184 SkIRect* clippedSrcRect) const; | |
| 185 void internalDrawBitmap(const SkBitmap&, | |
| 186 const SkRect&, | |
| 187 const GrTextureParams& params, | |
| 188 const SkPaint& paint, | |
| 189 SkCanvas::DrawBitmapRectFlags flags, | |
| 190 bool bicubic, | |
| 191 bool needsTextureDomain); | |
| 192 void drawTiledBitmap(const SkBitmap& bitmap, | |
| 193 const SkRect& srcRect, | |
| 194 const SkIRect& clippedSrcRect, | |
| 195 const GrTextureParams& params, | |
| 196 const SkPaint& paint, | |
| 197 SkCanvas::DrawBitmapRectFlags flags, | |
| 198 int tileSize, | |
| 199 bool bicubic); | |
| 200 | |
| 201 bool drawDashLine(const SkPoint pts[2], const SkPaint& paint); | |
| 202 | |
| 203 static SkPicture::AccelData::Key ComputeAccelDataKey(); | |
| 204 | |
| 205 typedef SkBaseDevice INHERITED; | |
| 206 }; | |
| 207 | |
| 208 #endif | |
| OLD | NEW |