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