Chromium Code Reviews| 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 "SkMutex.h" | 18 #include "../private/SkMutex.h" |
| 19 #include "SkMipMapLevel.h" | |
| 19 #include "SkPathEffect.h" | 20 #include "SkPathEffect.h" |
| 21 #include "SkTArray.h" | |
| 20 #include "SkTypes.h" | 22 #include "SkTypes.h" |
| 21 | 23 |
| 22 struct GrBatchAtlasConfig; | 24 struct GrBatchAtlasConfig; |
| 23 class GrBatchFontCache; | 25 class GrBatchFontCache; |
| 24 class GrCaps; | 26 class GrCaps; |
| 25 struct GrContextOptions; | 27 struct GrContextOptions; |
| 26 class GrDrawContext; | 28 class GrDrawContext; |
| 27 class GrDrawTarget; | 29 class GrDrawTarget; |
| 28 class GrFragmentProcessor; | 30 class GrFragmentProcessor; |
| 29 class GrGpu; | 31 class GrGpu; |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 * rendering quality for the display. Alternatively returns 0 if | 170 * rendering quality for the display. Alternatively returns 0 if |
| 169 * MSAA is not supported or recommended to be used by default. | 171 * MSAA is not supported or recommended to be used by default. |
| 170 */ | 172 */ |
| 171 int getRecommendedSampleCount(GrPixelConfig config, SkScalar dpi) const; | 173 int getRecommendedSampleCount(GrPixelConfig config, SkScalar dpi) const; |
| 172 | 174 |
| 173 /** | 175 /** |
| 174 * Returns a helper object to orchestrate draws. | 176 * Returns a helper object to orchestrate draws. |
| 175 * Callers should take a ref if they rely on the GrDrawContext sticking arou nd. | 177 * Callers should take a ref if they rely on the GrDrawContext sticking arou nd. |
| 176 * NULL will be returned if the context has been abandoned. | 178 * NULL will be returned if the context has been abandoned. |
| 177 * | 179 * |
| 180 * @param rt the render target receiving the draws | |
| 178 * @param surfaceProps the surface properties (mainly defines text drawing) | 181 * @param surfaceProps the surface properties (mainly defines text drawing) |
| 179 * | 182 * |
| 180 * @return a draw context | 183 * @return a draw context |
| 181 */ | 184 */ |
| 182 GrDrawContext* drawContext(const SkSurfaceProps* surfaceProps = NULL) { | 185 GrDrawContext* drawContext(GrRenderTarget* rt, const SkSurfaceProps* surface Props = NULL) { |
|
bsalomon
2015/10/19 14:56:18
Is this supposed to be showing up in the diff? Loo
| |
| 183 return fDrawingMgr.drawContext(surfaceProps); | 186 return fDrawingMgr.drawContext(rt, surfaceProps); |
| 187 } | |
| 188 | |
| 189 GrTextContext* textContext(const SkSurfaceProps& surfaceProps, GrRenderTarge t* rt) { | |
| 190 return fDrawingMgr.textContext(surfaceProps, rt); | |
| 184 } | 191 } |
| 185 | 192 |
| 186 /////////////////////////////////////////////////////////////////////////// | 193 /////////////////////////////////////////////////////////////////////////// |
| 187 // Misc. | 194 // Misc. |
| 188 | 195 |
| 189 /** | 196 /** |
| 190 * Flags that affect flush() behavior. | 197 * Flags that affect flush() behavior. |
| 191 */ | 198 */ |
| 192 enum FlushBits { | 199 enum FlushBits { |
| 193 /** | 200 /** |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 uint32_t pixelOpsFlags = 0); | 258 uint32_t pixelOpsFlags = 0); |
| 252 | 259 |
| 253 /** | 260 /** |
| 254 * Writes a rectangle of pixels to a surface. | 261 * Writes a rectangle of pixels to a surface. |
| 255 * @param surface the surface to write to. | 262 * @param surface the surface to write to. |
| 256 * @param left left edge of the rectangle to write (inclusive) | 263 * @param left left edge of the rectangle to write (inclusive) |
| 257 * @param top top edge of the rectangle to write (inclusive) | 264 * @param top top edge of the rectangle to write (inclusive) |
| 258 * @param width width of rectangle to write in pixels. | 265 * @param width width of rectangle to write in pixels. |
| 259 * @param height height of rectangle to write in pixels. | 266 * @param height height of rectangle to write in pixels. |
| 260 * @param config the pixel config of the source buffer | 267 * @param config the pixel config of the source buffer |
| 261 * @param buffer memory to read pixels from | 268 * @param texels array of mipmap levels containing texel data to load . |
| 262 * @param rowBytes number of bytes between consecutive rows. Zero | 269 * Begins with full-sized palette data for paletted tex tures. |
| 263 * means rows are tightly packed. | 270 * For compressed formats it contains the compressed pi xel data. |
| 271 * Otherwise, it contains width*height texels. If the a rray is empty, | |
| 272 * texture data is uninitialized. | |
| 264 * @param pixelOpsFlags see PixelOpsFlags enum above. | 273 * @param pixelOpsFlags see PixelOpsFlags enum above. |
| 274 * | |
| 265 * @return true if the write succeeded, false if not. The write can fail bec ause of an | 275 * @return true if the write succeeded, false if not. The write can fail bec ause of an |
| 266 * unsupported combination of surface and src configs. | 276 * unsupported combination of surface and src configs. |
| 267 */ | 277 */ |
| 268 bool writeSurfacePixels(GrSurface* surface, | 278 bool writeSurfacePixels(GrSurface* surface, |
| 269 int left, int top, int width, int height, | 279 int left, int top, int width, int height, |
| 280 GrPixelConfig config, const SkTArray<SkMipMapLevel>& texels, | |
| 281 uint32_t pixelOpsFlags = 0); | |
| 282 | |
| 283 /** | |
| 284 * This function is a shim which creates a SkTArray<SkMipMapLevel> of size 1 . | |
| 285 * It then calls writeSurfacePixels with that SkTArray. | |
| 286 * | |
| 287 * @param buffer Pointer to the pixel values (optional). | |
| 288 * @param rowBytes The number of bytes between rows of the texture. Zero | |
| 289 * implies tightly packed rows. For compressed pixel config s, this | |
| 290 * field is ignored. | |
| 291 */ | |
| 292 bool writeSurfacePixels(GrSurface* surface, | |
| 293 int left, int top, int width, int height, | |
| 270 GrPixelConfig config, const void* buffer, | 294 GrPixelConfig config, const void* buffer, |
| 271 size_t rowBytes, | 295 size_t rowBytes, |
| 272 uint32_t pixelOpsFlags = 0); | 296 uint32_t pixelOpsFlags = 0); |
| 273 | 297 |
| 274 /** | 298 /** |
| 275 * Copies a rectangle of texels from src to dst. | 299 * Copies a rectangle of texels from src to dst. |
| 276 * bounds. | 300 * bounds. |
| 277 * @param dst the surface to copy to. | 301 * @param dst the surface to copy to. |
| 278 * @param src the surface to copy from. | 302 * @param src the surface to copy from. |
| 279 * @param srcRect the rectangle of the src that should be copied. | 303 * @param srcRect the rectangle of the src that should be copied. |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 void* fInfo; | 427 void* fInfo; |
| 404 }; | 428 }; |
| 405 | 429 |
| 406 SkTDArray<CleanUpData> fCleanUpData; | 430 SkTDArray<CleanUpData> fCleanUpData; |
| 407 | 431 |
| 408 const uint32_t fUniqueID; | 432 const uint32_t fUniqueID; |
| 409 | 433 |
| 410 GrContext(); // init must be called after the constructor. | 434 GrContext(); // init must be called after the constructor. |
| 411 bool init(GrBackend, GrBackendContext, const GrContextOptions& options); | 435 bool init(GrBackend, GrBackendContext, const GrContextOptions& options); |
| 412 | 436 |
| 413 // Currently the DrawingMgr stores a separate GrDrawContext for each | 437 // Currently the DrawingMgr creates a separate GrTextContext for each |
| 414 // combination of text drawing options (pixel geometry x DFT use) | 438 // combination of text drawing options (pixel geometry x DFT use) |
| 415 // and hands the appropriate one back given the user's request. | 439 // and hands the appropriate one back given the DrawContext's request. |
| 416 // All of the GrDrawContexts still land in the same GrDrawTarget! | 440 // |
| 441 // It allocates a new GrDrawContext for each GrRenderTarget | |
| 442 // but all of them still land in the same GrDrawTarget! | |
| 417 // | 443 // |
| 418 // In the future this class will allocate a new GrDrawContext for | 444 // In the future this class will allocate a new GrDrawContext for |
| 419 // each GrRenderTarget/GrDrawTarget and manage the DAG. | 445 // each GrRenderTarget/GrDrawTarget and manage the DAG. |
| 420 class DrawingMgr { | 446 class DrawingMgr { |
| 421 public: | 447 public: |
| 422 DrawingMgr() : fDrawTarget(NULL) { | 448 DrawingMgr() : fDrawTarget(nullptr), fNVPRTextContext(nullptr) { |
| 423 sk_bzero(fDrawContext, sizeof(fDrawContext)); | 449 sk_bzero(fTextContexts, sizeof(fTextContexts)); |
| 424 } | 450 } |
| 425 | 451 |
| 426 ~DrawingMgr(); | 452 ~DrawingMgr(); |
| 427 | 453 |
| 428 void init(GrContext* context); | 454 void init(GrContext* context); |
| 429 | 455 |
| 430 void abandon(); | 456 void abandon(); |
| 431 bool abandoned() const { return NULL == fDrawTarget; } | 457 bool abandoned() const { return NULL == fDrawTarget; } |
| 432 | 458 |
| 433 void purgeResources(); | |
| 434 void reset(); | 459 void reset(); |
| 435 void flush(); | 460 void flush(); |
| 436 | 461 |
| 437 // Callers should take a ref if they rely on the GrDrawContext sticking around. | 462 // Callers assume the creation ref of the drawContext! |
| 438 // NULL will be returned if the context has been abandoned. | 463 // NULL will be returned if the context has been abandoned. |
| 439 GrDrawContext* drawContext(const SkSurfaceProps* surfaceProps); | 464 GrDrawContext* drawContext(GrRenderTarget* rt, const SkSurfaceProps* sur faceProps); |
| 465 | |
| 466 GrTextContext* textContext(const SkSurfaceProps& props, GrRenderTarget* rt); | |
| 440 | 467 |
| 441 private: | 468 private: |
| 442 void cleanup(); | 469 void cleanup(); |
| 443 | 470 |
| 444 friend class GrContext; // for access to fDrawTarget for testing | 471 friend class GrContext; // for access to fDrawTarget for testing |
| 445 | 472 |
| 446 static const int kNumPixelGeometries = 5; // The different pixel geometr ies | 473 static const int kNumPixelGeometries = 5; // The different pixel geometr ies |
| 447 static const int kNumDFTOptions = 2; // DFT or no DFT | 474 static const int kNumDFTOptions = 2; // DFT or no DFT |
| 448 | 475 |
| 449 GrContext* fContext; | 476 GrContext* fContext; |
| 450 GrDrawTarget* fDrawTarget; | 477 GrDrawTarget* fDrawTarget; |
| 451 | 478 |
| 452 GrDrawContext* fDrawContext[kNumPixelGeometries][kNumDFTOptions]; | 479 GrTextContext* fNVPRTextContext; |
| 480 GrTextContext* fTextContexts[kNumPixelGeometries][kNumDFTOptions]; | |
| 453 }; | 481 }; |
| 454 | 482 |
| 455 DrawingMgr fDrawingMgr; | 483 DrawingMgr fDrawingMgr; |
| 456 | 484 |
| 457 void initMockContext(); | 485 void initMockContext(); |
| 458 void initCommon(); | 486 void initCommon(); |
| 459 | 487 |
| 460 /** | 488 /** |
| 461 * These functions create premul <-> unpremul effects if it is possible to g enerate a pair | 489 * These functions create premul <-> unpremul effects if it is possible to g enerate a pair |
| 462 * of effects that make a readToUPM->writeToPM->readToUPM cycle invariant. O therwise, they | 490 * of effects that make a readToUPM->writeToPM->readToUPM cycle invariant. O therwise, they |
| 463 * return NULL. | 491 * return NULL. |
| 464 */ | 492 */ |
| 465 const GrFragmentProcessor* createPMToUPMEffect(GrProcessorDataManager*, GrTe xture*, | 493 const GrFragmentProcessor* createPMToUPMEffect(GrTexture*, bool swapRAndB, |
| 466 bool swapRAndB, const SkMatri x&) const; | 494 const SkMatrix&) const; |
| 467 const GrFragmentProcessor* createUPMToPMEffect(GrProcessorDataManager*, GrTe xture*, | 495 const GrFragmentProcessor* createUPMToPMEffect(GrTexture*, bool swapRAndB, |
| 468 bool swapRAndB, const SkMatri x&) const; | 496 const SkMatrix&) const; |
| 469 /** Called before either of the above two functions to determine the appropr iate fragment | 497 /** Called before either of the above two functions to determine the appropr iate fragment |
| 470 processors for conversions. This must be called by readSurfacePixels bef or a mutex is taken, | 498 processors for conversions. This must be called by readSurfacePixels bef ore a mutex is |
| 471 since testingvPM conversions itself will call readSurfacePixels */ | 499 taken, since testingvPM conversions itself will call readSurfacePixels * / |
| 472 void testPMConversionsIfNecessary(uint32_t flags); | 500 void testPMConversionsIfNecessary(uint32_t flags); |
| 473 /** Returns true if we've already determined that createPMtoUPMEffect and cr eateUPMToPMEffect | 501 /** Returns true if we've already determined that createPMtoUPMEffect and cr eateUPMToPMEffect |
| 474 will fail. In such cases fall back to SW conversion. */ | 502 will fail. In such cases fall back to SW conversion. */ |
| 475 bool didFailPMUPMConversionTest() const; | 503 bool didFailPMUPMConversionTest() const; |
| 476 | 504 |
| 477 /** | 505 /** |
| 478 * This callback allows the resource cache to callback into the GrContext | 506 * This callback allows the resource cache to callback into the GrContext |
| 479 * when the cache is still over budget after a purge. | 507 * when the cache is still over budget after a purge. |
| 480 */ | 508 */ |
| 481 static void OverBudgetCB(void* data); | 509 static void OverBudgetCB(void* data); |
| 482 | 510 |
| 483 /** | 511 /** |
| 484 * A callback similar to the above for use by the TextBlobCache | 512 * A callback similar to the above for use by the TextBlobCache |
| 485 * TODO move textblob draw calls below context so we can use the call above. | 513 * TODO move textblob draw calls below context so we can use the call above. |
| 486 */ | 514 */ |
| 487 static void TextBlobCacheOverBudgetCB(void* data); | 515 static void TextBlobCacheOverBudgetCB(void* data); |
| 488 | 516 |
| 489 typedef SkRefCnt INHERITED; | 517 typedef SkRefCnt INHERITED; |
| 490 }; | 518 }; |
| 491 | 519 |
| 492 #endif | 520 #endif |
| OLD | NEW |