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().isConfigTexturable(kBGRA_8888_GrPixelConfig) && |
213 !this->glCaps().bgraIsInternalFormat() && | 214 !this->glCaps().bgraIsInternalFormat() && |
214 kBGRA_8888_GrPixelConfig == srcConfig && | 215 kBGRA_8888_GrPixelConfig == srcConfig && |
215 kRGBA_8888_GrPixelConfig == texture->config()) { | 216 kRGBA_8888_GrPixelConfig == texture->config()) { |
216 return true; | 217 return true; |
217 } else { | 218 } else { |
218 return false; | 219 return false; |
219 } | 220 } |
220 } else { | 221 } else { |
221 return true; | 222 return true; |
222 } | 223 } |
(...skipping 301 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 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2388 if (NULL == internalFormat) { | 2397 if (NULL == internalFormat) { |
2389 internalFormat = &dontCare; | 2398 internalFormat = &dontCare; |
2390 } | 2399 } |
2391 if (NULL == externalFormat) { | 2400 if (NULL == externalFormat) { |
2392 externalFormat = &dontCare; | 2401 externalFormat = &dontCare; |
2393 } | 2402 } |
2394 if (NULL == externalType) { | 2403 if (NULL == externalType) { |
2395 externalType = &dontCare; | 2404 externalType = &dontCare; |
2396 } | 2405 } |
2397 | 2406 |
| 2407 if(!this->glCaps().isConfigTexturable(config)) { |
| 2408 return false; |
| 2409 } |
| 2410 |
2398 switch (config) { | 2411 switch (config) { |
2399 case kRGBA_8888_GrPixelConfig: | 2412 case kRGBA_8888_GrPixelConfig: |
2400 *internalFormat = GR_GL_RGBA; | 2413 *internalFormat = GR_GL_RGBA; |
2401 *externalFormat = GR_GL_RGBA; | 2414 *externalFormat = GR_GL_RGBA; |
2402 if (getSizedInternalFormat) { | 2415 if (getSizedInternalFormat) { |
2403 *internalFormat = GR_GL_RGBA8; | 2416 *internalFormat = GR_GL_RGBA8; |
2404 } else { | 2417 } else { |
2405 *internalFormat = GR_GL_RGBA; | 2418 *internalFormat = GR_GL_RGBA; |
2406 } | 2419 } |
2407 *externalType = GR_GL_UNSIGNED_BYTE; | 2420 *externalType = GR_GL_UNSIGNED_BYTE; |
2408 break; | 2421 break; |
2409 case kBGRA_8888_GrPixelConfig: | 2422 case kBGRA_8888_GrPixelConfig: |
2410 if (!this->glCaps().bgraFormatSupport()) { | |
2411 return false; | |
2412 } | |
2413 if (this->glCaps().bgraIsInternalFormat()) { | 2423 if (this->glCaps().bgraIsInternalFormat()) { |
2414 if (getSizedInternalFormat) { | 2424 if (getSizedInternalFormat) { |
2415 *internalFormat = GR_GL_BGRA8; | 2425 *internalFormat = GR_GL_BGRA8; |
2416 } else { | 2426 } else { |
2417 *internalFormat = GR_GL_BGRA; | 2427 *internalFormat = GR_GL_BGRA; |
2418 } | 2428 } |
2419 } else { | 2429 } else { |
2420 if (getSizedInternalFormat) { | 2430 if (getSizedInternalFormat) { |
2421 *internalFormat = GR_GL_RGBA8; | 2431 *internalFormat = GR_GL_RGBA8; |
2422 } else { | 2432 } else { |
(...skipping 21 matching lines...) Expand all Loading... |
2444 *internalFormat = GR_GL_RGBA; | 2454 *internalFormat = GR_GL_RGBA; |
2445 *externalFormat = GR_GL_RGBA; | 2455 *externalFormat = GR_GL_RGBA; |
2446 if (getSizedInternalFormat) { | 2456 if (getSizedInternalFormat) { |
2447 *internalFormat = GR_GL_RGBA4; | 2457 *internalFormat = GR_GL_RGBA4; |
2448 } else { | 2458 } else { |
2449 *internalFormat = GR_GL_RGBA; | 2459 *internalFormat = GR_GL_RGBA; |
2450 } | 2460 } |
2451 *externalType = GR_GL_UNSIGNED_SHORT_4_4_4_4; | 2461 *externalType = GR_GL_UNSIGNED_SHORT_4_4_4_4; |
2452 break; | 2462 break; |
2453 case kIndex_8_GrPixelConfig: | 2463 case kIndex_8_GrPixelConfig: |
2454 if (this->caps()->eightBitPaletteSupport()) { | 2464 // glCompressedTexImage doesn't take external params |
2455 // glCompressedTexImage doesn't take external params | 2465 *externalFormat = GR_GL_PALETTE8_RGBA8; |
2456 *externalFormat = GR_GL_PALETTE8_RGBA8; | 2466 // no sized/unsized internal format distinction here |
2457 // no sized/unsized internal format distinction here | 2467 *internalFormat = GR_GL_PALETTE8_RGBA8; |
2458 *internalFormat = GR_GL_PALETTE8_RGBA8; | 2468 // unused with CompressedTexImage |
2459 // unused with CompressedTexImage | 2469 *externalType = GR_GL_UNSIGNED_BYTE; |
2460 *externalType = GR_GL_UNSIGNED_BYTE; | |
2461 } else { | |
2462 return false; | |
2463 } | |
2464 break; | 2470 break; |
2465 case kAlpha_8_GrPixelConfig: | 2471 case kAlpha_8_GrPixelConfig: |
2466 if (this->glCaps().textureRedSupport()) { | 2472 if (this->glCaps().textureRedSupport()) { |
2467 *internalFormat = GR_GL_RED; | 2473 *internalFormat = GR_GL_RED; |
2468 *externalFormat = GR_GL_RED; | 2474 *externalFormat = GR_GL_RED; |
2469 if (getSizedInternalFormat) { | 2475 if (getSizedInternalFormat) { |
2470 *internalFormat = GR_GL_R8; | 2476 *internalFormat = GR_GL_R8; |
2471 } else { | 2477 } else { |
2472 *internalFormat = GR_GL_RED; | 2478 *internalFormat = GR_GL_RED; |
2473 } | 2479 } |
2474 *externalType = GR_GL_UNSIGNED_BYTE; | 2480 *externalType = GR_GL_UNSIGNED_BYTE; |
2475 } else { | 2481 } else { |
2476 *internalFormat = GR_GL_ALPHA; | 2482 *internalFormat = GR_GL_ALPHA; |
2477 *externalFormat = GR_GL_ALPHA; | 2483 *externalFormat = GR_GL_ALPHA; |
2478 if (getSizedInternalFormat) { | 2484 if (getSizedInternalFormat) { |
2479 *internalFormat = GR_GL_ALPHA8; | 2485 *internalFormat = GR_GL_ALPHA8; |
2480 } else { | 2486 } else { |
2481 *internalFormat = GR_GL_ALPHA; | 2487 *internalFormat = GR_GL_ALPHA; |
2482 } | 2488 } |
2483 *externalType = GR_GL_UNSIGNED_BYTE; | 2489 *externalType = GR_GL_UNSIGNED_BYTE; |
2484 } | 2490 } |
2485 break; | 2491 break; |
| 2492 case kETC1_GrPixelConfig: |
| 2493 *internalFormat = GR_GL_COMPRESSED_RGB8_ETC1; |
| 2494 break; |
| 2495 case kLATC_GrPixelConfig: |
| 2496 switch(this->glCaps().latcAlias()) { |
| 2497 case GrGLCaps::kLATC_LATCAlias: |
| 2498 *internalFormat = GR_GL_COMPRESSED_LUMINANCE_LATC1; |
| 2499 break; |
| 2500 case GrGLCaps::kRGTC_LATCAlias: |
| 2501 *internalFormat = GR_GL_COMPRESSED_RED_RGTC1; |
| 2502 break; |
| 2503 case GrGLCaps::k3DC_LATCAlias: |
| 2504 *internalFormat = GR_GL_COMPRESSED_3DC_X; |
| 2505 break; |
| 2506 } |
| 2507 break; |
2486 default: | 2508 default: |
2487 return false; | 2509 return false; |
2488 } | 2510 } |
2489 return true; | 2511 return true; |
2490 } | 2512 } |
2491 | 2513 |
2492 void GrGpuGL::setTextureUnit(int unit) { | 2514 void GrGpuGL::setTextureUnit(int unit) { |
2493 SkASSERT(unit >= 0 && unit < fHWBoundTextures.count()); | 2515 SkASSERT(unit >= 0 && unit < fHWBoundTextures.count()); |
2494 if (unit != fHWActiveTextureUnitIdx) { | 2516 if (unit != fHWActiveTextureUnitIdx) { |
2495 GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + unit)); | 2517 GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + unit)); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2552 } | 2574 } |
2553 const GrGLRenderTarget* srcRT = static_cast<const GrGLRenderTarget*>(src->as
RenderTarget()); | 2575 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 | 2576 // 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 | 2577 // renderbuffer) then it is an invalid operation to call CopyTexSubImage |
2556 if (NULL != srcRT && srcRT->renderFBOID() != srcRT->textureFBOID()) { | 2578 if (NULL != srcRT && srcRT->renderFBOID() != srcRT->textureFBOID()) { |
2557 return false; | 2579 return false; |
2558 } | 2580 } |
2559 if (gpu->glCaps().isConfigRenderable(src->config(), src->desc().fSampleCnt >
0) && | 2581 if (gpu->glCaps().isConfigRenderable(src->config(), src->desc().fSampleCnt >
0) && |
2560 NULL != dst->asTexture() && | 2582 NULL != dst->asTexture() && |
2561 dst->origin() == src->origin() && | 2583 dst->origin() == src->origin() && |
2562 kIndex_8_GrPixelConfig != src->config()) { | 2584 kIndex_8_GrPixelConfig != src->config() && |
| 2585 !GrPixelConfigIsCompressed(src->config())) { |
2563 if (NULL != wouldNeedTempFBO) { | 2586 if (NULL != wouldNeedTempFBO) { |
2564 *wouldNeedTempFBO = NULL == src->asRenderTarget(); | 2587 *wouldNeedTempFBO = NULL == src->asRenderTarget(); |
2565 } | 2588 } |
2566 return true; | 2589 return true; |
2567 } else { | 2590 } else { |
2568 return false; | 2591 return false; |
2569 } | 2592 } |
2570 } | 2593 } |
2571 | 2594 |
2572 // If a temporary FBO was created, its non-zero ID is returned. The viewport tha
t the copy rect is | 2595 // 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); | 2826 this->setVertexArrayID(gpu, 0); |
2804 } | 2827 } |
2805 int attrCount = gpu->glCaps().maxVertexAttributes(); | 2828 int attrCount = gpu->glCaps().maxVertexAttributes(); |
2806 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 2829 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
2807 fDefaultVertexArrayAttribState.resize(attrCount); | 2830 fDefaultVertexArrayAttribState.resize(attrCount); |
2808 } | 2831 } |
2809 attribState = &fDefaultVertexArrayAttribState; | 2832 attribState = &fDefaultVertexArrayAttribState; |
2810 } | 2833 } |
2811 return attribState; | 2834 return attribState; |
2812 } | 2835 } |
OLD | NEW |