Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: src/gpu/SkGpuDevice.h

Issue 933043006: Implement SkBaseDevice snapshot support Base URL: https://skia.googlesource.com/skia.git@skimage-filters-04-snapshot-devices
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkPictureRecord.h ('k') | src/gpu/SkGpuDevice.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2010 Google Inc. 3 * Copyright 2010 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #ifndef SkGpuDevice_DEFINED 9 #ifndef SkGpuDevice_DEFINED
10 #define SkGpuDevice_DEFINED 10 #define SkGpuDevice_DEFINED
11 11
12 #include "SkGr.h" 12 #include "SkGr.h"
13 #include "SkBitmap.h" 13 #include "SkBitmap.h"
14 #include "SkDevice.h" 14 #include "SkDevice.h"
15 #include "SkPicture.h" 15 #include "SkPicture.h"
16 #include "SkRegion.h" 16 #include "SkRegion.h"
17 #include "SkSurface.h" 17 #include "SkSurface.h"
18 #include "GrContext.h" 18 #include "GrContext.h"
19 #include "GrSurfacePriv.h" 19 #include "GrSurfacePriv.h"
20 20
21 struct SkDrawProcs; 21 struct SkDrawProcs;
22 struct GrSkDrawProcs; 22 struct GrSkDrawProcs;
23 23
24 class GrAccelData; 24 class GrAccelData;
25 struct GrCachedLayer; 25 struct GrCachedLayer;
26 class GrTextContext; 26 class GrTextContext;
27 class SkSurface_Gpu;
27 28
28 /** 29 /**
29 * Subclass of SkBaseDevice, which directs all drawing to the GrGpu owned by th e 30 * Subclass of SkBaseDevice, which directs all drawing to the GrGpu owned by th e
30 * canvas. 31 * canvas.
31 */ 32 */
32 class SK_API SkGpuDevice : public SkBaseDevice { 33 class SK_API SkGpuDevice : public SkBaseDevice {
33 public: 34 public:
34 enum Flags { 35 enum Flags {
35 kNeedClear_Flag = 1 << 0, //!< Surface requires an initial clear 36 kNeedClear_Flag = 1 << 0, //!< Surface requires an initial clear
36 }; 37 };
37 38
38 /** 39 /**
39 * Creates an SkGpuDevice from a GrRenderTarget. 40 * Creates an SkGpuDevice from a GrRenderTarget.
40 */ 41 */
41 static SkGpuDevice* Create(GrRenderTarget* target, const SkSurfaceProps*, un signed flags = 0); 42 static SkGpuDevice* Create(GrRenderTarget* target, const SkSurfaceProps*, un signed flags = 0);
42 43
43 /** 44 /**
44 * New device that will create an offscreen renderTarget based on the ImageI nfo and 45 * New device that will create an offscreen renderTarget based on the ImageI nfo and
45 * sampleCount. The Budgeted param controls whether the device's backing sto re counts against 46 * sampleCount. The Budgeted param controls whether the device's backing sto re counts against
46 * the resource cache budget. On failure, returns NULL. 47 * the resource cache budget. On failure, returns NULL.
47 */ 48 */
48 static SkGpuDevice* Create(GrContext*, SkSurface::Budgeted, const SkImageInf o&, 49 static SkGpuDevice* Create(GrContext*, SkSurface::Budgeted, const SkImageInf o&,
49 int sampleCount, const SkSurfaceProps*, unsigned flags = 0); 50 int sampleCount, const SkSurfaceProps*, unsigned flags = 0);
50 51
51 virtual ~SkGpuDevice(); 52 virtual ~SkGpuDevice();
52 53
54 void setSurface(SkSurface_Gpu* surface) {
55 fSurface = surface;
56 }
57
53 SkGpuDevice* cloneDevice(const SkSurfaceProps& props) { 58 SkGpuDevice* cloneDevice(const SkSurfaceProps& props) {
54 SkBaseDevice* dev = this->onCreateDevice(CreateInfo(this->imageInfo(), k Possible_TileUsage, 59 SkBaseDevice* dev = this->onCreateDevice(CreateInfo(this->imageInfo(), k Possible_TileUsage,
55 props.pixelGeometry( )), 60 props.pixelGeometry( )),
56 NULL); 61 NULL);
57 return static_cast<SkGpuDevice*>(dev); 62 return static_cast<SkGpuDevice*>(dev);
58 } 63 }
59 64
60 GrContext* context() const { return fContext; } 65 GrContext* context() const { return fContext; }
61 66
62 // set all pixels to 0 67 // set all pixels to 0
63 void clearAll(); 68 void clearAll();
64 69
65 void replaceRenderTarget(bool shouldRetainContent);
66
67 GrRenderTarget* accessRenderTarget() SK_OVERRIDE; 70 GrRenderTarget* accessRenderTarget() SK_OVERRIDE;
68 71
69 SkImageInfo imageInfo() const SK_OVERRIDE { 72 SkImageInfo imageInfo() const SK_OVERRIDE {
70 return fRenderTarget ? fRenderTarget->surfacePriv().info() : SkImageInfo ::MakeUnknown(); 73 return fRenderTarget ? fRenderTarget->surfacePriv().info() : SkImageInfo ::MakeUnknown();
71 } 74 }
72 75
73 const SkSurfaceProps& surfaceProps() const { return fSurfaceProps; } 76 const SkSurfaceProps& surfaceProps() const { return fSurfaceProps; }
74 77
78 void discard() SK_OVERRIDE;
79 SkImage* newImageSnapshot() SK_OVERRIDE;
80 SkImage* newImageSnapshot(const SkSurfaceProps* props, SkSurface::Budgeted);
81 int getBackendSampleCnt() const { return fRenderTarget->numSamples(); }
82 bool isBackendBudgeted() const;
83
75 void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE; 84 void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE;
76 virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t coun t, 85 virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t coun t,
77 const SkPoint[], const SkPaint& paint) SK_OVERRIDE; 86 const SkPoint[], const SkPaint& paint) SK_OVERRIDE;
78 virtual void drawRect(const SkDraw&, const SkRect& r, 87 virtual void drawRect(const SkDraw&, const SkRect& r,
79 const SkPaint& paint) SK_OVERRIDE; 88 const SkPaint& paint) SK_OVERRIDE;
80 virtual void drawRRect(const SkDraw&, const SkRRect& r, 89 virtual void drawRRect(const SkDraw&, const SkRRect& r,
81 const SkPaint& paint) SK_OVERRIDE; 90 const SkPaint& paint) SK_OVERRIDE;
82 virtual void drawDRRect(const SkDraw& draw, const SkRRect& outer, 91 virtual void drawDRRect(const SkDraw& draw, const SkRRect& outer,
83 const SkRRect& inner, const SkPaint& paint) SK_OVERR IDE; 92 const SkRRect& inner, const SkPaint& paint) SK_OVERR IDE;
84 virtual void drawOval(const SkDraw&, const SkRect& oval, 93 virtual void drawOval(const SkDraw&, const SkRect& oval,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 GrSkDrawProcs* fDrawProcs; 148 GrSkDrawProcs* fDrawProcs;
140 SkAutoTUnref<const SkClipStack> fClipStack; 149 SkAutoTUnref<const SkClipStack> fClipStack;
141 SkIPoint fClipOrigin; 150 SkIPoint fClipOrigin;
142 GrClip fClip; 151 GrClip fClip;
143 GrTextContext* fTextContext; 152 GrTextContext* fTextContext;
144 SkSurfaceProps fSurfaceProps; 153 SkSurfaceProps fSurfaceProps;
145 GrRenderTarget* fRenderTarget; 154 GrRenderTarget* fRenderTarget;
146 // remove when our clients don't rely on accessBitmap() 155 // remove when our clients don't rely on accessBitmap()
147 SkBitmap fLegacyBitmap; 156 SkBitmap fLegacyBitmap;
148 bool fNeedClear; 157 bool fNeedClear;
158 SkSurface_Gpu* fSurface;
159 SkAutoTUnref<SkImage> fSnapshot;
149 160
150 SkGpuDevice(GrRenderTarget*, const SkSurfaceProps*, unsigned flags); 161 SkGpuDevice(GrRenderTarget*, const SkSurfaceProps*, unsigned flags);
151 162
152 SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) SK_OVERRIDE; 163 SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) SK_OVERRIDE;
153 164
154 SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) SK_OVERRIDE ; 165 SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) SK_OVERRIDE ;
155 166
156 SkImageFilter::Cache* getImageFilterCache() SK_OVERRIDE; 167 SkImageFilter::Cache* getImageFilterCache() SK_OVERRIDE;
157 168
158 bool forceConservativeRasterClip() const SK_OVERRIDE { return true; } 169 bool forceConservativeRasterClip() const SK_OVERRIDE { return true; }
159 170
160 // sets the render target and clip on context 171 /* Prepares the device for modification and sets the clip on context.
161 void prepareDraw(const SkDraw&); 172 * returns true if the draw can proceed. */
173 bool prepareDraw(const SkDraw&);
174
175 /* Prepares the device for modification.
176 * returns true if the draw can proceed. */
177 bool prepareWrite();
178
179 enum ModifyMode { kDrawContent_ModifyMode, kDiscard_ModifyMode };
180 /** Prepares the render target for modification.
181 * 1. Detaches the snapshot, if needed.
182 * 2. Creates new render target if snapshot refers to the current render tar get.
183 * 3. Does the deferred clear, if needed.
184 * returns true if the render target is functional and can be rendered to.
185 */
186 bool prepareBackendRenderTarget(ModifyMode);
162 187
163 /** 188 /**
164 * Implementation for both drawBitmap and drawBitmapRect. 189 * Implementation for both drawBitmap and drawBitmapRect.
165 */ 190 */
166 void drawBitmapCommon(const SkDraw&, 191 void drawBitmapCommon(const SkDraw&,
167 const SkBitmap& bitmap, 192 const SkBitmap& bitmap,
168 const SkRect* srcRectPtr, 193 const SkRect* srcRectPtr,
169 const SkSize* dstSizePtr, // ignored iff srcRectP tr == NULL 194 const SkSize* dstSizePtr, // ignored iff srcRectP tr == NULL
170 const SkPaint&, 195 const SkPaint&,
171 SkCanvas::DrawBitmapRectFlags flags); 196 SkCanvas::DrawBitmapRectFlags flags);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 static SkPicture::AccelData::Key ComputeAccelDataKey(); 238 static SkPicture::AccelData::Key ComputeAccelDataKey();
214 239
215 static GrRenderTarget* CreateRenderTarget(GrContext*, SkSurface::Budgeted, c onst SkImageInfo&, 240 static GrRenderTarget* CreateRenderTarget(GrContext*, SkSurface::Budgeted, c onst SkImageInfo&,
216 int sampleCount); 241 int sampleCount);
217 242
218 friend class GrTextContext; 243 friend class GrTextContext;
219 typedef SkBaseDevice INHERITED; 244 typedef SkBaseDevice INHERITED;
220 }; 245 };
221 246
222 #endif 247 #endif
OLDNEW
« no previous file with comments | « src/core/SkPictureRecord.h ('k') | src/gpu/SkGpuDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698