OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "GrGLGpu.h" | 9 #include "GrGLGpu.h" |
10 #include "GrGLGLSL.h" | 10 #include "GrGLGLSL.h" |
11 #include "GrGLStencilAttachment.h" | 11 #include "GrGLStencilAttachment.h" |
12 #include "GrGLTextureRenderTarget.h" | 12 #include "GrGLTextureRenderTarget.h" |
13 #include "GrGpuResourcePriv.h" | 13 #include "GrGpuResourcePriv.h" |
14 #include "GrPipeline.h" | 14 #include "GrPipeline.h" |
15 #include "GrRenderTargetPriv.h" | 15 #include "GrRenderTargetPriv.h" |
16 #include "GrSurfacePriv.h" | 16 #include "GrSurfacePriv.h" |
17 #include "GrTexturePriv.h" | 17 #include "GrTexturePriv.h" |
18 #include "GrTypes.h" | 18 #include "GrTypes.h" |
19 #include "GrVertices.h" | 19 #include "GrVertices.h" |
20 #include "builders/GrGLShaderStringBuilder.h" | 20 #include "builders/GrGLShaderStringBuilder.h" |
21 #include "glsl/GrGLSL.h" | 21 #include "glsl/GrGLSL.h" |
22 #include "glsl/GrGLSLCaps.h" | 22 #include "glsl/GrGLSLCaps.h" |
23 #include "SkStrokeRec.h" | 23 #include "SkStrokeRec.h" |
24 #include "SkTemplates.h" | 24 #include "SkTemplates.h" |
| 25 #include "SkTypes.h" |
25 | 26 |
26 #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X) | 27 #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X) |
27 #define GL_CALL_RET(RET, X) GR_GL_CALL_RET(this->glInterface(), RET, X) | 28 #define GL_CALL_RET(RET, X) GR_GL_CALL_RET(this->glInterface(), RET, X) |
28 | 29 |
29 #define SKIP_CACHE_CHECK true | 30 #define SKIP_CACHE_CHECK true |
30 | 31 |
31 #if GR_GL_CHECK_ALLOC_WITH_GET_ERROR | 32 #if GR_GL_CHECK_ALLOC_WITH_GET_ERROR |
32 #define CLEAR_ERROR_BEFORE_ALLOC(iface) GrGLClearErr(iface) | 33 #define CLEAR_ERROR_BEFORE_ALLOC(iface) GrGLClearErr(iface) |
33 #define GL_ALLOC_CALL(iface, call) GR_GL_CALL_NOERRCHECK(iface, call) | 34 #define GL_ALLOC_CALL(iface, call) GR_GL_CALL_NOERRCHECK(iface, call) |
34 #define CHECK_ALLOC_ERROR(iface) GR_GL_GET_ERROR(iface) | 35 #define CHECK_ALLOC_ERROR(iface) GR_GL_GET_ERROR(iface) |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 // We only support GL_TEXTURE_2D at the moment. | 431 // We only support GL_TEXTURE_2D at the moment. |
431 idDesc.fTarget = GR_GL_TEXTURE_2D; | 432 idDesc.fTarget = GR_GL_TEXTURE_2D; |
432 | 433 |
433 switch (ownership) { | 434 switch (ownership) { |
434 case kAdopt_GrWrapOwnership: | 435 case kAdopt_GrWrapOwnership: |
435 idDesc.fLifeCycle = GrGpuResource::kAdopted_LifeCycle; | 436 idDesc.fLifeCycle = GrGpuResource::kAdopted_LifeCycle; |
436 break; | 437 break; |
437 case kBorrow_GrWrapOwnership: | 438 case kBorrow_GrWrapOwnership: |
438 idDesc.fLifeCycle = GrGpuResource::kBorrowed_LifeCycle; | 439 idDesc.fLifeCycle = GrGpuResource::kBorrowed_LifeCycle; |
439 break; | 440 break; |
440 } | 441 } |
441 | 442 |
442 // next line relies on GrBackendTextureDesc's flags matching GrTexture's | 443 // next line relies on GrBackendTextureDesc's flags matching GrTexture's |
443 surfDesc.fFlags = (GrSurfaceFlags) desc.fFlags; | 444 surfDesc.fFlags = (GrSurfaceFlags) desc.fFlags; |
444 surfDesc.fWidth = desc.fWidth; | 445 surfDesc.fWidth = desc.fWidth; |
445 surfDesc.fHeight = desc.fHeight; | 446 surfDesc.fHeight = desc.fHeight; |
446 surfDesc.fConfig = desc.fConfig; | 447 surfDesc.fConfig = desc.fConfig; |
447 surfDesc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount()
); | 448 surfDesc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount()
); |
448 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrBackendTextureFla
g); | 449 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrBackendTextureFla
g); |
449 // FIXME: this should be calling resolve_origin(), but Chrome code is curre
ntly | 450 // FIXME: this should be calling resolve_origin(), but Chrome code is curre
ntly |
450 // assuming the old behaviour, which is that backend textures are always | 451 // assuming the old behaviour, which is that backend textures are always |
(...skipping 29 matching lines...) Expand all Loading... |
480 idDesc.fRTFBOID = static_cast<GrGLuint>(wrapDesc.fRenderTargetHandle); | 481 idDesc.fRTFBOID = static_cast<GrGLuint>(wrapDesc.fRenderTargetHandle); |
481 idDesc.fMSColorRenderbufferID = 0; | 482 idDesc.fMSColorRenderbufferID = 0; |
482 idDesc.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID; | 483 idDesc.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID; |
483 switch (ownership) { | 484 switch (ownership) { |
484 case kAdopt_GrWrapOwnership: | 485 case kAdopt_GrWrapOwnership: |
485 idDesc.fLifeCycle = GrGpuResource::kAdopted_LifeCycle; | 486 idDesc.fLifeCycle = GrGpuResource::kAdopted_LifeCycle; |
486 break; | 487 break; |
487 case kBorrow_GrWrapOwnership: | 488 case kBorrow_GrWrapOwnership: |
488 idDesc.fLifeCycle = GrGpuResource::kBorrowed_LifeCycle; | 489 idDesc.fLifeCycle = GrGpuResource::kBorrowed_LifeCycle; |
489 break; | 490 break; |
490 } | 491 } |
491 idDesc.fSampleConfig = GrRenderTarget::kUnified_SampleConfig; | 492 idDesc.fSampleConfig = GrRenderTarget::kUnified_SampleConfig; |
492 | 493 |
493 GrSurfaceDesc desc; | 494 GrSurfaceDesc desc; |
494 desc.fConfig = wrapDesc.fConfig; | 495 desc.fConfig = wrapDesc.fConfig; |
495 desc.fFlags = kCheckAllocation_GrSurfaceFlag | kRenderTarget_GrSurfaceFlag; | 496 desc.fFlags = kCheckAllocation_GrSurfaceFlag | kRenderTarget_GrSurfaceFlag; |
496 desc.fWidth = wrapDesc.fWidth; | 497 desc.fWidth = wrapDesc.fWidth; |
497 desc.fHeight = wrapDesc.fHeight; | 498 desc.fHeight = wrapDesc.fHeight; |
498 desc.fSampleCnt = SkTMin(wrapDesc.fSampleCnt, this->caps()->maxSampleCount()
); | 499 desc.fSampleCnt = SkTMin(wrapDesc.fSampleCnt, this->caps()->maxSampleCount()
); |
499 desc.fOrigin = resolve_origin(wrapDesc.fOrigin, true); | 500 desc.fOrigin = resolve_origin(wrapDesc.fOrigin, true); |
500 | 501 |
501 return GrGLRenderTarget::CreateWrapped(this, desc, idDesc, wrapDesc.fStencil
Bits); | 502 return GrGLRenderTarget::CreateWrapped(this, desc, idDesc, wrapDesc.fStencil
Bits); |
502 } | 503 } |
503 | 504 |
504 //////////////////////////////////////////////////////////////////////////////// | 505 //////////////////////////////////////////////////////////////////////////////// |
505 bool GrGLGpu::onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height, | 506 bool GrGLGpu::onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height, |
506 size_t rowBytes, GrPixelConfig srcConfig, | 507 GrPixelConfig srcConfig, |
507 DrawPreference* drawPreference, | 508 DrawPreference* drawPreference, |
508 WritePixelTempDrawInfo* tempDrawInfo) { | 509 WritePixelTempDrawInfo* tempDrawInfo) { |
509 if (kIndex_8_GrPixelConfig == srcConfig || GrPixelConfigIsCompressed(dstSurf
ace->config())) { | 510 if (kIndex_8_GrPixelConfig == srcConfig || GrPixelConfigIsCompressed(dstSurf
ace->config())) { |
510 return false; | 511 return false; |
511 } | 512 } |
512 | 513 |
513 // This subclass only allows writes to textures. If the dst is not a texture
we have to draw | 514 // This subclass only allows writes to textures. If the dst is not a texture
we have to draw |
514 // into it. We could use glDrawPixels on GLs that have it, but we don't toda
y. | 515 // into it. We could use glDrawPixels on GLs that have it, but we don't toda
y. |
515 if (!dstSurface->asTexture()) { | 516 if (!dstSurface->asTexture()) { |
516 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); | 517 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 if (!this->glCaps().unpackFlipYSupport() && | 557 if (!this->glCaps().unpackFlipYSupport() && |
557 kBottomLeft_GrSurfaceOrigin == dstSurface->origin()) { | 558 kBottomLeft_GrSurfaceOrigin == dstSurface->origin()) { |
558 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference); | 559 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference); |
559 } | 560 } |
560 | 561 |
561 return true; | 562 return true; |
562 } | 563 } |
563 | 564 |
564 bool GrGLGpu::onWritePixels(GrSurface* surface, | 565 bool GrGLGpu::onWritePixels(GrSurface* surface, |
565 int left, int top, int width, int height, | 566 int left, int top, int width, int height, |
566 GrPixelConfig config, const void* buffer, | 567 GrPixelConfig config, |
567 size_t rowBytes) { | 568 const SkTArray<SkMipMapLevel>& texels) { |
568 GrGLTexture* glTex = static_cast<GrGLTexture*>(surface->asTexture()); | 569 GrGLTexture* glTex = static_cast<GrGLTexture*>(surface->asTexture()); |
569 if (!glTex) { | 570 if (!glTex) { |
570 return false; | 571 return false; |
571 } | 572 } |
572 | 573 |
573 // OpenGL doesn't do sRGB <-> linear conversions when reading and writing pi
xels. | 574 // OpenGL doesn't do sRGB <-> linear conversions when reading and writing pi
xels. |
574 if (GrPixelConfigIsSRGB(surface->config()) != GrPixelConfigIsSRGB(config)) { | 575 if (GrPixelConfigIsSRGB(surface->config()) != GrPixelConfigIsSRGB(config)) { |
575 return false; | 576 return false; |
576 } | 577 } |
577 | 578 |
578 this->setScratchTextureUnit(); | 579 this->setScratchTextureUnit(); |
579 GL_CALL(BindTexture(glTex->target(), glTex->textureID())); | 580 GL_CALL(BindTexture(glTex->target(), glTex->textureID())); |
580 | 581 |
581 bool success = false; | 582 bool success = false; |
582 if (GrPixelConfigIsCompressed(glTex->desc().fConfig)) { | 583 if (GrPixelConfigIsCompressed(glTex->desc().fConfig)) { |
583 // We check that config == desc.fConfig in GrGLGpu::canWriteTexturePixel
s() | 584 // We check that config == desc.fConfig in GrGLGpu::canWriteTexturePixel
s() |
584 SkASSERT(config == glTex->desc().fConfig); | 585 SkASSERT(config == glTex->desc().fConfig); |
585 success = this->uploadCompressedTexData(glTex->desc(), glTex->target(),
buffer, false, left, | 586 success = this->uploadCompressedTexData(glTex->desc(), glTex->target(),
texels, false, |
586 top, width, height); | 587 left, top, width, height); |
587 } else { | 588 } else { |
588 success = this->uploadTexData(glTex->desc(), glTex->target(), false, lef
t, top, width, | 589 success = this->uploadTexData(glTex->desc(), glTex->target(), false, lef
t, top, width, |
589 height, config, buffer, rowBytes); | 590 height, config, texels); |
590 } | 591 } |
591 | 592 |
592 if (success) { | 593 return success; |
593 glTex->texturePriv().dirtyMipMaps(true); | |
594 return true; | |
595 } | |
596 | |
597 return false; | |
598 } | 594 } |
599 | 595 |
600 static inline GrGLenum check_alloc_error(const GrSurfaceDesc& desc, | 596 static inline GrGLenum check_alloc_error(const GrSurfaceDesc& desc, |
601 const GrGLInterface* interface) { | 597 const GrGLInterface* interface) { |
602 if (SkToBool(desc.fFlags & kCheckAllocation_GrSurfaceFlag)) { | 598 if (SkToBool(desc.fFlags & kCheckAllocation_GrSurfaceFlag)) { |
603 return GR_GL_GET_ERROR(interface); | 599 return GR_GL_GET_ERROR(interface); |
604 } else { | 600 } else { |
605 return CHECK_ALLOC_ERROR(interface); | 601 return CHECK_ALLOC_ERROR(interface); |
606 } | 602 } |
607 } | 603 } |
608 | 604 |
609 bool GrGLGpu::uploadTexData(const GrSurfaceDesc& desc, | 605 /** |
610 GrGLenum target, | 606 * Determines if TexStorage can be used when creating a texture. |
611 bool isNewTexture, | 607 * |
612 int left, int top, int width, int height, | 608 * @param caps The capabilities of the GL device. |
613 GrPixelConfig dataConfig, | 609 * @param standard The GL standard in use. |
614 const void* data, | 610 * @param desc The surface descriptor for the texture being created. |
615 size_t rowBytes) { | 611 */ |
616 SkASSERT(data || isNewTexture); | 612 static bool can_use_tex_storage(const GrGLCaps& caps, const GrGLStandard& standa
rd, |
617 | 613 const GrSurfaceDesc& desc) { |
618 // If we're uploading compressed data then we should be using uploadCompress
edTexData | 614 bool useTexStorage = caps.texStorageSupport(); |
619 SkASSERT(!GrPixelConfigIsCompressed(dataConfig)); | 615 if (useTexStorage && kGL_GrGLStandard == standard) { |
620 | |
621 size_t bpp = GrBytesPerPixel(dataConfig); | |
622 if (!GrSurfacePriv::AdjustWritePixelParams(desc.fWidth, desc.fHeight, bpp, &
left, &top, | |
623 &width, &height, &data, &rowBytes
)) { | |
624 return false; | |
625 } | |
626 size_t trimRowBytes = width * bpp; | |
627 | |
628 // in case we need a temporary, trimmed copy of the src pixels | |
629 #if defined(GOOGLE3) | |
630 // Stack frame size is limited in GOOGLE3. | |
631 SkAutoSMalloc<64 * 128> tempStorage; | |
632 #else | |
633 SkAutoSMalloc<128 * 128> tempStorage; | |
634 #endif | |
635 | |
636 // We currently lazily create MIPMAPs when the we see a draw with | |
637 // GrTextureParams::kMipMap_FilterMode. Using texture storage requires that
the | |
638 // MIP levels are all created when the texture is created. So for now we don
't use | |
639 // texture storage. | |
640 bool useTexStorage = false && | |
641 isNewTexture && | |
642 this->glCaps().texStorageSupport(); | |
643 | |
644 if (useTexStorage && kGL_GrGLStandard == this->glStandard()) { | |
645 // 565 is not a sized internal format on desktop GL. So on desktop with | 616 // 565 is not a sized internal format on desktop GL. So on desktop with |
646 // 565 we always use an unsized internal format to let the system pick | 617 // 565 we always use an unsized internal format to let the system pick |
647 // the best sized format to convert the 565 data to. Since TexStorage | 618 // the best sized format to convert the 565 data to. Since TexStorage |
648 // only allows sized internal formats we will instead use TexImage2D. | 619 // only allows sized internal formats we will instead use TexImage2D. |
649 useTexStorage = desc.fConfig != kRGB_565_GrPixelConfig; | 620 useTexStorage = desc.fConfig != kRGB_565_GrPixelConfig; |
650 } | 621 } |
651 | 622 |
652 GrGLenum internalFormat = 0x0; // suppress warning | 623 return useTexStorage; |
653 GrGLenum externalFormat = 0x0; // suppress warning | 624 } |
654 GrGLenum externalType = 0x0; // suppress warning | |
655 | 625 |
| 626 /** |
| 627 * Determines if sized internal formats are available for the texture being crea
ted. |
| 628 * |
| 629 * @param useTexStorage The result of a call to can_use_tex_storage(). |
| 630 * @param caps The capabilities of the GL device. |
| 631 * @param standard The GL standard in use. |
| 632 * @param version The GL version in use. |
| 633 * @param dataConfig The pixel configuration for the texture being created. |
| 634 */ |
| 635 static bool can_use_sized_format(bool useTexStorage, const GrGLCaps& caps, |
| 636 const GrGLStandard& standard, const GrGLVersion
& version, |
| 637 GrPixelConfig dataConfig) { |
656 // glTexStorage requires sized internal formats on both desktop and ES. ES2
requires an unsized | 638 // glTexStorage requires sized internal formats on both desktop and ES. ES2
requires an unsized |
657 // format for glTexImage, unlike ES3 and desktop. | 639 // format for glTexImage, unlike ES3 and desktop. |
658 bool useSizedFormat = useTexStorage; | 640 bool useSizedFormat = useTexStorage; |
659 if (kGL_GrGLStandard == this->glStandard() || | 641 if (kGL_GrGLStandard == standard || |
660 (this->glVersion() >= GR_GL_VER(3, 0) && | 642 (version >= GR_GL_VER(3, 0) && |
661 // ES3 only works with sized BGRA8 format if "GL_APPLE_texture_format_B
GRA8888" enabled | 643 // ES3 only works with sized BGRA8 format if "GL_APPLE_texture_format_B
GRA8888" enabled |
662 (kBGRA_8888_GrPixelConfig != dataConfig || !this->glCaps().bgraIsIntern
alFormat()))) { | 644 (kBGRA_8888_GrPixelConfig != dataConfig || !caps.bgraIsInternalFormat()
))) { |
663 useSizedFormat = true; | 645 useSizedFormat = true; |
664 } | 646 } |
665 | 647 |
666 if (!this->configToGLFormats(dataConfig, useSizedFormat, &internalFormat, | 648 return useSizedFormat; |
667 &externalFormat, &externalType)) { | 649 } |
668 return false; | |
669 } | |
670 | 650 |
671 /* | 651 /** |
672 * check whether to allocate a temporary buffer for flipping y or | 652 * Prior to a texture being created, the image may need to be flipped vertically
. This function |
673 * because our srcData has extra bytes past each row. If so, we need | 653 * prepares the texels for texture creation. |
674 * to trim those off here, since GL ES may not let us specify | 654 * |
675 * GL_UNPACK_ROW_LENGTH. | 655 * @param desc The surface descriptor for the texture being create
d. |
676 */ | 656 * @param caps The capabilities of the GL device. |
677 bool restoreGLRowLength = false; | 657 * @param interface The GL interface in use. |
678 bool swFlipY = false; | 658 * @param swFlipY Should software be used when flipping a texture ver
tically? |
679 bool glFlipY = false; | 659 * @param glFlipY Should GL be used when flipping a texture verticall
y? |
680 if (data) { | 660 * @param width The width of the texture in texels. |
681 if (kBottomLeft_GrSurfaceOrigin == desc.fOrigin) { | 661 * @param height The height of the texture in texels. |
682 if (this->glCaps().unpackFlipYSupport()) { | 662 * @param bpp The bits per pixel (or texel, really) of the textur
e. |
683 glFlipY = true; | 663 * @param texels An array of mipmap levels which contain the texel d
ata at that level. |
684 } else { | 664 * @param tempStorage In the case where the image needs to be flipped ver
tically, it will |
685 swFlipY = true; | 665 * use tempStorage as a buffer. |
686 } | 666 * @param restoreGLRowLength After the texture is created, will the GL row lengt
h unpacking need |
| 667 * to be restored? |
| 668 */ |
| 669 static void prepare_image_for_writing_to_texture(const GrSurfaceDesc& desc, cons
t GrGLCaps& caps, |
| 670 const GrGLInterface& interface,
bool swFlipY, |
| 671 bool glFlipY, int bpp, |
| 672 SkTArray<SkMipMapLevel>& texels
, |
| 673 #if defined(GOOGLE3) |
| 674 // Stack frame size is limited
in GOOGLE3. |
| 675 SkAutoSMalloc<64 * 128>& tempSt
orage, |
| 676 #else |
| 677 SkAutoSMalloc<128 * 128>& tempS
torage, |
| 678 #endif |
| 679 bool* restoreGLRowLength) { |
| 680 for (int currentMipLevel = 0; currentMipLevel < texels.count(); currentMipLe
vel++) { |
| 681 if (texels[currentMipLevel].fTexels == nullptr) { |
| 682 continue; |
687 } | 683 } |
688 if (this->glCaps().unpackRowLengthSupport() && !swFlipY) { | 684 |
| 685 const size_t trimRowBytes = texels[currentMipLevel].fWidth * bpp; |
| 686 |
| 687 /* |
| 688 * check whether to allocate a temporary buffer for flipping y or |
| 689 * because our srcData has extra bytes past each row. If so, we need |
| 690 * to trim those off here, since GL ES may not let us specify |
| 691 * GL_UNPACK_ROW_LENGTH. |
| 692 */ |
| 693 *restoreGLRowLength = false; |
| 694 |
| 695 const size_t rowBytes = texels[currentMipLevel].fRowBytes; |
| 696 if (caps.unpackRowLengthSupport() && !swFlipY) { |
689 // can't use this for flipping, only non-neg values allowed. :( | 697 // can't use this for flipping, only non-neg values allowed. :( |
690 if (rowBytes != trimRowBytes) { | 698 if (rowBytes != trimRowBytes) { |
691 GrGLint rowLength = static_cast<GrGLint>(rowBytes / bpp); | 699 GrGLint rowLength = static_cast<GrGLint>(rowBytes / bpp); |
692 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, rowLength)); | 700 GR_GL_CALL(&interface, PixelStorei(GR_GL_UNPACK_ROW_LENGTH, rowL
ength)); |
693 restoreGLRowLength = true; | 701 *restoreGLRowLength = true; |
694 } | 702 } |
695 } else { | 703 } else { |
696 if (trimRowBytes != rowBytes || swFlipY) { | 704 if (trimRowBytes != rowBytes || swFlipY) { |
| 705 const int height = texels[currentMipLevel].fHeight; |
697 // copy data into our new storage, skipping the trailing bytes | 706 // copy data into our new storage, skipping the trailing bytes |
698 size_t trimSize = height * trimRowBytes; | 707 const size_t trimSize = height * trimRowBytes; |
699 const char* src = (const char*)data; | 708 const char* src = (const char*)texels[currentMipLevel].fTexels; |
700 if (swFlipY) { | 709 if (swFlipY && height >= 1) { |
701 src += (height - 1) * rowBytes; | 710 src += (height - 1) * rowBytes; |
702 } | 711 } |
703 char* dst = (char*)tempStorage.reset(trimSize); | 712 char* dst = (char*)tempStorage.reset(trimSize); |
704 for (int y = 0; y < height; y++) { | 713 for (int y = 0; y < height; y++) { |
705 memcpy(dst, src, trimRowBytes); | 714 memcpy(dst, src, trimRowBytes); |
706 if (swFlipY) { | 715 if (swFlipY) { |
707 src -= rowBytes; | 716 src -= rowBytes; |
708 } else { | 717 } else { |
709 src += rowBytes; | 718 src += rowBytes; |
710 } | 719 } |
711 dst += trimRowBytes; | 720 dst += trimRowBytes; |
712 } | 721 } |
713 // now point data to our copied version | 722 // now point data to our copied version |
714 data = tempStorage.get(); | 723 texels[currentMipLevel] = SkMipMapLevel(tempStorage.get(), trimR
owBytes, |
| 724 texels[currentMipLevel].
fWidth, |
| 725 texels[currentMipLevel].
fHeight); |
715 } | 726 } |
716 } | 727 } |
717 if (glFlipY) { | 728 if (glFlipY) { |
718 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_TRUE)); | 729 GR_GL_CALL(&interface, PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_TRUE))
; |
719 } | 730 } |
720 GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, | 731 GR_GL_CALL(&interface, PixelStorei(GR_GL_UNPACK_ALIGNMENT, |
721 static_cast<GrGLint>(GrUnpackAlignment(dataConfig)))); | 732 static_cast<GrGLint>(GrUnpackAlignmen
t(desc.fConfig)))); |
722 } | 733 } |
| 734 } |
| 735 |
| 736 /** |
| 737 * Creates storage space for the texture and fills it with texels. |
| 738 * |
| 739 * @param desc The surface descriptor for the texture being created. |
| 740 * @param interface The GL interface in use. |
| 741 * @param useTexStorage The result of a call to can_use_tex_storage(). |
| 742 * @param internalFormat The data format used for the internal storage of the te
xture. |
| 743 * @param externalFormat The data format used for the external storage of the te
xture. |
| 744 * @param externalType The type of the data used for the external storage of t
he texture. |
| 745 * @param texels The texel data of the texture being created. |
| 746 * @param succeeded Set to true if allocating and populating the texture co
mpleted |
| 747 * without error. |
| 748 */ |
| 749 static void allocate_and_populate_uncompressed_texture(const GrSurfaceDesc& desc
, |
| 750 const GrGLInterface& inte
rface, |
| 751 GrGLenum target, |
| 752 bool useTexStorage, |
| 753 GrGLenum internalFormat, |
| 754 GrGLenum externalFormat, |
| 755 GrGLenum externalType, |
| 756 const SkTArray<SkMipMapLe
vel>& texels, |
| 757 bool* succeeded) { |
| 758 CLEAR_ERROR_BEFORE_ALLOC(&interface); |
| 759 if (useTexStorage) { |
| 760 // We never resize or change formats of textures. |
| 761 GL_ALLOC_CALL(&interface, |
| 762 TexStorage2D(target, |
| 763 texels.count(), |
| 764 internalFormat, |
| 765 desc.fWidth, desc.fHeight)); |
| 766 |
| 767 GrGLenum error = check_alloc_error(desc, &interface); |
| 768 if (error != GR_GL_NO_ERROR) { |
| 769 *succeeded = false; |
| 770 } else { |
| 771 for (int currentMipLevel = 0; currentMipLevel < texels.count(); curr
entMipLevel++) { |
| 772 const void* currentMipData = texels[currentMipLevel].fTexels; |
| 773 if (currentMipData == nullptr) { |
| 774 continue; |
| 775 } |
| 776 |
| 777 GR_GL_CALL(&interface, |
| 778 TexSubImage2D(target, |
| 779 currentMipLevel, |
| 780 0, // left |
| 781 0, // top |
| 782 texels[currentMipLevel].fWidth, |
| 783 texels[currentMipLevel].fHeight, |
| 784 externalFormat, externalType, |
| 785 currentMipData)); |
| 786 } |
| 787 *succeeded = true; |
| 788 } |
| 789 } else { |
| 790 *succeeded = true; |
| 791 for (int currentMipLevel = 0; currentMipLevel < texels.count(); currentM
ipLevel++) { |
| 792 GL_ALLOC_CALL(&interface, |
| 793 TexImage2D(target, |
| 794 currentMipLevel, |
| 795 internalFormat, |
| 796 texels[currentMipLevel].fWidth, |
| 797 texels[currentMipLevel].fHeight, |
| 798 0, // border |
| 799 externalFormat, externalType, |
| 800 texels[currentMipLevel].fTexels)); |
| 801 GrGLenum error = check_alloc_error(desc, &interface); |
| 802 if (error != GR_GL_NO_ERROR) { |
| 803 *succeeded = false; |
| 804 break; |
| 805 } |
| 806 } |
| 807 } |
| 808 } |
| 809 |
| 810 /** |
| 811 * Creates storage space for the texture and fills it with texels. |
| 812 * |
| 813 * @param desc The surface descriptor for the texture being created. |
| 814 * @param interface The GL interface in use. |
| 815 * @param useTexStorage The result of a call to can_use_tex_storage(). |
| 816 * @param internalFormat The data format used for the internal storage of the te
xture. |
| 817 * @param texels The texel data of the texture being created. |
| 818 */ |
| 819 static bool allocate_and_populate_compressed_texture(const GrSurfaceDesc& desc, |
| 820 const GrGLInterface& interf
ace, |
| 821 GrGLenum target, |
| 822 bool useTexStorage, GrGLenu
m internalFormat, |
| 823 const SkTArray<SkMipMapLeve
l>& texels) { |
| 824 CLEAR_ERROR_BEFORE_ALLOC(&interface); |
| 825 if (useTexStorage) { |
| 826 // We never resize or change formats of textures. |
| 827 GL_ALLOC_CALL(&interface, |
| 828 TexStorage2D(target, |
| 829 texels.count(), |
| 830 internalFormat, |
| 831 desc.fWidth, desc.fHeight)); |
| 832 GrGLenum error = check_alloc_error(desc, &interface); |
| 833 if (error != GR_GL_NO_ERROR) { |
| 834 return false; |
| 835 } else { |
| 836 for (int currentMipLevel = 0; currentMipLevel < texels.count(); curr
entMipLevel++) { |
| 837 const void* currentMipData = texels[currentMipLevel].fTexels; |
| 838 if (currentMipData == nullptr) { |
| 839 continue; |
| 840 } |
| 841 |
| 842 int width = texels[currentMipLevel].fWidth; |
| 843 int height = texels[currentMipLevel].fHeight; |
| 844 |
| 845 // Make sure that the width and height that we pass to OpenGL |
| 846 // is a multiple of the block size. |
| 847 size_t dataSize = GrCompressedFormatDataSize(desc.fConfig, width
, height); |
| 848 GR_GL_CALL(&interface, CompressedTexSubImage2D(target, |
| 849 currentMipLevel, |
| 850 0, // left |
| 851 0, // top |
| 852 width, |
| 853 height, |
| 854 internalFormat, S
kToInt(dataSize), |
| 855 currentMipData)); |
| 856 } |
| 857 } |
| 858 } else { |
| 859 for (int currentMipLevel = 0; currentMipLevel < texels.count(); currentM
ipLevel++) { |
| 860 |
| 861 int width = texels[currentMipLevel].fWidth; |
| 862 int height = texels[currentMipLevel].fHeight; |
| 863 |
| 864 // Make sure that the width and height that we pass to OpenGL |
| 865 // is a multiple of the block size. |
| 866 size_t dataSize = GrCompressedFormatDataSize(desc.fConfig, width, he
ight); |
| 867 |
| 868 GL_ALLOC_CALL(&interface, |
| 869 CompressedTexImage2D(target, |
| 870 texels.count(), |
| 871 internalFormat, |
| 872 width, |
| 873 height, |
| 874 0, // border |
| 875 SkToInt(dataSize), |
| 876 texels[currentMipLevel].fTexels))
; |
| 877 |
| 878 GrGLenum error = check_alloc_error(desc, &interface); |
| 879 if (error != GR_GL_NO_ERROR) { |
| 880 return false; |
| 881 } |
| 882 } |
| 883 } |
| 884 return true; |
| 885 } |
| 886 |
| 887 /** |
| 888 * After a texture is created, any state which was altered during its creation |
| 889 * needs to be restored. |
| 890 * |
| 891 * @param interface The GL interface to use. |
| 892 * @param caps The capabilities of the GL device. |
| 893 * @param restoreGLRowLength Should the row length unpacking be restored? |
| 894 * @param glFlipY Did GL flip the texture vertically? |
| 895 */ |
| 896 static void restore_pixelstore_state(const GrGLInterface& interface, const GrGLC
aps& caps, |
| 897 bool restoreGLRowLength, bool glFlipY) { |
| 898 if (restoreGLRowLength) { |
| 899 SkASSERT(caps.unpackRowLengthSupport()); |
| 900 GR_GL_CALL(&interface, PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); |
| 901 } |
| 902 if (glFlipY) { |
| 903 GR_GL_CALL(&interface, PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_FALSE)); |
| 904 } |
| 905 } |
| 906 |
| 907 bool GrGLGpu::uploadTexData(const GrSurfaceDesc& desc, |
| 908 GrGLenum target, |
| 909 bool isNewTexture, |
| 910 int left, int top, int width, int height, |
| 911 GrPixelConfig dataConfig, |
| 912 const SkTArray<SkMipMapLevel>& texels) { |
| 913 // If we're uploading compressed data then we should be using uploadCompress
edTexData |
| 914 SkASSERT(!GrPixelConfigIsCompressed(dataConfig)); |
| 915 |
| 916 SkTArray<SkMipMapLevel> texelsCopy(texels); |
| 917 |
| 918 for (int currentMipLevel = texelsCopy.count() - 1; currentMipLevel >= 0; cur
rentMipLevel--) { |
| 919 //SkASSERT(texelsCopy[currentMipLevel].fTexels || isNewTexture); |
| 920 } |
| 921 |
| 922 |
| 923 const GrGLInterface* interface = this->glInterface(); |
| 924 const GrGLCaps& caps = this->glCaps(); |
| 925 GrGLStandard standard = this->glStandard(); |
| 926 GrGLVersion version = this->glVersion(); |
| 927 |
| 928 size_t bpp = GrBytesPerPixel(dataConfig); |
| 929 for (int currentMipLevel = 0; currentMipLevel < texels.count(); currentMipLe
vel++) { |
| 930 if (texelsCopy[currentMipLevel].fTexels == nullptr) { |
| 931 continue; |
| 932 } |
| 933 |
| 934 if (texelsCopy[currentMipLevel].fHeight > SK_MaxS32 |
| 935 || texelsCopy[currentMipLevel].fWidth > SK_MaxS32) { |
| 936 return false; |
| 937 } |
| 938 int currentMipHeight = texelsCopy[currentMipLevel].fHeight; |
| 939 int currentMipWidth = texelsCopy[currentMipLevel].fWidth; |
| 940 if (!GrSurfacePriv::AdjustWritePixelParams(desc.fWidth, desc.fHeight, bp
p, &left, &top, |
| 941 ¤tMipWidth, |
| 942 ¤tMipHeight, |
| 943 &texelsCopy[currentMipLevel].fTex
els, |
| 944 &texelsCopy[currentMipLevel].fRow
Bytes)) { |
| 945 return false; |
| 946 } |
| 947 if (currentMipWidth < 0 || currentMipHeight < 0) { |
| 948 return false; |
| 949 } |
| 950 texelsCopy[currentMipLevel].fWidth = currentMipWidth; |
| 951 texelsCopy[currentMipLevel].fHeight = currentMipHeight; |
| 952 } |
| 953 |
| 954 bool useTexStorage = can_use_tex_storage(caps, standard, desc); |
| 955 bool useSizedFormat = can_use_sized_format(useTexStorage, caps, standard, ve
rsion, dataConfig); |
| 956 |
| 957 GrGLenum internalFormat = 0x0; // suppress warning |
| 958 GrGLenum externalFormat = 0x0; // suppress warning |
| 959 GrGLenum externalType = 0x0; // suppress warning |
| 960 |
| 961 if (!this->configToGLFormats(dataConfig, useSizedFormat, &internalFormat, |
| 962 &externalFormat, &externalType)) { |
| 963 return false; |
| 964 } |
| 965 |
| 966 bool swFlipY = false; |
| 967 bool glFlipY = false; |
| 968 |
| 969 if (kBottomLeft_GrSurfaceOrigin == desc.fOrigin) { |
| 970 if (caps.unpackFlipYSupport()) { |
| 971 glFlipY = true; |
| 972 } else { |
| 973 swFlipY = true; |
| 974 } |
| 975 } |
| 976 |
| 977 bool restoreGLRowLength = false; |
| 978 |
| 979 // in case we need a temporary, trimmed copy of the src pixels |
| 980 #if defined(GOOGLE3) |
| 981 // Stack frame size is limited in GOOGLE3. |
| 982 SkAutoSMalloc<64 * 128> tempStorage; |
| 983 #else |
| 984 SkAutoSMalloc<128 * 128> tempStorage; |
| 985 #endif |
| 986 |
| 987 prepare_image_for_writing_to_texture(desc, caps, *interface, swFlipY, glFlip
Y, bpp, texelsCopy, |
| 988 tempStorage, &restoreGLRowLength); |
723 bool succeeded = true; | 989 bool succeeded = true; |
724 if (isNewTexture && | 990 if (isNewTexture && |
725 0 == left && 0 == top && | 991 0 == left && 0 == top && |
726 desc.fWidth == width && desc.fHeight == height) { | 992 desc.fWidth == width && desc.fHeight == height) { |
727 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); | 993 allocate_and_populate_uncompressed_texture(desc, *interface, useTexStora
ge, internalFormat, |
728 if (useTexStorage) { | 994 externalFormat, externalType,
target, |
729 // We never resize or change formats of textures. | 995 texelsCopy, &succeeded); |
730 GL_ALLOC_CALL(this->glInterface(), | |
731 TexStorage2D(target, | |
732 1, // levels | |
733 internalFormat, | |
734 desc.fWidth, desc.fHeight)); | |
735 } else { | |
736 GL_ALLOC_CALL(this->glInterface(), | |
737 TexImage2D(target, | |
738 0, // level | |
739 internalFormat, | |
740 desc.fWidth, desc.fHeight, | |
741 0, // border | |
742 externalFormat, externalType, | |
743 data)); | |
744 } | |
745 GrGLenum error = check_alloc_error(desc, this->glInterface()); | |
746 if (error != GR_GL_NO_ERROR) { | |
747 succeeded = false; | |
748 } else { | |
749 // if we have data and we used TexStorage to create the texture, we | |
750 // now upload with TexSubImage. | |
751 if (data && useTexStorage) { | |
752 GL_CALL(TexSubImage2D(target, | |
753 0, // level | |
754 left, top, | |
755 width, height, | |
756 externalFormat, externalType, | |
757 data)); | |
758 } | |
759 } | |
760 } else { | 996 } else { |
761 if (swFlipY || glFlipY) { | 997 if (swFlipY || glFlipY) { |
762 top = desc.fHeight - (top + height); | 998 top = desc.fHeight - (top + height); |
763 } | 999 } |
764 GL_CALL(TexSubImage2D(target, | 1000 for (int currentMipLevel = 0; currentMipLevel < texelsCopy.count(); curr
entMipLevel++) { |
765 0, // level | 1001 if (texelsCopy[currentMipLevel].fTexels == nullptr) { |
766 left, top, | 1002 continue; |
767 width, height, | 1003 } |
768 externalFormat, externalType, data)); | 1004 |
769 } | 1005 GL_CALL(TexSubImage2D(target, |
770 | 1006 currentMipLevel, |
771 if (restoreGLRowLength) { | 1007 left, top, |
772 SkASSERT(this->glCaps().unpackRowLengthSupport()); | 1008 texelsCopy[currentMipLevel].fWidth, |
773 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); | 1009 texelsCopy[currentMipLevel].fHeight, |
774 } | 1010 externalFormat, externalType, |
775 if (glFlipY) { | 1011 texelsCopy[currentMipLevel].fTexels)); |
776 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_FALSE)); | 1012 } |
777 } | 1013 } |
| 1014 |
| 1015 restore_pixelstore_state(*interface, caps, restoreGLRowLength, glFlipY); |
| 1016 |
778 return succeeded; | 1017 return succeeded; |
779 } | 1018 } |
780 | 1019 |
781 // TODO: This function is using a lot of wonky semantics like, if width == -1 | 1020 // TODO: This function is using a lot of wonky semantics like, if width == -1 |
782 // then set width = desc.fWdith ... blah. A better way to do it might be to | 1021 // then set width = desc.fWdith ... blah. A better way to do it might be to |
783 // create a CompressedTexData struct that takes a desc/ptr and figures out | 1022 // create a CompressedTexData struct that takes a desc/ptr and figures out |
784 // the proper upload semantics. Then users can construct this function how they | 1023 // the proper upload semantics. Then users can construct this function how they |
785 // see fit if they want to go against the "standard" way to do it. | 1024 // see fit if they want to go against the "standard" way to do it. |
786 bool GrGLGpu::uploadCompressedTexData(const GrSurfaceDesc& desc, | 1025 bool GrGLGpu::uploadCompressedTexData(const GrSurfaceDesc& desc, |
787 GrGLenum target, | 1026 GrGLenum target, |
788 const void* data, | 1027 const SkTArray<SkMipMapLevel>& texels, |
789 bool isNewTexture, | 1028 bool isNewTexture, |
790 int left, int top, int width, int height)
{ | 1029 int left, int top, int width, int height)
{ |
791 SkASSERT(data || isNewTexture); | 1030 SkASSERT(isNewTexture); |
792 | 1031 |
793 // No support for software flip y, yet... | 1032 // No support for software flip y, yet... |
794 SkASSERT(kBottomLeft_GrSurfaceOrigin != desc.fOrigin); | 1033 SkASSERT(kBottomLeft_GrSurfaceOrigin != desc.fOrigin); |
795 | 1034 |
| 1035 const GrGLInterface* interface = this->glInterface(); |
| 1036 const GrGLCaps& caps = this->glCaps(); |
| 1037 GrGLStandard standard = this->glStandard(); |
| 1038 |
796 if (-1 == width) { | 1039 if (-1 == width) { |
797 width = desc.fWidth; | 1040 width = desc.fWidth; |
798 } | 1041 } |
799 #ifdef SK_DEBUG | 1042 #ifdef SK_DEBUG |
800 else { | 1043 else { |
801 SkASSERT(width <= desc.fWidth); | 1044 SkASSERT(width <= desc.fWidth); |
802 } | 1045 } |
803 #endif | 1046 #endif |
804 | 1047 |
805 if (-1 == height) { | 1048 if (-1 == height) { |
806 height = desc.fHeight; | 1049 height = desc.fHeight; |
807 } | 1050 } |
808 #ifdef SK_DEBUG | 1051 #ifdef SK_DEBUG |
809 else { | 1052 else { |
810 SkASSERT(height <= desc.fHeight); | 1053 SkASSERT(height <= desc.fHeight); |
811 } | 1054 } |
812 #endif | 1055 #endif |
813 | 1056 |
814 // Make sure that the width and height that we pass to OpenGL | 1057 bool useTexStorage = can_use_tex_storage(caps, standard, desc); |
815 // is a multiple of the block size. | |
816 size_t dataSize = GrCompressedFormatDataSize(desc.fConfig, width, height); | |
817 | 1058 |
818 // We only need the internal format for compressed 2D textures. | 1059 // We only need the internal format for compressed 2D textures. |
819 GrGLenum internalFormat = 0; | 1060 GrGLenum internalFormat = 0; |
820 if (!this->configToGLFormats(desc.fConfig, false, &internalFormat, nullptr,
nullptr)) { | 1061 if (!this->configToGLFormats(desc.fConfig, false, &internalFormat, nullptr,
nullptr)) { |
821 return false; | 1062 return false; |
822 } | 1063 } |
823 | 1064 |
824 if (isNewTexture) { | 1065 if (isNewTexture) { |
825 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); | 1066 return allocate_and_populate_compressed_texture(desc, *interface, target
, useTexStorage, |
826 GL_ALLOC_CALL(this->glInterface(), | 1067 internalFormat, texels); |
827 CompressedTexImage2D(target, | |
828 0, // level | |
829 internalFormat, | |
830 width, height, | |
831 0, // border | |
832 SkToInt(dataSize), | |
833 data)); | |
834 GrGLenum error = check_alloc_error(desc, this->glInterface()); | |
835 if (error != GR_GL_NO_ERROR) { | |
836 return false; | |
837 } | |
838 } else { | 1068 } else { |
839 // Paletted textures can't be updated. | 1069 // Paletted textures can't be updated. |
840 if (GR_GL_PALETTE8_RGBA8 == internalFormat) { | 1070 if (GR_GL_PALETTE8_RGBA8 == internalFormat) { |
841 return false; | 1071 return false; |
842 } | 1072 } |
843 GL_CALL(CompressedTexSubImage2D(target, | 1073 for (int currentMipLevel = 0; currentMipLevel < texels.count(); currentM
ipLevel++) { |
844 0, // level | 1074 if (texels[currentMipLevel].fTexels == nullptr) { |
845 left, top, | 1075 continue; |
846 width, height, | 1076 } |
847 internalFormat, | 1077 |
848 SkToInt(dataSize), | 1078 // Make sure that the width and height that we pass to OpenGL |
849 data)); | 1079 // is a multiple of the block size. |
| 1080 size_t dataSize = GrCompressedFormatDataSize(desc.fConfig, |
| 1081 texels[currentMipLevel]
.fWidth, |
| 1082 texels[currentMipLevel]
.fHeight); |
| 1083 GL_CALL(CompressedTexSubImage2D(target, |
| 1084 currentMipLevel, |
| 1085 left, top, |
| 1086 texels[currentMipLevel].fWidth, |
| 1087 texels[currentMipLevel].fHeight, |
| 1088 internalFormat, |
| 1089 dataSize, |
| 1090 texels[currentMipLevel].fTexels)); |
| 1091 } |
850 } | 1092 } |
851 | 1093 |
852 return true; | 1094 return true; |
853 } | 1095 } |
854 | 1096 |
855 static bool renderbuffer_storage_msaa(const GrGLContext& ctx, | 1097 static bool renderbuffer_storage_msaa(const GrGLContext& ctx, |
856 int sampleCount, | 1098 int sampleCount, |
857 GrGLenum format, | 1099 GrGLenum format, |
858 int width, int height) { | 1100 int width, int height) { |
859 CLEAR_ERROR_BEFORE_ALLOC(ctx.interface()); | 1101 CLEAR_ERROR_BEFORE_ALLOC(ctx.interface()); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1008 // SkDEBUGFAIL("null texture"); | 1250 // SkDEBUGFAIL("null texture"); |
1009 return nullptr; | 1251 return nullptr; |
1010 } | 1252 } |
1011 | 1253 |
1012 #if 0 && defined(SK_DEBUG) | 1254 #if 0 && defined(SK_DEBUG) |
1013 static size_t as_size_t(int x) { | 1255 static size_t as_size_t(int x) { |
1014 return x; | 1256 return x; |
1015 } | 1257 } |
1016 #endif | 1258 #endif |
1017 | 1259 |
| 1260 static GrGLTexture::IDDesc generate_and_bind_gl_texture(const GrGLInterface* int
erface, |
| 1261 GrGpuResource::LifeCycle
lifeCycle) { |
| 1262 GrGLTexture::IDDesc idDesc; |
| 1263 GR_GL_CALL(interface, GenTextures(1, &idDesc.fTextureID)); |
| 1264 idDesc.fLifeCycle = lifeCycle; |
| 1265 // We only support GL_TEXTURE_2D at the moment. |
| 1266 idDesc.fTarget = GR_GL_TEXTURE_2D; |
| 1267 return idDesc; |
| 1268 } |
| 1269 |
| 1270 static GrGLTexture::TexParams set_initial_texture_params(const GrGLInterface* in
terface, |
| 1271 GrGLTexture::IDDesc idD
esc) { |
| 1272 // Some drivers like to know filter/wrap before seeing glTexImage2D. Some |
| 1273 // drivers have a bug where an FBO won't be complete if it includes a |
| 1274 // texture that is not mipmap complete (considering the filter in use). |
| 1275 GrGLTexture::TexParams initialTexParams; |
| 1276 // we only set a subset here so invalidate first |
| 1277 initialTexParams.invalidate(); |
| 1278 initialTexParams.fMinFilter = GR_GL_NEAREST; |
| 1279 initialTexParams.fMagFilter = GR_GL_NEAREST; |
| 1280 initialTexParams.fWrapS = GR_GL_CLAMP_TO_EDGE; |
| 1281 initialTexParams.fWrapT = GR_GL_CLAMP_TO_EDGE; |
| 1282 GR_GL_CALL(interface, TexParameteri(idDesc.fTarget, |
| 1283 GR_GL_TEXTURE_MAG_FILTER, |
| 1284 initialTexParams.fMagFilter)); |
| 1285 GR_GL_CALL(interface, TexParameteri(idDesc.fTarget, |
| 1286 GR_GL_TEXTURE_MIN_FILTER, |
| 1287 initialTexParams.fMinFilter)); |
| 1288 GR_GL_CALL(interface, TexParameteri(idDesc.fTarget, |
| 1289 GR_GL_TEXTURE_WRAP_S, |
| 1290 initialTexParams.fWrapS)); |
| 1291 GR_GL_CALL(interface, TexParameteri(idDesc.fTarget, |
| 1292 GR_GL_TEXTURE_WRAP_T, |
| 1293 initialTexParams.fWrapT)); |
| 1294 return initialTexParams; |
| 1295 } |
| 1296 |
1018 GrTexture* GrGLGpu::onCreateTexture(const GrSurfaceDesc& desc, | 1297 GrTexture* GrGLGpu::onCreateTexture(const GrSurfaceDesc& desc, |
1019 GrGpuResource::LifeCycle lifeCycle, | 1298 GrGpuResource::LifeCycle lifeCycle, |
1020 const void* srcData, size_t rowBytes) { | 1299 const SkTArray<SkMipMapLevel>& texels) { |
1021 // We fail if the MSAA was requested and is not available. | 1300 // We fail if the MSAA was requested and is not available. |
1022 if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && desc.fSampleC
nt) { | 1301 if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && desc.fSampleC
nt) { |
1023 //SkDebugf("MSAA RT requested but not supported on this platform."); | 1302 //SkDebugf("MSAA RT requested but not supported on this platform."); |
1024 return return_null_texture(); | 1303 return return_null_texture(); |
1025 } | 1304 } |
1026 | 1305 |
1027 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); | 1306 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); |
1028 | 1307 |
1029 GrGLTexture::IDDesc idDesc; | 1308 GrGLTexture::IDDesc idDesc = generate_and_bind_gl_texture(this->glInterface(
), lifeCycle); |
1030 GL_CALL(GenTextures(1, &idDesc.fTextureID)); | |
1031 idDesc.fLifeCycle = lifeCycle; | |
1032 // We only support GL_TEXTURE_2D at the moment. | |
1033 idDesc.fTarget = GR_GL_TEXTURE_2D; | |
1034 | |
1035 if (!idDesc.fTextureID) { | 1309 if (!idDesc.fTextureID) { |
1036 return return_null_texture(); | 1310 return return_null_texture(); |
1037 } | 1311 } |
1038 | 1312 |
1039 this->setScratchTextureUnit(); | 1313 this->setScratchTextureUnit(); |
1040 GL_CALL(BindTexture(idDesc.fTarget, idDesc.fTextureID)); | 1314 GL_CALL(BindTexture(idDesc.fTarget, idDesc.fTextureID)); |
1041 | 1315 |
1042 if (renderTarget && this->glCaps().textureUsageSupport()) { | 1316 if (renderTarget && this->glCaps().textureUsageSupport()) { |
1043 // provides a hint about how this texture will be used | 1317 // provides a hint about how this texture will be used |
1044 GL_CALL(TexParameteri(idDesc.fTarget, | 1318 GL_CALL(TexParameteri(idDesc.fTarget, |
1045 GR_GL_TEXTURE_USAGE, | 1319 GR_GL_TEXTURE_USAGE, |
1046 GR_GL_FRAMEBUFFER_ATTACHMENT)); | 1320 GR_GL_FRAMEBUFFER_ATTACHMENT)); |
1047 } | 1321 } |
1048 | 1322 |
1049 // Some drivers like to know filter/wrap before seeing glTexImage2D. Some | 1323 GrGLTexture::TexParams initialTexParams = set_initial_texture_params(this->g
lInterface(), |
1050 // drivers have a bug where an FBO won't be complete if it includes a | 1324 idDesc)
; |
1051 // texture that is not mipmap complete (considering the filter in use). | 1325 |
1052 GrGLTexture::TexParams initialTexParams; | 1326 if (!this->uploadTexData(desc, GR_GL_TEXTURE_2D, true, 0, 0, |
1053 // we only set a subset here so invalidate first | |
1054 initialTexParams.invalidate(); | |
1055 initialTexParams.fMinFilter = GR_GL_NEAREST; | |
1056 initialTexParams.fMagFilter = GR_GL_NEAREST; | |
1057 initialTexParams.fWrapS = GR_GL_CLAMP_TO_EDGE; | |
1058 initialTexParams.fWrapT = GR_GL_CLAMP_TO_EDGE; | |
1059 GL_CALL(TexParameteri(idDesc.fTarget, | |
1060 GR_GL_TEXTURE_MAG_FILTER, | |
1061 initialTexParams.fMagFilter)); | |
1062 GL_CALL(TexParameteri(idDesc.fTarget, | |
1063 GR_GL_TEXTURE_MIN_FILTER, | |
1064 initialTexParams.fMinFilter)); | |
1065 GL_CALL(TexParameteri(idDesc.fTarget, | |
1066 GR_GL_TEXTURE_WRAP_S, | |
1067 initialTexParams.fWrapS)); | |
1068 GL_CALL(TexParameteri(idDesc.fTarget, | |
1069 GR_GL_TEXTURE_WRAP_T, | |
1070 initialTexParams.fWrapT)); | |
1071 if (!this->uploadTexData(desc, idDesc.fTarget, true, 0, 0, | |
1072 desc.fWidth, desc.fHeight, | 1327 desc.fWidth, desc.fHeight, |
1073 desc.fConfig, srcData, rowBytes)) { | 1328 desc.fConfig, texels)) { |
1074 GL_CALL(DeleteTextures(1, &idDesc.fTextureID)); | 1329 GL_CALL(DeleteTextures(1, &idDesc.fTextureID)); |
1075 return return_null_texture(); | 1330 return return_null_texture(); |
1076 } | 1331 } |
1077 | 1332 |
1078 GrGLTexture* tex; | 1333 GrGLTexture* tex; |
1079 if (renderTarget) { | 1334 if (renderTarget) { |
1080 // unbind the texture from the texture unit before binding it to the fra
me buffer | 1335 // unbind the texture from the texture unit before binding it to the fra
me buffer |
1081 GL_CALL(BindTexture(idDesc.fTarget, 0)); | 1336 GL_CALL(BindTexture(idDesc.fTarget, 0)); |
1082 GrGLRenderTarget::IDDesc rtIDDesc; | 1337 GrGLRenderTarget::IDDesc rtIDDesc; |
1083 | 1338 |
1084 if (!this->createRenderTargetObjects(desc, lifeCycle, idDesc.fTextureID,
idDesc.fTarget, | 1339 if (!this->createRenderTargetObjects(desc, lifeCycle, idDesc.fTextureID,
idDesc.fTarget, |
1085 &rtIDDesc)) { | 1340 &rtIDDesc)) { |
1086 GL_CALL(DeleteTextures(1, &idDesc.fTextureID)); | 1341 GL_CALL(DeleteTextures(1, &idDesc.fTextureID)); |
1087 return return_null_texture(); | 1342 return return_null_texture(); |
1088 } | 1343 } |
1089 tex = new GrGLTextureRenderTarget(this, desc, idDesc, rtIDDesc); | 1344 tex = new GrGLTextureRenderTarget(this, desc, idDesc, rtIDDesc); |
1090 } else { | 1345 } else { |
1091 tex = new GrGLTexture(this, desc, idDesc); | 1346 tex = new GrGLTexture(this, desc, idDesc); |
1092 } | 1347 } |
1093 tex->setCachedTexParams(initialTexParams, this->getResetTimestamp()); | 1348 tex->setCachedTexParams(initialTexParams, this->getResetTimestamp()); |
1094 #ifdef TRACE_TEXTURE_CREATION | 1349 #ifdef TRACE_TEXTURE_CREATION |
1095 SkDebugf("--- new texture [%d] size=(%d %d) config=%d\n", | 1350 SkDebugf("--- new texture [%d] size=(%d %d) config=%d\n", |
1096 glTexDesc.fTextureID, desc.fWidth, desc.fHeight, desc.fConfig); | 1351 glTexDesc.fTextureID, desc.fWidth, desc.fHeight, desc.fConfig); |
1097 #endif | 1352 #endif |
1098 return tex; | 1353 return tex; |
1099 } | 1354 } |
1100 | 1355 |
1101 GrTexture* GrGLGpu::onCreateCompressedTexture(const GrSurfaceDesc& desc, | 1356 GrTexture* GrGLGpu::onCreateCompressedTexture(const GrSurfaceDesc& desc, |
1102 GrGpuResource::LifeCycle lifeCycle
, | 1357 GrGpuResource::LifeCycle lifeCycle
, |
1103 const void* srcData) { | 1358 const SkTArray<SkMipMapLevel>& tex
els) { |
1104 // Make sure that we're not flipping Y. | 1359 // Make sure that we're not flipping Y. |
1105 if (kBottomLeft_GrSurfaceOrigin == desc.fOrigin) { | 1360 if (kBottomLeft_GrSurfaceOrigin == desc.fOrigin) { |
1106 return return_null_texture(); | 1361 return return_null_texture(); |
1107 } | 1362 } |
1108 | 1363 |
1109 GrGLTexture::IDDesc idDesc; | 1364 GrGLTexture::IDDesc idDesc = generate_and_bind_gl_texture(this->glInterface(
), lifeCycle); |
1110 GL_CALL(GenTextures(1, &idDesc.fTextureID)); | |
1111 idDesc.fLifeCycle = lifeCycle; | |
1112 // We only support GL_TEXTURE_2D at the moment. | |
1113 idDesc.fTarget = GR_GL_TEXTURE_2D; | |
1114 | |
1115 if (!idDesc.fTextureID) { | 1365 if (!idDesc.fTextureID) { |
1116 return return_null_texture(); | 1366 return return_null_texture(); |
1117 } | 1367 } |
1118 | 1368 |
1119 this->setScratchTextureUnit(); | 1369 this->setScratchTextureUnit(); |
1120 GL_CALL(BindTexture(idDesc.fTarget, idDesc.fTextureID)); | 1370 GL_CALL(BindTexture(idDesc.fTarget, idDesc.fTextureID)); |
1121 | 1371 |
1122 // Some drivers like to know filter/wrap before seeing glTexImage2D. Some | 1372 GrGLTexture::TexParams initialTexParams = set_initial_texture_params(this->g
lInterface(), |
1123 // drivers have a bug where an FBO won't be complete if it includes a | 1373 idDesc)
; |
1124 // texture that is not mipmap complete (considering the filter in use). | |
1125 GrGLTexture::TexParams initialTexParams; | |
1126 // we only set a subset here so invalidate first | |
1127 initialTexParams.invalidate(); | |
1128 initialTexParams.fMinFilter = GR_GL_NEAREST; | |
1129 initialTexParams.fMagFilter = GR_GL_NEAREST; | |
1130 initialTexParams.fWrapS = GR_GL_CLAMP_TO_EDGE; | |
1131 initialTexParams.fWrapT = GR_GL_CLAMP_TO_EDGE; | |
1132 GL_CALL(TexParameteri(idDesc.fTarget, | |
1133 GR_GL_TEXTURE_MAG_FILTER, | |
1134 initialTexParams.fMagFilter)); | |
1135 GL_CALL(TexParameteri(idDesc.fTarget, | |
1136 GR_GL_TEXTURE_MIN_FILTER, | |
1137 initialTexParams.fMinFilter)); | |
1138 GL_CALL(TexParameteri(idDesc.fTarget, | |
1139 GR_GL_TEXTURE_WRAP_S, | |
1140 initialTexParams.fWrapS)); | |
1141 GL_CALL(TexParameteri(idDesc.fTarget, | |
1142 GR_GL_TEXTURE_WRAP_T, | |
1143 initialTexParams.fWrapT)); | |
1144 | 1374 |
1145 if (!this->uploadCompressedTexData(desc, idDesc.fTarget, srcData)) { | 1375 if (!this->uploadCompressedTexData(desc, idDesc.fTarget, texels)) { |
1146 GL_CALL(DeleteTextures(1, &idDesc.fTextureID)); | 1376 GL_CALL(DeleteTextures(1, &idDesc.fTextureID)); |
1147 return return_null_texture(); | 1377 return return_null_texture(); |
1148 } | 1378 } |
1149 | 1379 |
1150 GrGLTexture* tex; | 1380 GrGLTexture* tex; |
1151 tex = new GrGLTexture(this, desc, idDesc); | 1381 tex = new GrGLTexture(this, desc, idDesc); |
1152 tex->setCachedTexParams(initialTexParams, this->getResetTimestamp()); | 1382 tex->setCachedTexParams(initialTexParams, this->getResetTimestamp()); |
1153 #ifdef TRACE_TEXTURE_CREATION | 1383 #ifdef TRACE_TEXTURE_CREATION |
1154 SkDebugf("--- new compressed texture [%d] size=(%d %d) config=%d\n", | 1384 SkDebugf("--- new compressed texture [%d] size=(%d %d) config=%d\n", |
1155 glTexDesc.fTextureID, desc.fWidth, desc.fHeight, desc.fConfig); | 1385 glTexDesc.fTextureID, desc.fWidth, desc.fHeight, desc.fConfig); |
(...skipping 1545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2701 *internalFormat = GR_GL_ALPHA; | 2931 *internalFormat = GR_GL_ALPHA; |
2702 } | 2932 } |
2703 *externalFormat = GR_GL_ALPHA; | 2933 *externalFormat = GR_GL_ALPHA; |
2704 } | 2934 } |
2705 if (kGL_GrGLStandard == this->glStandard() || this->glVersion() >= G
R_GL_VER(3, 0)) { | 2935 if (kGL_GrGLStandard == this->glStandard() || this->glVersion() >= G
R_GL_VER(3, 0)) { |
2706 *externalType = GR_GL_HALF_FLOAT; | 2936 *externalType = GR_GL_HALF_FLOAT; |
2707 } else { | 2937 } else { |
2708 *externalType = GR_GL_HALF_FLOAT_OES; | 2938 *externalType = GR_GL_HALF_FLOAT_OES; |
2709 } | 2939 } |
2710 break; | 2940 break; |
2711 | 2941 |
2712 case kRGBA_half_GrPixelConfig: | 2942 case kRGBA_half_GrPixelConfig: |
2713 *internalFormat = GR_GL_RGBA16F; | 2943 *internalFormat = GR_GL_RGBA16F; |
2714 *externalFormat = GR_GL_RGBA; | 2944 *externalFormat = GR_GL_RGBA; |
2715 if (kGL_GrGLStandard == this->glStandard() || this->glVersion() >= G
R_GL_VER(3, 0)) { | 2945 if (kGL_GrGLStandard == this->glStandard() || this->glVersion() >= G
R_GL_VER(3, 0)) { |
2716 *externalType = GR_GL_HALF_FLOAT; | 2946 *externalType = GR_GL_HALF_FLOAT; |
2717 } else { | 2947 } else { |
2718 *externalType = GR_GL_HALF_FLOAT_OES; | 2948 *externalType = GR_GL_HALF_FLOAT_OES; |
2719 } | 2949 } |
2720 break; | 2950 break; |
2721 | 2951 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2827 viewport->fWidth = surface->width(); | 3057 viewport->fWidth = surface->width(); |
2828 viewport->fHeight = surface->height(); | 3058 viewport->fHeight = surface->height(); |
2829 } else { | 3059 } else { |
2830 fStats.incRenderTargetBinds(); | 3060 fStats.incRenderTargetBinds(); |
2831 GR_GL_CALL(this->glInterface(), BindFramebuffer(fboTarget, rt->renderFBO
ID())); | 3061 GR_GL_CALL(this->glInterface(), BindFramebuffer(fboTarget, rt->renderFBO
ID())); |
2832 *viewport = rt->getViewport(); | 3062 *viewport = rt->getViewport(); |
2833 } | 3063 } |
2834 } | 3064 } |
2835 | 3065 |
2836 void GrGLGpu::unbindTextureFBOForCopy(GrGLenum fboTarget, GrSurface* surface) { | 3066 void GrGLGpu::unbindTextureFBOForCopy(GrGLenum fboTarget, GrSurface* surface) { |
2837 // bindSurfaceFBOForCopy temporarily binds textures that are not render targ
ets to | 3067 // bindSurfaceFBOForCopy temporarily binds textures that are not render targ
ets to |
2838 if (!surface->asRenderTarget()) { | 3068 if (!surface->asRenderTarget()) { |
2839 SkASSERT(surface->asTexture()); | 3069 SkASSERT(surface->asTexture()); |
2840 GrGLenum textureTarget = static_cast<GrGLTexture*>(surface->asTexture())
->target(); | 3070 GrGLenum textureTarget = static_cast<GrGLTexture*>(surface->asTexture())
->target(); |
2841 GR_GL_CALL(this->glInterface(), FramebufferTexture2D(fboTarget, | 3071 GR_GL_CALL(this->glInterface(), FramebufferTexture2D(fboTarget, |
2842 GR_GL_COLOR_ATTACHM
ENT0, | 3072 GR_GL_COLOR_ATTACHM
ENT0, |
2843 textureTarget, | 3073 textureTarget, |
2844 0, | 3074 0, |
2845 0)); | 3075 0)); |
2846 } | 3076 } |
2847 } | 3077 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2899 } | 3129 } |
2900 | 3130 |
2901 bool GrGLGpu::onCopySurface(GrSurface* dst, | 3131 bool GrGLGpu::onCopySurface(GrSurface* dst, |
2902 GrSurface* src, | 3132 GrSurface* src, |
2903 const SkIRect& srcRect, | 3133 const SkIRect& srcRect, |
2904 const SkIPoint& dstPoint) { | 3134 const SkIPoint& dstPoint) { |
2905 if (src->asTexture() && dst->asRenderTarget()) { | 3135 if (src->asTexture() && dst->asRenderTarget()) { |
2906 this->copySurfaceAsDraw(dst, src, srcRect, dstPoint); | 3136 this->copySurfaceAsDraw(dst, src, srcRect, dstPoint); |
2907 return true; | 3137 return true; |
2908 } | 3138 } |
2909 | 3139 |
2910 if (can_copy_texsubimage(dst, src, this)) { | 3140 if (can_copy_texsubimage(dst, src, this)) { |
2911 this->copySurfaceAsCopyTexSubImage(dst, src, srcRect, dstPoint); | 3141 this->copySurfaceAsCopyTexSubImage(dst, src, srcRect, dstPoint); |
2912 return true; | 3142 return true; |
2913 } | 3143 } |
2914 | 3144 |
2915 if (can_blit_framebuffer(dst, src, this)) { | 3145 if (can_blit_framebuffer(dst, src, this)) { |
2916 return this->copySurfaceAsBlitFramebuffer(dst, src, srcRect, dstPoint); | 3146 return this->copySurfaceAsBlitFramebuffer(dst, src, srcRect, dstPoint); |
2917 } | 3147 } |
2918 | 3148 |
2919 return false; | 3149 return false; |
2920 } | 3150 } |
2921 | 3151 |
2922 | 3152 |
2923 void GrGLGpu::createCopyProgram() { | 3153 void GrGLGpu::createCopyProgram() { |
2924 const char* version = this->glCaps().glslCaps()->versionDeclString(); | 3154 const char* version = this->glCaps().glslCaps()->versionDeclString(); |
2925 | 3155 |
2926 GrGLSLShaderVar aVertex("a_vertex", kVec2f_GrSLType, GrShaderVar::kAttribute
_TypeModifier); | 3156 GrGLSLShaderVar aVertex("a_vertex", kVec2f_GrSLType, GrShaderVar::kAttribute
_TypeModifier); |
2927 GrGLSLShaderVar uTexCoordXform("u_texCoordXform", kVec4f_GrSLType, | 3157 GrGLSLShaderVar uTexCoordXform("u_texCoordXform", kVec4f_GrSLType, |
2928 GrShaderVar::kUniform_TypeModifier); | 3158 GrShaderVar::kUniform_TypeModifier); |
2929 GrGLSLShaderVar uPosXform("u_posXform", kVec4f_GrSLType, GrShaderVar::kUnifo
rm_TypeModifier); | 3159 GrGLSLShaderVar uPosXform("u_posXform", kVec4f_GrSLType, GrShaderVar::kUnifo
rm_TypeModifier); |
2930 GrGLSLShaderVar uTexture("u_texture", kSampler2D_GrSLType, GrShaderVar::kUni
form_TypeModifier); | 3160 GrGLSLShaderVar uTexture("u_texture", kSampler2D_GrSLType, GrShaderVar::kUni
form_TypeModifier); |
2931 GrGLSLShaderVar vTexCoord("v_texCoord", kVec2f_GrSLType, GrShaderVar::kVaryi
ngOut_TypeModifier); | 3161 GrGLSLShaderVar vTexCoord("v_texCoord", kVec2f_GrSLType, GrShaderVar::kVaryi
ngOut_TypeModifier); |
2932 GrGLSLShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, GrShaderVar::kOut
_TypeModifier); | 3162 GrGLSLShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, GrShaderVar::kOut
_TypeModifier); |
2933 | 3163 |
2934 SkString vshaderTxt(version); | 3164 SkString vshaderTxt(version); |
2935 aVertex.appendDecl(this->glCaps().glslCaps(), &vshaderTxt); | 3165 aVertex.appendDecl(this->glCaps().glslCaps(), &vshaderTxt); |
2936 vshaderTxt.append(";"); | 3166 vshaderTxt.append(";"); |
2937 uTexCoordXform.appendDecl(this->glCaps().glslCaps(), &vshaderTxt); | 3167 uTexCoordXform.appendDecl(this->glCaps().glslCaps(), &vshaderTxt); |
2938 vshaderTxt.append(";"); | 3168 vshaderTxt.append(";"); |
2939 uPosXform.appendDecl(this->glCaps().glslCaps(), &vshaderTxt); | 3169 uPosXform.appendDecl(this->glCaps().glslCaps(), &vshaderTxt); |
2940 vshaderTxt.append(";"); | 3170 vshaderTxt.append(";"); |
2941 vTexCoord.appendDecl(this->glCaps().glslCaps(), &vshaderTxt); | 3171 vTexCoord.appendDecl(this->glCaps().glslCaps(), &vshaderTxt); |
2942 vshaderTxt.append(";"); | 3172 vshaderTxt.append(";"); |
2943 | 3173 |
2944 vshaderTxt.append( | 3174 vshaderTxt.append( |
2945 "// Copy Program VS\n" | 3175 "// Copy Program VS\n" |
2946 "void main() {" | 3176 "void main() {" |
2947 " v_texCoord = a_vertex.xy * u_texCoordXform.xy + u_texCoordXform.zw;" | 3177 " v_texCoord = a_vertex.xy * u_texCoordXform.xy + u_texCoordXform.zw;" |
2948 " gl_Position.xy = a_vertex * u_posXform.xy + u_posXform.zw;" | 3178 " gl_Position.xy = a_vertex * u_posXform.xy + u_posXform.zw;" |
2949 " gl_Position.zw = vec2(0, 1);" | 3179 " gl_Position.zw = vec2(0, 1);" |
2950 "}" | 3180 "}" |
2951 ); | 3181 ); |
2952 | 3182 |
2953 SkString fshaderTxt(version); | 3183 SkString fshaderTxt(version); |
(...skipping 14 matching lines...) Expand all Loading... |
2968 fsOutName = "gl_FragColor"; | 3198 fsOutName = "gl_FragColor"; |
2969 } | 3199 } |
2970 fshaderTxt.appendf( | 3200 fshaderTxt.appendf( |
2971 "// Copy Program FS\n" | 3201 "// Copy Program FS\n" |
2972 "void main() {" | 3202 "void main() {" |
2973 " %s = %s(u_texture, v_texCoord);" | 3203 " %s = %s(u_texture, v_texCoord);" |
2974 "}", | 3204 "}", |
2975 fsOutName, | 3205 fsOutName, |
2976 GrGLSLTexture2DFunctionName(kVec2f_GrSLType, this->glslGeneration()) | 3206 GrGLSLTexture2DFunctionName(kVec2f_GrSLType, this->glslGeneration()) |
2977 ); | 3207 ); |
2978 | 3208 |
2979 GL_CALL_RET(fCopyProgram.fProgram, CreateProgram()); | 3209 GL_CALL_RET(fCopyProgram.fProgram, CreateProgram()); |
2980 const char* str; | 3210 const char* str; |
2981 GrGLint length; | 3211 GrGLint length; |
2982 | 3212 |
2983 str = vshaderTxt.c_str(); | 3213 str = vshaderTxt.c_str(); |
2984 length = SkToInt(vshaderTxt.size()); | 3214 length = SkToInt(vshaderTxt.size()); |
2985 GrGLuint vshader = GrGLCompileAndAttachShader(*fGLContext, fCopyProgram.fPro
gram, | 3215 GrGLuint vshader = GrGLCompileAndAttachShader(*fGLContext, fCopyProgram.fPro
gram, |
2986 GR_GL_VERTEX_SHADER, &str, &le
ngth, 1, &fStats); | 3216 GR_GL_VERTEX_SHADER, &str, &le
ngth, 1, &fStats); |
2987 | 3217 |
2988 str = fshaderTxt.c_str(); | 3218 str = fshaderTxt.c_str(); |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3295 this->setVertexArrayID(gpu, 0); | 3525 this->setVertexArrayID(gpu, 0); |
3296 } | 3526 } |
3297 int attrCount = gpu->glCaps().maxVertexAttributes(); | 3527 int attrCount = gpu->glCaps().maxVertexAttributes(); |
3298 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 3528 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
3299 fDefaultVertexArrayAttribState.resize(attrCount); | 3529 fDefaultVertexArrayAttribState.resize(attrCount); |
3300 } | 3530 } |
3301 attribState = &fDefaultVertexArrayAttribState; | 3531 attribState = &fDefaultVertexArrayAttribState; |
3302 } | 3532 } |
3303 return attribState; | 3533 return attribState; |
3304 } | 3534 } |
OLD | NEW |