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 | 8 |
| 9 #include "GrGpu.h" | 9 #include "GrGpu.h" |
| 10 | 10 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 fIndexBuffer.reset(di.indexBuffer()); | 40 fIndexBuffer.reset(di.indexBuffer()); |
| 41 | 41 |
| 42 return *this; | 42 return *this; |
| 43 } | 43 } |
| 44 | 44 |
| 45 //////////////////////////////////////////////////////////////////////////////// | 45 //////////////////////////////////////////////////////////////////////////////// |
| 46 | 46 |
| 47 GrGpu::GrGpu(GrContext* context) | 47 GrGpu::GrGpu(GrContext* context) |
| 48 : fResetTimestamp(kExpiredTimestamp+1) | 48 : fResetTimestamp(kExpiredTimestamp+1) |
| 49 , fResetBits(kAll_GrBackendState) | 49 , fResetBits(kAll_GrBackendState) |
| 50 , fMultisampleSpecsAllocator(1) | |
| 50 , fContext(context) { | 51 , fContext(context) { |
| 51 } | 52 } |
| 52 | 53 |
| 53 GrGpu::~GrGpu() {} | 54 GrGpu::~GrGpu() {} |
| 54 | 55 |
| 55 void GrGpu::contextAbandoned() {} | 56 void GrGpu::contextAbandoned() {} |
| 56 | 57 |
| 57 //////////////////////////////////////////////////////////////////////////////// | 58 //////////////////////////////////////////////////////////////////////////////// |
| 58 | 59 |
| 59 bool GrGpu::makeCopyForTextureParams(int width, int height, const GrTextureParam s& textureParams, | 60 bool GrGpu::makeCopyForTextureParams(int width, int height, const GrTextureParam s& textureParams, |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 } | 438 } |
| 438 return false; | 439 return false; |
| 439 } | 440 } |
| 440 | 441 |
| 441 void GrGpu::resolveRenderTarget(GrRenderTarget* target) { | 442 void GrGpu::resolveRenderTarget(GrRenderTarget* target) { |
| 442 SkASSERT(target); | 443 SkASSERT(target); |
| 443 this->handleDirtyContext(); | 444 this->handleDirtyContext(); |
| 444 this->onResolveRenderTarget(target); | 445 this->onResolveRenderTarget(target); |
| 445 } | 446 } |
| 446 | 447 |
| 448 inline static uint8_t multisample_specs_id(uint8_t numSamples, GrSurfaceOrigin o rigin, | |
| 449 const GrCaps& caps) { | |
| 450 if (!caps.sampleLocationsSupport()) { | |
| 451 return numSamples; | |
| 452 } | |
| 453 | |
| 454 SkASSERT(numSamples < 128); | |
| 455 SkASSERT(kTopLeft_GrSurfaceOrigin == origin || kBottomLeft_GrSurfaceOrigin = = origin); | |
| 456 return (numSamples << 1) | (origin - 1); | |
| 457 | |
| 458 GR_STATIC_ASSERT(1 == kTopLeft_GrSurfaceOrigin); | |
| 459 GR_STATIC_ASSERT(2 == kBottomLeft_GrSurfaceOrigin); | |
| 460 } | |
| 461 | |
| 462 const GrGpu::MultisampleSpecs& GrGpu::getMultisampleSpecs(GrRenderTarget* rt, | |
| 463 const GrStencilSetting s& stencil) { | |
| 464 const GrSurfaceDesc& desc = rt->desc(); | |
| 465 uint8_t surfDescKey = multisample_specs_id(desc.fSampleCnt, desc.fOrigin, *t his->caps()); | |
| 466 if (fMultisampleSpecsMap.count() > surfDescKey && fMultisampleSpecsMap[surfD escKey]) { | |
| 467 #if !defined(SK_DEBUG) | |
|
Mark Kilgard
2016/03/07 21:12:52
nice approach
| |
| 468 // In debug mode we query the multisample info every time and verify the caching is correct. | |
| 469 return *fMultisampleSpecsMap[surfDescKey]; | |
| 470 #endif | |
| 471 } | |
| 472 int effectiveSampleCnt; | |
| 473 SkAutoTDeleteArray<SkPoint> locations(nullptr); | |
| 474 this->onGetMultisampleSpecs(rt, stencil, &effectiveSampleCnt, &locations); | |
| 475 SkASSERT(effectiveSampleCnt && effectiveSampleCnt >= desc.fSampleCnt); | |
| 476 uint8_t effectiveKey = multisample_specs_id(effectiveSampleCnt, desc.fOrigin , *this->caps()); | |
| 477 if (fMultisampleSpecsMap.count() > effectiveKey && fMultisampleSpecsMap[effe ctiveKey]) { | |
| 478 const MultisampleSpecs& specs = *fMultisampleSpecsMap[effectiveKey]; | |
| 479 SkASSERT(effectiveKey == specs.fUniqueID); | |
| 480 SkASSERT(effectiveSampleCnt == specs.fEffectiveSampleCnt); | |
| 481 SkASSERT(!this->caps()->sampleLocationsSupport() || | |
| 482 !memcmp(locations.get(), specs.fSampleLocations.get(), | |
| 483 effectiveSampleCnt * sizeof(SkPoint))); | |
| 484 SkASSERT(surfDescKey <= effectiveKey); | |
| 485 SkASSERT(!fMultisampleSpecsMap[surfDescKey] || fMultisampleSpecsMap[surf DescKey] == &specs); | |
| 486 fMultisampleSpecsMap[surfDescKey] = &specs; | |
| 487 return specs; | |
| 488 } | |
| 489 const MultisampleSpecs& specs = *new (&fMultisampleSpecsAllocator) | |
| 490 MultisampleSpecs{effectiveKey, effectiveSampleCnt, locations.detach()}; | |
| 491 if (fMultisampleSpecsMap.count() <= effectiveKey) { | |
| 492 int n = 1 + effectiveKey - fMultisampleSpecsMap.count(); | |
| 493 fMultisampleSpecsMap.push_back_n(n, (const MultisampleSpecs*) nullptr); | |
| 494 } | |
| 495 fMultisampleSpecsMap[effectiveKey] = &specs; | |
| 496 if (effectiveSampleCnt != desc.fSampleCnt) { | |
| 497 SkASSERT(surfDescKey < effectiveKey); | |
| 498 fMultisampleSpecsMap[surfDescKey] = &specs; | |
| 499 } | |
| 500 return specs; | |
| 501 } | |
| 502 | |
| 447 //////////////////////////////////////////////////////////////////////////////// | 503 //////////////////////////////////////////////////////////////////////////////// |
| 448 | 504 |
| 449 void GrGpu::draw(const DrawArgs& args, const GrVertices& vertices) { | 505 void GrGpu::draw(const DrawArgs& args, const GrVertices& vertices) { |
| 450 this->handleDirtyContext(); | 506 this->handleDirtyContext(); |
| 451 if (GrXferBarrierType barrierType = args.fPipeline->xferBarrierType(*this->c aps())) { | 507 if (GrXferBarrierType barrierType = args.fPipeline->xferBarrierType(*this->c aps())) { |
| 452 this->xferBarrier(args.fPipeline->getRenderTarget(), barrierType); | 508 this->xferBarrier(args.fPipeline->getRenderTarget(), barrierType); |
| 453 } | 509 } |
| 454 | 510 |
| 455 GrVertices::Iterator iter; | 511 GrVertices::Iterator iter; |
| 456 const GrNonInstancedVertices* verts = iter.init(vertices); | 512 const GrNonInstancedVertices* verts = iter.init(vertices); |
| 457 do { | 513 do { |
| 458 this->onDraw(args, *verts); | 514 this->onDraw(args, *verts); |
| 459 fStats.incNumDraws(); | 515 fStats.incNumDraws(); |
| 460 } while ((verts = iter.next())); | 516 } while ((verts = iter.next())); |
| 461 } | 517 } |
| 462 | 518 |
| OLD | NEW |