OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 #include "GrVkGpu.h" | 8 #include "GrVkGpu.h" |
9 | 9 |
10 #include "GrContextOptions.h" | 10 #include "GrContextOptions.h" |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 // Submit the current command buffer to the Queue | 421 // Submit the current command buffer to the Queue |
422 this->submitCommandBuffer(kSkip_SyncQueue); | 422 this->submitCommandBuffer(kSkip_SyncQueue); |
423 | 423 |
424 transferBuffer->unref(); | 424 transferBuffer->unref(); |
425 } | 425 } |
426 | 426 |
427 return true; | 427 return true; |
428 } | 428 } |
429 | 429 |
430 //////////////////////////////////////////////////////////////////////////////// | 430 //////////////////////////////////////////////////////////////////////////////// |
431 GrTexture* GrVkGpu::onCreateTexture(const GrSurfaceDesc& desc, GrGpuResource::Li
feCycle lifeCycle, | 431 GrTexture* GrVkGpu::onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted budget
ed, |
432 const SkTArray<GrMipLevel>& texels) { | 432 const SkTArray<GrMipLevel>& texels) { |
433 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); | 433 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); |
434 | 434 |
435 VkFormat pixelFormat; | 435 VkFormat pixelFormat; |
436 if (!GrPixelConfigToVkFormat(desc.fConfig, &pixelFormat)) { | 436 if (!GrPixelConfigToVkFormat(desc.fConfig, &pixelFormat)) { |
437 return nullptr; | 437 return nullptr; |
438 } | 438 } |
439 | 439 |
440 if (!fVkCaps->isConfigTexturable(desc.fConfig)) { | 440 if (!fVkCaps->isConfigTexturable(desc.fConfig)) { |
441 return nullptr; | 441 return nullptr; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 imageDesc.fWidth = desc.fWidth; | 476 imageDesc.fWidth = desc.fWidth; |
477 imageDesc.fHeight = desc.fHeight; | 477 imageDesc.fHeight = desc.fHeight; |
478 imageDesc.fLevels = 1; | 478 imageDesc.fLevels = 1; |
479 imageDesc.fSamples = 1; | 479 imageDesc.fSamples = 1; |
480 imageDesc.fImageTiling = linearTiling ? VK_IMAGE_TILING_LINEAR : VK_IMAGE_TI
LING_OPTIMAL; | 480 imageDesc.fImageTiling = linearTiling ? VK_IMAGE_TILING_LINEAR : VK_IMAGE_TI
LING_OPTIMAL; |
481 imageDesc.fUsageFlags = usageFlags; | 481 imageDesc.fUsageFlags = usageFlags; |
482 imageDesc.fMemProps = memProps; | 482 imageDesc.fMemProps = memProps; |
483 | 483 |
484 GrVkTexture* tex; | 484 GrVkTexture* tex; |
485 if (renderTarget) { | 485 if (renderTarget) { |
486 tex = GrVkTextureRenderTarget::CreateNewTextureRenderTarget(this, desc,
lifeCycle, | 486 tex = GrVkTextureRenderTarget::CreateNewTextureRenderTarget(this, budget
ed, desc, |
487 imageDesc); | 487 imageDesc); |
488 } else { | 488 } else { |
489 tex = GrVkTexture::CreateNewTexture(this, desc, lifeCycle, imageDesc); | 489 tex = GrVkTexture::CreateNewTexture(this, budgeted, desc, imageDesc); |
490 } | 490 } |
491 | 491 |
492 if (!tex) { | 492 if (!tex) { |
493 return nullptr; | 493 return nullptr; |
494 } | 494 } |
495 | 495 |
496 // TODO: We're ignoring MIP levels here. | 496 // TODO: We're ignoring MIP levels here. |
497 if (!texels.empty()) { | 497 if (!texels.empty()) { |
498 SkASSERT(texels.begin()->fPixels); | 498 SkASSERT(texels.begin()->fPixels); |
499 if (!this->uploadTexData(tex, 0, 0, desc.fWidth, desc.fHeight, desc.fCon
fig, | 499 if (!this->uploadTexData(tex, 0, 0, desc.fWidth, desc.fHeight, desc.fCon
fig, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 int maxSize = this->caps()->maxTextureSize(); | 531 int maxSize = this->caps()->maxTextureSize(); |
532 if (desc.fWidth > maxSize || desc.fHeight > maxSize) { | 532 if (desc.fWidth > maxSize || desc.fHeight > maxSize) { |
533 return nullptr; | 533 return nullptr; |
534 } | 534 } |
535 | 535 |
536 const GrVkTextureInfo* info = reinterpret_cast<const GrVkTextureInfo*>(desc.
fTextureHandle); | 536 const GrVkTextureInfo* info = reinterpret_cast<const GrVkTextureInfo*>(desc.
fTextureHandle); |
537 if (VK_NULL_HANDLE == info->fImage || VK_NULL_HANDLE == info->fAlloc) { | 537 if (VK_NULL_HANDLE == info->fImage || VK_NULL_HANDLE == info->fAlloc) { |
538 return nullptr; | 538 return nullptr; |
539 } | 539 } |
540 | 540 |
541 GrGpuResource::LifeCycle lifeCycle = (kAdopt_GrWrapOwnership == ownership) | |
542 ? GrGpuResource::kAdopted_LifeCycle | |
543 : GrGpuResource::kBorrowed_LifeCycle; | |
544 | |
545 GrSurfaceDesc surfDesc; | 541 GrSurfaceDesc surfDesc; |
546 // next line relies on GrBackendTextureDesc's flags matching GrTexture's | 542 // next line relies on GrBackendTextureDesc's flags matching GrTexture's |
547 surfDesc.fFlags = (GrSurfaceFlags)desc.fFlags; | 543 surfDesc.fFlags = (GrSurfaceFlags)desc.fFlags; |
548 surfDesc.fWidth = desc.fWidth; | 544 surfDesc.fWidth = desc.fWidth; |
549 surfDesc.fHeight = desc.fHeight; | 545 surfDesc.fHeight = desc.fHeight; |
550 surfDesc.fConfig = desc.fConfig; | 546 surfDesc.fConfig = desc.fConfig; |
551 surfDesc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount()
); | 547 surfDesc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount()
); |
552 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrBackendTextureFla
g); | 548 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrBackendTextureFla
g); |
553 // In GL, Chrome assumes all textures are BottomLeft | 549 // In GL, Chrome assumes all textures are BottomLeft |
554 // In VK, we don't have this restriction | 550 // In VK, we don't have this restriction |
555 surfDesc.fOrigin = resolve_origin(desc.fOrigin); | 551 surfDesc.fOrigin = resolve_origin(desc.fOrigin); |
556 | 552 |
557 GrVkTexture* texture = nullptr; | 553 GrVkTexture* texture = nullptr; |
558 if (renderTarget) { | 554 if (renderTarget) { |
559 texture = GrVkTextureRenderTarget::CreateWrappedTextureRenderTarget(this
, surfDesc, | 555 texture = GrVkTextureRenderTarget::CreateWrappedTextureRenderTarget(this
, surfDesc, |
560 life
Cycle, format, | 556 owne
rship, format, |
561 info
); | 557 info
); |
562 } else { | 558 } else { |
563 texture = GrVkTexture::CreateWrappedTexture(this, surfDesc, lifeCycle, f
ormat, | 559 texture = GrVkTexture::CreateWrappedTexture(this, surfDesc, ownership, f
ormat, info); |
564 info); | |
565 } | 560 } |
566 if (!texture) { | 561 if (!texture) { |
567 return nullptr; | 562 return nullptr; |
568 } | 563 } |
569 | 564 |
570 return texture; | 565 return texture; |
571 } | 566 } |
572 | 567 |
573 GrRenderTarget* GrVkGpu::onWrapBackendRenderTarget(const GrBackendRenderTargetDe
sc& wrapDesc, | 568 GrRenderTarget* GrVkGpu::onWrapBackendRenderTarget(const GrBackendRenderTargetDe
sc& wrapDesc, |
574 GrWrapOwnership ownership) { | 569 GrWrapOwnership ownership) { |
575 | 570 |
576 const GrVkTextureInfo* info = | 571 const GrVkTextureInfo* info = |
577 reinterpret_cast<const GrVkTextureInfo*>(wrapDesc.fRenderTargetHandle); | 572 reinterpret_cast<const GrVkTextureInfo*>(wrapDesc.fRenderTargetHandle); |
578 if (VK_NULL_HANDLE == info->fImage || | 573 if (VK_NULL_HANDLE == info->fImage || |
579 (VK_NULL_HANDLE == info->fAlloc && kAdopt_GrWrapOwnership == ownership))
{ | 574 (VK_NULL_HANDLE == info->fAlloc && kAdopt_GrWrapOwnership == ownership))
{ |
580 return nullptr; | 575 return nullptr; |
581 } | 576 } |
582 | 577 |
583 GrGpuResource::LifeCycle lifeCycle = (kAdopt_GrWrapOwnership == ownership) | |
584 ? GrGpuResource::kAdopted_LifeCycle | |
585 : GrGpuResource::kBorrowed_LifeCycle; | |
586 | |
587 GrSurfaceDesc desc; | 578 GrSurfaceDesc desc; |
588 desc.fConfig = wrapDesc.fConfig; | 579 desc.fConfig = wrapDesc.fConfig; |
589 desc.fFlags = kCheckAllocation_GrSurfaceFlag; | 580 desc.fFlags = kCheckAllocation_GrSurfaceFlag; |
590 desc.fWidth = wrapDesc.fWidth; | 581 desc.fWidth = wrapDesc.fWidth; |
591 desc.fHeight = wrapDesc.fHeight; | 582 desc.fHeight = wrapDesc.fHeight; |
592 desc.fSampleCnt = SkTMin(wrapDesc.fSampleCnt, this->caps()->maxSampleCount()
); | 583 desc.fSampleCnt = SkTMin(wrapDesc.fSampleCnt, this->caps()->maxSampleCount()
); |
593 | 584 |
594 desc.fOrigin = resolve_origin(wrapDesc.fOrigin); | 585 desc.fOrigin = resolve_origin(wrapDesc.fOrigin); |
595 | 586 |
596 GrVkRenderTarget* tgt = GrVkRenderTarget::CreateWrappedRenderTarget(this, de
sc, | 587 GrVkRenderTarget* tgt = GrVkRenderTarget::CreateWrappedRenderTarget(this, de
sc, |
597 lifeCycl
e, | 588 ownershi
p, |
598 info); | 589 info); |
599 if (tgt && wrapDesc.fStencilBits) { | 590 if (tgt && wrapDesc.fStencilBits) { |
600 if (!createStencilAttachmentForRenderTarget(tgt, desc.fWidth, desc.fHeig
ht)) { | 591 if (!createStencilAttachmentForRenderTarget(tgt, desc.fWidth, desc.fHeig
ht)) { |
601 tgt->unref(); | 592 tgt->unref(); |
602 return nullptr; | 593 return nullptr; |
603 } | 594 } |
604 } | 595 } |
605 return tgt; | 596 return tgt; |
606 } | 597 } |
607 | 598 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 int width, | 636 int width, |
646 int height)
{ | 637 int height)
{ |
647 SkASSERT(width >= rt->width()); | 638 SkASSERT(width >= rt->width()); |
648 SkASSERT(height >= rt->height()); | 639 SkASSERT(height >= rt->height()); |
649 | 640 |
650 int samples = rt->numStencilSamples(); | 641 int samples = rt->numStencilSamples(); |
651 | 642 |
652 const GrVkCaps::StencilFormat& sFmt = this->vkCaps().preferedStencilFormat()
; | 643 const GrVkCaps::StencilFormat& sFmt = this->vkCaps().preferedStencilFormat()
; |
653 | 644 |
654 GrVkStencilAttachment* stencil(GrVkStencilAttachment::Create(this, | 645 GrVkStencilAttachment* stencil(GrVkStencilAttachment::Create(this, |
655 GrGpuResource::
kCached_LifeCycle, | |
656 width, | 646 width, |
657 height, | 647 height, |
658 samples, | 648 samples, |
659 sFmt)); | 649 sFmt)); |
660 fStats.incStencilAttachmentCreates(); | 650 fStats.incStencilAttachmentCreates(); |
661 return stencil; | 651 return stencil; |
662 } | 652 } |
663 | 653 |
664 //////////////////////////////////////////////////////////////////////////////// | 654 //////////////////////////////////////////////////////////////////////////////// |
665 | 655 |
(...skipping 914 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1580 aglSwapBuffers(aglGetCurrentContext()); | 1570 aglSwapBuffers(aglGetCurrentContext()); |
1581 int set_a_break_pt_here = 9; | 1571 int set_a_break_pt_here = 9; |
1582 aglSwapBuffers(aglGetCurrentContext()); | 1572 aglSwapBuffers(aglGetCurrentContext()); |
1583 #elif defined(SK_BUILD_FOR_WIN32) | 1573 #elif defined(SK_BUILD_FOR_WIN32) |
1584 SwapBuf(); | 1574 SwapBuf(); |
1585 int set_a_break_pt_here = 9; | 1575 int set_a_break_pt_here = 9; |
1586 SwapBuf(); | 1576 SwapBuf(); |
1587 #endif | 1577 #endif |
1588 #endif | 1578 #endif |
1589 } | 1579 } |
OLD | NEW |