| 60 | } |
| 61 | |
| 62 | std::shared_ptr<TextureView> TextureView::MakeFormat(Context* context, int width, int height, |
| 63 | const void* pixels, size_t rowBytes, |
| 64 | PixelFormat pixelFormat, bool mipmapped, |
| 65 | ImageOrigin origin) { |
| 66 | if (!CheckSizeAndFormat(context, width, height, pixelFormat)) { |
| 67 | return nullptr; |
| 68 | } |
| 69 | auto gpu = context->gpu(); |
| 70 | mipmapped = context->caps()->mipmapSupport && mipmapped; |
| 71 | auto scratchKey = ComputeTextureScratchKey(width, height, pixelFormat, mipmapped); |
| 72 | auto textureView = Resource::Find<TextureView>(context, scratchKey); |
| 73 | if (textureView) { |
| 74 | textureView->_origin = origin; |
| 75 | } else { |
| 76 | GPUTextureDescriptor descriptor = {width, height, pixelFormat, mipmapped}; |
| 77 | auto texture = gpu->createTexture(descriptor); |
| 78 | if (texture == nullptr) { |
| 79 | return nullptr; |
| 80 | } |
| 81 | textureView = Resource::AddToCache(context, new DefaultTextureView(std::move(texture), origin), |
| 82 | scratchKey); |
| 83 | } |
| 84 | if (pixels != nullptr) { |
| 85 | auto texture = textureView->getTexture(); |
| 86 | gpu->queue()->writeTexture(texture, Rect::MakeWH(width, height), pixels, rowBytes); |
| 87 | } |
| 88 | return textureView; |
| 89 | } |
| 90 | |
| 91 | std::shared_ptr<TextureView> TextureView::MakeFrom(Context* context, |
| 92 | const BackendTexture& backendTexture, |
nothing calls this directly
no test coverage detected