| 1475 | #endif /* SDL_HAVE_YUV */ |
| 1476 | |
| 1477 | static int |
| 1478 | SDL_UpdateTextureNative(SDL_Texture * texture, const SDL_Rect * rect, |
| 1479 | const void *pixels, int pitch) |
| 1480 | { |
| 1481 | SDL_Texture *native = texture->native; |
| 1482 | |
| 1483 | if (!rect->w || !rect->h) { |
| 1484 | return 0; /* nothing to do. */ |
| 1485 | } |
| 1486 | |
| 1487 | if (texture->access == SDL_TEXTUREACCESS_STREAMING) { |
| 1488 | /* We can lock the texture and copy to it */ |
| 1489 | void *native_pixels = NULL; |
| 1490 | int native_pitch = 0; |
| 1491 | |
| 1492 | if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) { |
| 1493 | return -1; |
| 1494 | } |
| 1495 | SDL_ConvertPixels(rect->w, rect->h, |
| 1496 | texture->format, pixels, pitch, |
| 1497 | native->format, native_pixels, native_pitch); |
| 1498 | SDL_UnlockTexture(native); |
| 1499 | } else { |
| 1500 | /* Use a temporary buffer for updating */ |
| 1501 | const int temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3); |
| 1502 | const size_t alloclen = rect->h * temp_pitch; |
| 1503 | if (alloclen > 0) { |
| 1504 | void *temp_pixels = SDL_malloc(alloclen); |
| 1505 | if (!temp_pixels) { |
| 1506 | return SDL_OutOfMemory(); |
| 1507 | } |
| 1508 | SDL_ConvertPixels(rect->w, rect->h, |
| 1509 | texture->format, pixels, pitch, |
| 1510 | native->format, temp_pixels, temp_pitch); |
| 1511 | SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch); |
| 1512 | SDL_free(temp_pixels); |
| 1513 | } |
| 1514 | } |
| 1515 | return 0; |
| 1516 | } |
| 1517 | |
| 1518 | int |
| 1519 | SDL_UpdateTexture(SDL_Texture * texture, const SDL_Rect * rect, |
no test coverage detected