| 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 "GrGpuGL.h" | 9 #include "GrGpuGL.h" |
| 10 #include "GrGLStencilBuffer.h" | 10 #include "GrGLStencilBuffer.h" |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 GrPixelConfig GrGpuGL::preferredWritePixelsConfig(GrPixelConfig writeConfig, | 193 GrPixelConfig GrGpuGL::preferredWritePixelsConfig(GrPixelConfig writeConfig, |
| 194 GrPixelConfig surfaceConfig) c
onst { | 194 GrPixelConfig surfaceConfig) c
onst { |
| 195 if (GR_GL_RGBA_8888_PIXEL_OPS_SLOW && kRGBA_8888_GrPixelConfig == writeConfi
g) { | 195 if (GR_GL_RGBA_8888_PIXEL_OPS_SLOW && kRGBA_8888_GrPixelConfig == writeConfi
g) { |
| 196 return kBGRA_8888_GrPixelConfig; | 196 return kBGRA_8888_GrPixelConfig; |
| 197 } else { | 197 } else { |
| 198 return writeConfig; | 198 return writeConfig; |
| 199 } | 199 } |
| 200 } | 200 } |
| 201 | 201 |
| 202 bool GrGpuGL::canWriteTexturePixels(const GrTexture* texture, GrPixelConfig srcC
onfig) const { | 202 bool GrGpuGL::canWriteTexturePixels(const GrTexture* texture, GrPixelConfig srcC
onfig) const { |
| 203 if (kIndex_8_GrPixelConfig == srcConfig || kIndex_8_GrPixelConfig == texture
->config()) { | 203 if (kIndex_8_GrPixelConfig == srcConfig || kIndex_8_GrPixelConfig == texture
->config() || |
| 204 GrPixelConfigIsCompressed(srcConfig) || GrPixelConfigIsCompressed(textur
e->config())) { |
| 204 return false; | 205 return false; |
| 205 } | 206 } |
| 206 if (srcConfig != texture->config() && kGLES_GrGLStandard == this->glStandard
()) { | 207 if (srcConfig != texture->config() && kGLES_GrGLStandard == this->glStandard
()) { |
| 207 // In general ES2 requires the internal format of the texture and the fo
rmat of the src | 208 // In general ES2 requires the internal format of the texture and the fo
rmat of the src |
| 208 // pixels to match. However, It may or may not be possible to upload BGR
A data to a RGBA | 209 // pixels to match. However, It may or may not be possible to upload BGR
A data to a RGBA |
| 209 // texture. It depends upon which extension added BGRA. The Apple extens
ion allows it | 210 // texture. It depends upon which extension added BGRA. The Apple extens
ion allows it |
| 210 // (BGRA's internal format is RGBA) while the EXT extension does not (BG
RA is its own | 211 // (BGRA's internal format is RGBA) while the EXT extension does not (BG
RA is its own |
| 211 // internal format). | 212 // internal format). |
| 212 if (this->glCaps().bgraFormatSupport() && | 213 if (this->glCaps().bgraFormatSupport() && |
| 213 !this->glCaps().bgraIsInternalFormat() && | 214 !this->glCaps().bgraIsInternalFormat() && |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 } | 525 } |
| 525 | 526 |
| 526 bool GrGpuGL::uploadTexData(const GrGLTexture::Desc& desc, | 527 bool GrGpuGL::uploadTexData(const GrGLTexture::Desc& desc, |
| 527 bool isNewTexture, | 528 bool isNewTexture, |
| 528 int left, int top, int width, int height, | 529 int left, int top, int width, int height, |
| 529 GrPixelConfig dataConfig, | 530 GrPixelConfig dataConfig, |
| 530 const void* data, | 531 const void* data, |
| 531 size_t rowBytes) { | 532 size_t rowBytes) { |
| 532 SkASSERT(NULL != data || isNewTexture); | 533 SkASSERT(NULL != data || isNewTexture); |
| 533 | 534 |
| 535 // If we're uploading compressed data then we should be using uploadCompress
edTexData |
| 536 SkASSERT(!GrPixelConfigIsCompressed(dataConfig)); |
| 537 |
| 534 size_t bpp = GrBytesPerPixel(dataConfig); | 538 size_t bpp = GrBytesPerPixel(dataConfig); |
| 535 if (!adjust_pixel_ops_params(desc.fWidth, desc.fHeight, bpp, &left, &top, | 539 if (!adjust_pixel_ops_params(desc.fWidth, desc.fHeight, bpp, &left, &top, |
| 536 &width, &height, &data, &rowBytes)) { | 540 &width, &height, &data, &rowBytes)) { |
| 537 return false; | 541 return false; |
| 538 } | 542 } |
| 539 size_t trimRowBytes = width * bpp; | 543 size_t trimRowBytes = width * bpp; |
| 540 | 544 |
| 541 // in case we need a temporary, trimmed copy of the src pixels | 545 // in case we need a temporary, trimmed copy of the src pixels |
| 542 SkAutoSMalloc<128 * 128> tempStorage; | 546 SkAutoSMalloc<128 * 128> tempStorage; |
| 543 | 547 |
| 544 // paletted textures cannot be partially updated | 548 // paletted textures cannot be partially updated |
| 545 // We currently lazily create MIPMAPs when the we see a draw with | 549 // We currently lazily create MIPMAPs when the we see a draw with |
| 546 // GrTextureParams::kMipMap_FilterMode. Using texture storage requires that
the | 550 // GrTextureParams::kMipMap_FilterMode. Using texture storage requires that
the |
| 547 // MIP levels are all created when the texture is created. So for now we don
't use | 551 // MIP levels are all created when the texture is created. So for now we don
't use |
| 548 // texture storage. | 552 // texture storage. |
| 549 bool useTexStorage = false && | 553 bool useTexStorage = false && |
| 550 isNewTexture && | 554 isNewTexture && |
| 551 desc.fConfig != kIndex_8_GrPixelConfig && | 555 kIndex_8_GrPixelConfig != desc.fConfig && |
| 552 this->glCaps().texStorageSupport(); | 556 this->glCaps().texStorageSupport(); |
| 553 | 557 |
| 554 if (useTexStorage && kGL_GrGLStandard == this->glStandard()) { | 558 if (useTexStorage && kGL_GrGLStandard == this->glStandard()) { |
| 555 // 565 is not a sized internal format on desktop GL. So on desktop with | 559 // 565 is not a sized internal format on desktop GL. So on desktop with |
| 556 // 565 we always use an unsized internal format to let the system pick | 560 // 565 we always use an unsized internal format to let the system pick |
| 557 // the best sized format to convert the 565 data to. Since TexStorage | 561 // the best sized format to convert the 565 data to. Since TexStorage |
| 558 // only allows sized internal formats we will instead use TexImage2D. | 562 // only allows sized internal formats we will instead use TexImage2D. |
| 559 useTexStorage = desc.fConfig != kRGB_565_GrPixelConfig; | 563 useTexStorage = desc.fConfig != kRGB_565_GrPixelConfig; |
| 560 } | 564 } |
| 561 | 565 |
| (...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1425 return false; | 1429 return false; |
| 1426 } | 1430 } |
| 1427 } | 1431 } |
| 1428 | 1432 |
| 1429 bool GrGpuGL::onReadPixels(GrRenderTarget* target, | 1433 bool GrGpuGL::onReadPixels(GrRenderTarget* target, |
| 1430 int left, int top, | 1434 int left, int top, |
| 1431 int width, int height, | 1435 int width, int height, |
| 1432 GrPixelConfig config, | 1436 GrPixelConfig config, |
| 1433 void* buffer, | 1437 void* buffer, |
| 1434 size_t rowBytes) { | 1438 size_t rowBytes) { |
| 1439 // We cannot read pixels into a compressed buffer |
| 1440 if (GrPixelConfigIsCompressed(config)) { |
| 1441 return false; |
| 1442 } |
| 1443 |
| 1435 GrGLenum format; | 1444 GrGLenum format; |
| 1436 GrGLenum type; | 1445 GrGLenum type; |
| 1437 bool flipY = kBottomLeft_GrSurfaceOrigin == target->origin(); | 1446 bool flipY = kBottomLeft_GrSurfaceOrigin == target->origin(); |
| 1438 if (!this->configToGLFormats(config, false, NULL, &format, &type)) { | 1447 if (!this->configToGLFormats(config, false, NULL, &format, &type)) { |
| 1439 return false; | 1448 return false; |
| 1440 } | 1449 } |
| 1441 size_t bpp = GrBytesPerPixel(config); | 1450 size_t bpp = GrBytesPerPixel(config); |
| 1442 if (!adjust_pixel_ops_params(target->width(), target->height(), bpp, | 1451 if (!adjust_pixel_ops_params(target->width(), target->height(), bpp, |
| 1443 &left, &top, &width, &height, | 1452 &left, &top, &width, &height, |
| 1444 const_cast<const void**>(&buffer), | 1453 const_cast<const void**>(&buffer), |
| (...skipping 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2476 *internalFormat = GR_GL_ALPHA; | 2485 *internalFormat = GR_GL_ALPHA; |
| 2477 *externalFormat = GR_GL_ALPHA; | 2486 *externalFormat = GR_GL_ALPHA; |
| 2478 if (getSizedInternalFormat) { | 2487 if (getSizedInternalFormat) { |
| 2479 *internalFormat = GR_GL_ALPHA8; | 2488 *internalFormat = GR_GL_ALPHA8; |
| 2480 } else { | 2489 } else { |
| 2481 *internalFormat = GR_GL_ALPHA; | 2490 *internalFormat = GR_GL_ALPHA; |
| 2482 } | 2491 } |
| 2483 *externalType = GR_GL_UNSIGNED_BYTE; | 2492 *externalType = GR_GL_UNSIGNED_BYTE; |
| 2484 } | 2493 } |
| 2485 break; | 2494 break; |
| 2495 case kETC1_GrPixelConfig: |
| 2496 *internalFormat = GR_GL_COMPRESSED_RGB8_ETC1; |
| 2497 break; |
| 2498 case kLATC_GrPixelConfig: |
| 2499 switch(this->glCaps().latcAlias()) { |
| 2500 case GrGLCaps::kLATC_LATCAlias: |
| 2501 *internalFormat = GR_GL_COMPRESSED_LUMINANCE_LATC1; |
| 2502 break; |
| 2503 case GrGLCaps::kRGTC_LATCAlias: |
| 2504 *internalFormat = GR_GL_COMPRESSED_RED_RGTC1; |
| 2505 break; |
| 2506 case GrGLCaps::k3DC_LATCAlias: |
| 2507 *internalFormat = GR_GL_COMPRESSED_3DC_X; |
| 2508 break; |
| 2509 } |
| 2510 break; |
| 2486 default: | 2511 default: |
| 2487 return false; | 2512 return false; |
| 2488 } | 2513 } |
| 2489 return true; | 2514 return true; |
| 2490 } | 2515 } |
| 2491 | 2516 |
| 2492 void GrGpuGL::setTextureUnit(int unit) { | 2517 void GrGpuGL::setTextureUnit(int unit) { |
| 2493 SkASSERT(unit >= 0 && unit < fHWBoundTextures.count()); | 2518 SkASSERT(unit >= 0 && unit < fHWBoundTextures.count()); |
| 2494 if (unit != fHWActiveTextureUnitIdx) { | 2519 if (unit != fHWActiveTextureUnitIdx) { |
| 2495 GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + unit)); | 2520 GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + unit)); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2552 } | 2577 } |
| 2553 const GrGLRenderTarget* srcRT = static_cast<const GrGLRenderTarget*>(src->as
RenderTarget()); | 2578 const GrGLRenderTarget* srcRT = static_cast<const GrGLRenderTarget*>(src->as
RenderTarget()); |
| 2554 // If the src is multisampled (and uses an extension where there is a separa
te MSAA | 2579 // If the src is multisampled (and uses an extension where there is a separa
te MSAA |
| 2555 // renderbuffer) then it is an invalid operation to call CopyTexSubImage | 2580 // renderbuffer) then it is an invalid operation to call CopyTexSubImage |
| 2556 if (NULL != srcRT && srcRT->renderFBOID() != srcRT->textureFBOID()) { | 2581 if (NULL != srcRT && srcRT->renderFBOID() != srcRT->textureFBOID()) { |
| 2557 return false; | 2582 return false; |
| 2558 } | 2583 } |
| 2559 if (gpu->glCaps().isConfigRenderable(src->config(), src->desc().fSampleCnt >
0) && | 2584 if (gpu->glCaps().isConfigRenderable(src->config(), src->desc().fSampleCnt >
0) && |
| 2560 NULL != dst->asTexture() && | 2585 NULL != dst->asTexture() && |
| 2561 dst->origin() == src->origin() && | 2586 dst->origin() == src->origin() && |
| 2562 kIndex_8_GrPixelConfig != src->config()) { | 2587 kIndex_8_GrPixelConfig != src->config() && |
| 2588 !GrPixelConfigIsCompressed(src->config())) { |
| 2563 if (NULL != wouldNeedTempFBO) { | 2589 if (NULL != wouldNeedTempFBO) { |
| 2564 *wouldNeedTempFBO = NULL == src->asRenderTarget(); | 2590 *wouldNeedTempFBO = NULL == src->asRenderTarget(); |
| 2565 } | 2591 } |
| 2566 return true; | 2592 return true; |
| 2567 } else { | 2593 } else { |
| 2568 return false; | 2594 return false; |
| 2569 } | 2595 } |
| 2570 } | 2596 } |
| 2571 | 2597 |
| 2572 // If a temporary FBO was created, its non-zero ID is returned. The viewport tha
t the copy rect is | 2598 // If a temporary FBO was created, its non-zero ID is returned. The viewport tha
t the copy rect is |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2803 this->setVertexArrayID(gpu, 0); | 2829 this->setVertexArrayID(gpu, 0); |
| 2804 } | 2830 } |
| 2805 int attrCount = gpu->glCaps().maxVertexAttributes(); | 2831 int attrCount = gpu->glCaps().maxVertexAttributes(); |
| 2806 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 2832 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
| 2807 fDefaultVertexArrayAttribState.resize(attrCount); | 2833 fDefaultVertexArrayAttribState.resize(attrCount); |
| 2808 } | 2834 } |
| 2809 attribState = &fDefaultVertexArrayAttribState; | 2835 attribState = &fDefaultVertexArrayAttribState; |
| 2810 } | 2836 } |
| 2811 return attribState; | 2837 return attribState; |
| 2812 } | 2838 } |
| OLD | NEW |