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 28 matching lines...) Expand all Loading... |
39 fIndexBuffer.reset(di.indexBuffer()); | 39 fIndexBuffer.reset(di.indexBuffer()); |
40 | 40 |
41 return *this; | 41 return *this; |
42 } | 42 } |
43 | 43 |
44 //////////////////////////////////////////////////////////////////////////////// | 44 //////////////////////////////////////////////////////////////////////////////// |
45 | 45 |
46 GrGpu::GrGpu(GrContext* context) | 46 GrGpu::GrGpu(GrContext* context) |
47 : fResetTimestamp(kExpiredTimestamp+1) | 47 : fResetTimestamp(kExpiredTimestamp+1) |
48 , fResetBits(kAll_GrBackendState) | 48 , fResetBits(kAll_GrBackendState) |
49 , fMultisampleSpecsAllocator(1) | |
50 , fContext(context) { | 49 , fContext(context) { |
| 50 fMultisampleSpecs.emplace_back(0, 0, nullptr); // Index 0 is an invalid uniq
ue id. |
51 } | 51 } |
52 | 52 |
53 GrGpu::~GrGpu() {} | 53 GrGpu::~GrGpu() {} |
54 | 54 |
55 void GrGpu::disconnect(DisconnectType) {} | 55 void GrGpu::disconnect(DisconnectType) {} |
56 | 56 |
57 //////////////////////////////////////////////////////////////////////////////// | 57 //////////////////////////////////////////////////////////////////////////////// |
58 | 58 |
59 bool GrGpu::makeCopyForTextureParams(int width, int height, const GrTextureParam
s& textureParams, | 59 bool GrGpu::makeCopyForTextureParams(int width, int height, const GrTextureParam
s& textureParams, |
60 GrTextureProducer::CopyParams* copyParams)
const { | 60 GrTextureProducer::CopyParams* copyParams)
const { |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 if (GrRenderTarget* target = surface->asRenderTarget()) { | 418 if (GrRenderTarget* target = surface->asRenderTarget()) { |
419 target->flagAsNeedingResolve(bounds); | 419 target->flagAsNeedingResolve(bounds); |
420 } | 420 } |
421 GrTexture* texture = surface->asTexture(); | 421 GrTexture* texture = surface->asTexture(); |
422 if (texture && 1 == mipLevels) { | 422 if (texture && 1 == mipLevels) { |
423 texture->texturePriv().dirtyMipMaps(true); | 423 texture->texturePriv().dirtyMipMaps(true); |
424 } | 424 } |
425 } | 425 } |
426 } | 426 } |
427 | 427 |
428 inline static uint8_t multisample_specs_id(uint8_t numSamples, GrSurfaceOrigin o
rigin, | |
429 const GrCaps& caps) { | |
430 if (!caps.sampleLocationsSupport()) { | |
431 return numSamples; | |
432 } | |
433 | |
434 SkASSERT(numSamples < 128); | |
435 SkASSERT(kTopLeft_GrSurfaceOrigin == origin || kBottomLeft_GrSurfaceOrigin =
= origin); | |
436 return (numSamples << 1) | (origin - 1); | |
437 | |
438 GR_STATIC_ASSERT(1 == kTopLeft_GrSurfaceOrigin); | |
439 GR_STATIC_ASSERT(2 == kBottomLeft_GrSurfaceOrigin); | |
440 } | |
441 | |
442 const GrGpu::MultisampleSpecs& GrGpu::getMultisampleSpecs(GrRenderTarget* rt, | 428 const GrGpu::MultisampleSpecs& GrGpu::getMultisampleSpecs(GrRenderTarget* rt, |
443 const GrStencilSetting
s& stencil) { | 429 const GrStencilSetting
s& stencil) { |
444 const GrSurfaceDesc& desc = rt->desc(); | 430 SkASSERT(rt->desc().fSampleCnt > 1); |
445 uint8_t surfDescKey = multisample_specs_id(desc.fSampleCnt, desc.fOrigin, *t
his->caps()); | 431 |
446 if (fMultisampleSpecsMap.count() > surfDescKey && fMultisampleSpecsMap[surfD
escKey]) { | 432 #ifndef SK_DEBUG |
447 #if !defined(SK_DEBUG) | 433 // In debug mode we query the multisample info every time to verify the cach
ing is correct. |
448 // In debug mode we query the multisample info every time and verify the
caching is correct. | 434 if (uint8_t id = rt->renderTargetPriv().accessMultisampleSpecsID()) { |
449 return *fMultisampleSpecsMap[surfDescKey]; | 435 SkASSERT(id > 0 && id < fMultisampleSpecs.count()); |
| 436 return fMultisampleSpecs[id]; |
| 437 } |
450 #endif | 438 #endif |
| 439 |
| 440 int effectiveSampleCnt; |
| 441 SkSTArray<16, SkPoint, true> pattern; |
| 442 this->onGetMultisampleSpecs(rt, stencil, &effectiveSampleCnt, &pattern); |
| 443 SkASSERT(effectiveSampleCnt >= rt->desc().fSampleCnt); |
| 444 |
| 445 uint8_t id; |
| 446 if (this->caps()->sampleLocationsSupport()) { |
| 447 SkASSERT(pattern.count() == effectiveSampleCnt); |
| 448 const auto& insertResult = fMultisampleSpecsIdMap.insert( |
| 449 MultisampleSpecsIdMap::value_type(pattern, SkTMin(fMultisampleSpecs.
count(), 255))); |
| 450 id = insertResult.first->second; |
| 451 if (insertResult.second) { |
| 452 // This means the insert did not find the pattern in the map already
, and therefore an |
| 453 // actual insertion took place. (We don't expect to see many unique
sample patterns.) |
| 454 const SkPoint* sampleLocations = insertResult.first->first.begin(); |
| 455 SkASSERT(id == fMultisampleSpecs.count()); |
| 456 fMultisampleSpecs.emplace_back(id, effectiveSampleCnt, sampleLocatio
ns); |
| 457 } |
| 458 } else { |
| 459 id = effectiveSampleCnt; |
| 460 for (int i = fMultisampleSpecs.count(); i <= id; ++i) { |
| 461 fMultisampleSpecs.emplace_back(i, i, nullptr); |
| 462 } |
451 } | 463 } |
452 int effectiveSampleCnt; | 464 SkASSERT(id > 0); |
453 SkAutoTDeleteArray<SkPoint> locations(nullptr); | 465 SkASSERT(!rt->renderTargetPriv().accessMultisampleSpecsID() || |
454 this->onGetMultisampleSpecs(rt, stencil, &effectiveSampleCnt, &locations); | 466 rt->renderTargetPriv().accessMultisampleSpecsID() == id); |
455 SkASSERT(effectiveSampleCnt && effectiveSampleCnt >= desc.fSampleCnt); | 467 |
456 uint8_t effectiveKey = multisample_specs_id(effectiveSampleCnt, desc.fOrigin
, *this->caps()); | 468 rt->renderTargetPriv().accessMultisampleSpecsID() = id; |
457 if (fMultisampleSpecsMap.count() > effectiveKey && fMultisampleSpecsMap[effe
ctiveKey]) { | 469 return fMultisampleSpecs[id]; |
458 const MultisampleSpecs& specs = *fMultisampleSpecsMap[effectiveKey]; | |
459 SkASSERT(effectiveKey == specs.fUniqueID); | |
460 SkASSERT(effectiveSampleCnt == specs.fEffectiveSampleCnt); | |
461 SkASSERT(!this->caps()->sampleLocationsSupport() || | |
462 !memcmp(locations.get(), specs.fSampleLocations.get(), | |
463 effectiveSampleCnt * sizeof(SkPoint))); | |
464 SkASSERT(surfDescKey <= effectiveKey); | |
465 SkASSERT(!fMultisampleSpecsMap[surfDescKey] || fMultisampleSpecsMap[surf
DescKey] == &specs); | |
466 fMultisampleSpecsMap[surfDescKey] = &specs; | |
467 return specs; | |
468 } | |
469 const MultisampleSpecs& specs = *new (&fMultisampleSpecsAllocator) | |
470 MultisampleSpecs{effectiveKey, effectiveSampleCnt, locations.release()}; | |
471 if (fMultisampleSpecsMap.count() <= effectiveKey) { | |
472 int n = 1 + effectiveKey - fMultisampleSpecsMap.count(); | |
473 fMultisampleSpecsMap.push_back_n(n, (const MultisampleSpecs*) nullptr); | |
474 } | |
475 fMultisampleSpecsMap[effectiveKey] = &specs; | |
476 if (effectiveSampleCnt != desc.fSampleCnt) { | |
477 SkASSERT(surfDescKey < effectiveKey); | |
478 fMultisampleSpecsMap[surfDescKey] = &specs; | |
479 } | |
480 return specs; | |
481 } | 470 } |
482 | 471 |
| 472 bool GrGpu::SamplePatternComparator::operator()(const SamplePattern& a, |
| 473 const SamplePattern& b) const { |
| 474 if (a.count() != b.count()) { |
| 475 return a.count() < b.count(); |
| 476 } |
| 477 for (int i = 0; i < a.count(); ++i) { |
| 478 // This doesn't have geometric meaning. We just need to define an orderi
ng for std::map. |
| 479 if (a[i].x() != b[i].x()) { |
| 480 return a[i].x() < b[i].x(); |
| 481 } |
| 482 if (a[i].y() != b[i].y()) { |
| 483 return a[i].y() < b[i].y(); |
| 484 } |
| 485 } |
| 486 return false; // Equal. |
| 487 } |
OLD | NEW |