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

Side by Side Diff: include/gpu/GrContext.h

Issue 1151283004: Split drawing functionality out of GrContext and into new GrDrawContext (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix no-GPU builds Created 5 years, 7 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 | « gyp/gpu.gypi ('k') | include/gpu/GrDrawContext.h » ('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 * Copyright 2010 Google Inc. 2 * Copyright 2010 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef GrContext_DEFINED 8 #ifndef GrContext_DEFINED
9 #define GrContext_DEFINED 9 #define GrContext_DEFINED
10 10
11 #include "GrClip.h" 11 #include "GrClip.h"
12 #include "GrColor.h" 12 #include "GrColor.h"
13 #include "GrPaint.h" 13 #include "GrPaint.h"
14 #include "GrPathRendererChain.h" 14 #include "GrPathRendererChain.h"
15 #include "GrRenderTarget.h" 15 #include "GrRenderTarget.h"
16 #include "GrTextureProvider.h" 16 #include "GrTextureProvider.h"
17 #include "SkMatrix.h" 17 #include "SkMatrix.h"
18 #include "SkPathEffect.h" 18 #include "SkPathEffect.h"
19 #include "SkTypes.h" 19 #include "SkTypes.h"
20 20
21 class GrAARectRenderer; 21 class GrAARectRenderer;
22 class GrBatchFontCache; 22 class GrBatchFontCache;
23 struct GrContextOptions; 23 struct GrContextOptions;
24 class GrDrawContext;
24 class GrDrawTarget; 25 class GrDrawTarget;
25 class GrFragmentProcessor; 26 class GrFragmentProcessor;
26 class GrGpu; 27 class GrGpu;
27 class GrGpuTraceMarker; 28 class GrGpuTraceMarker;
28 class GrIndexBuffer; 29 class GrIndexBuffer;
29 class GrLayerCache; 30 class GrLayerCache;
30 class GrOvalRenderer; 31 class GrOvalRenderer;
31 class GrPath; 32 class GrPath;
32 class GrPathRenderer; 33 class GrPathRenderer;
33 class GrPipelineBuilder; 34 class GrPipelineBuilder;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 * Purge all the unlocked resources from the cache. 152 * Purge all the unlocked resources from the cache.
152 * This entry point is mainly meant for timing texture uploads 153 * This entry point is mainly meant for timing texture uploads
153 * and is not defined in normal builds of Skia. 154 * and is not defined in normal builds of Skia.
154 */ 155 */
155 void purgeAllUnlockedResources(); 156 void purgeAllUnlockedResources();
156 157
157 ////////////////////////////////////////////////////////////////////////// 158 //////////////////////////////////////////////////////////////////////////
158 /// Texture and Render Target Queries 159 /// Texture and Render Target Queries
159 160
160 /** 161 /**
162 * Are shader derivatives supported?
163 */
164 bool shaderDerivativeSupport() const;
165
166 /**
161 * Can the provided configuration act as a texture? 167 * Can the provided configuration act as a texture?
162 */ 168 */
163 bool isConfigTexturable(GrPixelConfig) const; 169 bool isConfigTexturable(GrPixelConfig) const;
164 170
165 /** 171 /**
166 * Can non-power-of-two textures be used with tile modes other than clamp? 172 * Can non-power-of-two textures be used with tile modes other than clamp?
167 */ 173 */
168 bool npotTextureTileSupport() const; 174 bool npotTextureTileSupport() const;
169 175
170 /** 176 /**
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 * 210 *
205 * @param config the configuration of the render target. 211 * @param config the configuration of the render target.
206 * @param dpi the display density in dots per inch. 212 * @param dpi the display density in dots per inch.
207 * 213 *
208 * @return sample count that should be perform well and have good enough 214 * @return sample count that should be perform well and have good enough
209 * rendering quality for the display. Alternatively returns 0 if 215 * rendering quality for the display. Alternatively returns 0 if
210 * MSAA is not supported or recommended to be used by default. 216 * MSAA is not supported or recommended to be used by default.
211 */ 217 */
212 int getRecommendedSampleCount(GrPixelConfig config, SkScalar dpi) const; 218 int getRecommendedSampleCount(GrPixelConfig config, SkScalar dpi) const;
213 219
214 ///////////////////////////////////////////////////////////////////////////
215 // Draws
216
217 /** 220 /**
218 * Clear the entire or rect of the render target, ignoring any clips. 221 * Returns a helper object to orchestrate draws.
219 * @param rect the rect to clear or the whole thing if rect is NULL. 222 *
220 * @param color the color to clear to. 223 * @return a draw context
221 * @param canIgnoreRect allows partial clears to be converted to whole
222 * clears on platforms for which that is cheap
223 * @param target The render target to clear.
224 */ 224 */
225 void clear(const SkIRect* rect, GrColor color, bool canIgnoreRect, GrRenderT arget* target); 225 GrDrawContext* drawContext() {
226 226 return fDrawingMgr.drawContext();
227 /**
228 * Draw everywhere (respecting the clip) with the paint.
229 */
230 void drawPaint(GrRenderTarget*, const GrClip&, const GrPaint&, const SkMatri x& viewMatrix);
231
232 /**
233 * Draw the rect using a paint.
234 * @param paint describes how to color pixels.
235 * @param viewMatrix transformation matrix
236 * @param strokeInfo the stroke information (width, join, cap), and.
237 * the dash information (intervals, count, phase).
238 * If strokeInfo == NULL, then the rect is filled.
239 * Otherwise, if stroke width == 0, then the stroke
240 * is always a single pixel thick, else the rect is
241 * mitered/beveled stroked based on stroke width.
242 * The rects coords are used to access the paint (through texture matrix)
243 */
244 void drawRect(GrRenderTarget*,
245 const GrClip&,
246 const GrPaint& paint,
247 const SkMatrix& viewMatrix,
248 const SkRect&,
249 const GrStrokeInfo* strokeInfo = NULL);
250
251 /**
252 * Maps a rectangle of shader coordinates to a rectangle and draws that rect angle
253 *
254 * @param paint describes how to color pixels.
255 * @param viewMatrix transformation matrix which applies to rectToDraw
256 * @param rectToDraw the rectangle to draw
257 * @param localRect the rectangle of shader coordinates applied to rectT oDraw
258 * @param localMatrix an optional matrix to transform the shader coordinat es before applying
259 * to rectToDraw
260 */
261 void drawNonAARectToRect(GrRenderTarget*,
262 const GrClip&,
263 const GrPaint& paint,
264 const SkMatrix& viewMatrix,
265 const SkRect& rectToDraw,
266 const SkRect& localRect,
267 const SkMatrix* localMatrix = NULL);
268
269 /**
270 * Draws a non-AA rect with paint and a localMatrix
271 */
272 void drawNonAARectWithLocalMatrix(GrRenderTarget* rt,
273 const GrClip& clip,
274 const GrPaint& paint,
275 const SkMatrix& viewMatrix,
276 const SkRect& rect,
277 const SkMatrix& localMatrix) {
278 this->drawNonAARectToRect(rt, clip, paint, viewMatrix, rect, rect, &loca lMatrix);
279 } 227 }
280 228
281 /**
282 * Draw a roundrect using a paint.
283 *
284 * @param paint describes how to color pixels.
285 * @param viewMatrix transformation matrix
286 * @param rrect the roundrect to draw
287 * @param strokeInfo the stroke information (width, join, cap) and
288 * the dash information (intervals, count, phase).
289 */
290 void drawRRect(GrRenderTarget*,
291 const GrClip&,
292 const GrPaint&,
293 const SkMatrix& viewMatrix,
294 const SkRRect& rrect,
295 const GrStrokeInfo&);
296
297 /**
298 * Shortcut for drawing an SkPath consisting of nested rrects using a paint .
299 * Does not support stroking. The result is undefined if outer does not con tain
300 * inner.
301 *
302 * @param paint describes how to color pixels.
303 * @param viewMatrix transformation matrix
304 * @param outer the outer roundrect
305 * @param inner the inner roundrect
306 */
307 void drawDRRect(GrRenderTarget*,
308 const GrClip&,
309 const GrPaint&,
310 const SkMatrix& viewMatrix,
311 const SkRRect& outer,
312 const SkRRect& inner);
313
314
315 /**
316 * Draws a path.
317 *
318 * @param paint describes how to color pixels.
319 * @param viewMatrix transformation matrix
320 * @param path the path to draw
321 * @param strokeInfo the stroke information (width, join, cap) and
322 * the dash information (intervals, count, phase).
323 */
324 void drawPath(GrRenderTarget*,
325 const GrClip&,
326 const GrPaint&,
327 const SkMatrix& viewMatrix,
328 const SkPath&,
329 const GrStrokeInfo&);
330
331 /**
332 * Draws vertices with a paint.
333 *
334 * @param paint describes how to color pixels.
335 * @param viewMatrix transformation matrix
336 * @param primitiveType primitives type to draw.
337 * @param vertexCount number of vertices.
338 * @param positions array of vertex positions, required.
339 * @param texCoords optional array of texture coordinates used
340 * to access the paint.
341 * @param colors optional array of per-vertex colors, supercedes
342 * the paint's color field.
343 * @param indices optional array of indices. If NULL vertices
344 * are drawn non-indexed.
345 * @param indexCount if indices is non-null then this is the
346 * number of indices.
347 */
348 void drawVertices(GrRenderTarget*,
349 const GrClip&,
350 const GrPaint& paint,
351 const SkMatrix& viewMatrix,
352 GrPrimitiveType primitiveType,
353 int vertexCount,
354 const SkPoint positions[],
355 const SkPoint texs[],
356 const GrColor colors[],
357 const uint16_t indices[],
358 int indexCount);
359
360 /**
361 * Draws an oval.
362 *
363 * @param paint describes how to color pixels.
364 * @param viewMatrix transformation matrix
365 * @param oval the bounding rect of the oval.
366 * @param strokeInfo the stroke information (width, join, cap) and
367 * the dash information (intervals, count, phase).
368 */
369 void drawOval(GrRenderTarget*,
370 const GrClip&,
371 const GrPaint& paint,
372 const SkMatrix& viewMatrix,
373 const SkRect& oval,
374 const GrStrokeInfo& strokeInfo);
375
376 /////////////////////////////////////////////////////////////////////////// 229 ///////////////////////////////////////////////////////////////////////////
377 // Misc. 230 // Misc.
378 231
379 /** 232 /**
380 * Flags that affect flush() behavior. 233 * Flags that affect flush() behavior.
381 */ 234 */
382 enum FlushBits { 235 enum FlushBits {
383 /** 236 /**
384 * A client may reach a point where it has partially rendered a frame 237 * A client may reach a point where it has partially rendered a frame
385 * through a GrContext that it knows the user will never see. This flag 238 * through a GrContext that it knows the user will never see. This flag
386 * causes the flush to skip submission of deferred content to the 3D API 239 * causes the flush to skip submission of deferred content to the 3D API
387 * during the flush. 240 * during the flush.
388 */ 241 */
389 kDiscard_FlushBit = 0x2, 242 kDiscard_FlushBit = 0x2,
390 }; 243 };
391 244
392 /** 245 /**
393 * Call to ensure all drawing to the context has been issued to the 246 * Call to ensure all drawing to the context has been issued to the
394 * underlying 3D API. 247 * underlying 3D API.
395 * @param flagsBitfield flags that control the flushing behavior. See 248 * @param flagsBitfield flags that control the flushing behavior. See
396 * FlushBits. 249 * FlushBits.
397 */ 250 */
398 void flush(int flagsBitfield = 0); 251 void flush(int flagsBitfield = 0);
399 252
253 void flushIfNecessary() {
254 if (fFlushToReduceCacheSize) {
255 this->flush();
256 }
257 }
258
400 /** 259 /**
401 * These flags can be used with the read/write pixels functions below. 260 * These flags can be used with the read/write pixels functions below.
402 */ 261 */
403 enum PixelOpsFlags { 262 enum PixelOpsFlags {
404 /** The GrContext will not be flushed before the surface read or write. This means that 263 /** The GrContext will not be flushed before the surface read or write. This means that
405 the read or write may occur before previous draws have executed. */ 264 the read or write may occur before previous draws have executed. */
406 kDontFlush_PixelOpsFlag = 0x1, 265 kDontFlush_PixelOpsFlag = 0x1,
407 /** Any surface writes should be flushed to the backend 3D API after the surface operation 266 /** Any surface writes should be flushed to the backend 3D API after the surface operation
408 is complete */ 267 is complete */
409 kFlushWrites_PixelOp = 0x2, 268 kFlushWrites_PixelOp = 0x2,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 * used to make the surface contents available to be read in the backend 3D API, usually for a 352 * used to make the surface contents available to be read in the backend 3D API, usually for a
494 * compositing step external to Skia. 353 * compositing step external to Skia.
495 * 354 *
496 * It is not necessary to call this before reading the render target via Ski a/GrContext. 355 * It is not necessary to call this before reading the render target via Ski a/GrContext.
497 * GrContext will detect when it must perform a resolve before reading pixel s back from the 356 * GrContext will detect when it must perform a resolve before reading pixel s back from the
498 * surface or using it as a texture. 357 * surface or using it as a texture.
499 */ 358 */
500 void prepareSurfaceForExternalRead(GrSurface*); 359 void prepareSurfaceForExternalRead(GrSurface*);
501 360
502 /** 361 /**
503 * Provides a perfomance hint that the render target's contents are allowed
504 * to become undefined.
505 */
506 void discardRenderTarget(GrRenderTarget*);
507
508 /**
509 * An ID associated with this context, guaranteed to be unique. 362 * An ID associated with this context, guaranteed to be unique.
510 */ 363 */
511 uint32_t uniqueID() { return fUniqueID; } 364 uint32_t uniqueID() { return fUniqueID; }
512 365
513 /////////////////////////////////////////////////////////////////////////// 366 ///////////////////////////////////////////////////////////////////////////
514 // Functions intended for internal use only. 367 // Functions intended for internal use only.
515 GrGpu* getGpu() { return fGpu; } 368 GrGpu* getGpu() { return fGpu; }
516 const GrGpu* getGpu() const { return fGpu; } 369 const GrGpu* getGpu() const { return fGpu; }
517 GrBatchFontCache* getBatchFontCache() { return fBatchFontCache; } 370 GrBatchFontCache* getBatchFontCache() { return fBatchFontCache; }
518 GrLayerCache* getLayerCache() { return fLayerCache.get(); } 371 GrLayerCache* getLayerCache() { return fLayerCache.get(); }
519 GrTextBlobCache* getTextBlobCache() { return fTextBlobCache; } 372 GrTextBlobCache* getTextBlobCache() { return fTextBlobCache; }
520 GrDrawTarget* getTextTarget(); 373 bool abandoned() const { return fDrawingMgr.abandoned(); }
521 GrAARectRenderer* getAARectRenderer() { return fAARectRenderer; }
522 GrResourceProvider* resourceProvider() { return fResourceProvider; } 374 GrResourceProvider* resourceProvider() { return fResourceProvider; }
523 const GrResourceProvider* resourceProvider() const { return fResourceProvide r; } 375 const GrResourceProvider* resourceProvider() const { return fResourceProvide r; }
524 GrResourceCache* getResourceCache() { return fResourceCache; } 376 GrResourceCache* getResourceCache() { return fResourceCache; }
525 377
526 // Called by tests that draw directly to the context via GrDrawTarget 378 // Called by tests that draw directly to the context via GrDrawTarget
527 void getTestTarget(GrTestTarget*); 379 void getTestTarget(GrTestTarget*);
528 380
529 void addGpuTraceMarker(const GrGpuTraceMarker* marker); 381 void addGpuTraceMarker(const GrGpuTraceMarker* marker);
530 void removeGpuTraceMarker(const GrGpuTraceMarker* marker); 382 void removeGpuTraceMarker(const GrGpuTraceMarker* marker);
531 383
(...skipping 25 matching lines...) Expand all
557 GrTextureProvider* fTextureProvider; 409 GrTextureProvider* fTextureProvider;
558 }; 410 };
559 411
560 GrBatchFontCache* fBatchFontCache; 412 GrBatchFontCache* fBatchFontCache;
561 SkAutoTDelete<GrLayerCache> fLayerCache; 413 SkAutoTDelete<GrLayerCache> fLayerCache;
562 SkAutoTDelete<GrTextBlobCache> fTextBlobCache; 414 SkAutoTDelete<GrTextBlobCache> fTextBlobCache;
563 415
564 GrPathRendererChain* fPathRendererChain; 416 GrPathRendererChain* fPathRendererChain;
565 GrSoftwarePathRenderer* fSoftwarePathRenderer; 417 GrSoftwarePathRenderer* fSoftwarePathRenderer;
566 418
567 GrDrawTarget* fDrawBuffer;
568
569 // Set by OverbudgetCB() to request that GrContext flush before exiting a dr aw. 419 // Set by OverbudgetCB() to request that GrContext flush before exiting a dr aw.
570 bool fFlushToReduceCacheSize; 420 bool fFlushToReduceCacheSize;
571 GrAARectRenderer* fAARectRenderer;
572 GrOvalRenderer* fOvalRenderer;
573
574 bool fDidTestPMConversions; 421 bool fDidTestPMConversions;
575 int fPMToUPMConversion; 422 int fPMToUPMConversion;
576 int fUPMToPMConversion; 423 int fUPMToPMConversion;
577 424
578 struct CleanUpData { 425 struct CleanUpData {
579 PFCleanUpFunc fFunc; 426 PFCleanUpFunc fFunc;
580 void* fInfo; 427 void* fInfo;
581 }; 428 };
582 429
583 SkTDArray<CleanUpData> fCleanUpData; 430 SkTDArray<CleanUpData> fCleanUpData;
584 431
585 int fMaxTextureSizeOverride; 432 int fMaxTextureSizeOverride;
586 433
587 const uint32_t fUniqueID; 434 const uint32_t fUniqueID;
588 435
589 GrContext(); // init must be called after the constructor. 436 GrContext(); // init must be called after the constructor.
590 bool init(GrBackend, GrBackendContext, const GrContextOptions& options); 437 bool init(GrBackend, GrBackendContext, const GrContextOptions& options);
438
439 // Currently the DrawingMgr just wraps the single GrDrawTarget in a single
440 // GrDrawContext and hands it out. In the future this class will allocate
441 // a new GrDrawContext for each GrRenderTarget/GrDrawTarget and manage
442 // the DAG.
443 class DrawingMgr {
444 public:
445 DrawingMgr()
446 : fDrawTarget(NULL)
447 , fDrawContext(NULL) {
448 }
449
450 ~DrawingMgr();
451
452 void init(GrContext* context);
453
454 void abandon();
455 bool abandoned() const { return NULL == fDrawTarget; }
456
457 void purgeResources();
458 void reset();
459 void flush();
460
461 // Callers should take a ref if they rely on the GrDrawContext sticking around.
462 // NULL will be returned if the context has been abandoned.
463 GrDrawContext* drawContext();
464
465 private:
466 friend class GrContext; // for access to fDrawTarget for testing
467
468 GrDrawTarget* fDrawTarget;
469
470 GrDrawContext* fDrawContext;
471 };
472
473 DrawingMgr fDrawingMgr;
474
591 void initMockContext(); 475 void initMockContext();
592 void initCommon(); 476 void initCommon();
593 477
594 class AutoCheckFlush;
595 // Sets the paint and returns the target to draw into.
596 GrDrawTarget* prepareToDraw(GrPipelineBuilder*,
597 GrRenderTarget* rt,
598 const GrClip&,
599 const GrPaint* paint,
600 const AutoCheckFlush*);
601
602 // A simpler version of the above which just returns the draw target. Clip is *NOT* set
603 GrDrawTarget* prepareToDraw();
604
605 void internalDrawPath(GrDrawTarget*,
606 GrPipelineBuilder*,
607 const SkMatrix& viewMatrix,
608 GrColor,
609 bool useAA,
610 const SkPath&,
611 const GrStrokeInfo&);
612
613 /** 478 /**
614 * Creates a new text rendering context that is optimal for the 479 * Creates a new text rendering context that is optimal for the
615 * render target and the context. Caller assumes the ownership 480 * render target and the context. Caller assumes the ownership
616 * of the returned object. The returned object must be deleted 481 * of the returned object. The returned object must be deleted
617 * before the context is destroyed. 482 * before the context is destroyed.
618 * TODO we can possibly bury this behind context, but we need to be able to use the 483 * TODO we can possibly bury this behind context, but we need to be able to use the
619 * drawText_asPaths logic on SkGpuDevice 484 * drawText_asPaths logic on SkGpuDevice
620 */ 485 */
621 GrTextContext* createTextContext(GrRenderTarget*, 486 GrTextContext* createTextContext(GrRenderTarget*,
622 SkGpuDevice*, 487 SkGpuDevice*,
(...skipping 21 matching lines...) Expand all
644 */ 509 */
645 static void TextBlobCacheOverBudgetCB(void* data); 510 static void TextBlobCacheOverBudgetCB(void* data);
646 511
647 // TODO see note on createTextContext 512 // TODO see note on createTextContext
648 friend class SkGpuDevice; 513 friend class SkGpuDevice;
649 514
650 typedef SkRefCnt INHERITED; 515 typedef SkRefCnt INHERITED;
651 }; 516 };
652 517
653 #endif 518 #endif
OLDNEW
« no previous file with comments | « gyp/gpu.gypi ('k') | include/gpu/GrDrawContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698