MCPcopy Create free account
hub / github.com/Tencent/tgfx / MakeFormat

Method MakeFormat

src/gpu/resources/TextureView.cpp:62–89  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60}
61
62std::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
91std::shared_ptr<TextureView> TextureView::MakeFrom(Context* context,
92 const BackendTexture& backendTexture,

Callers

nothing calls this directly

Calls 7

ComputeTextureScratchKeyFunction · 0.85
gpuMethod · 0.80
createTextureMethod · 0.80
writeTextureMethod · 0.80
queueMethod · 0.80
capsMethod · 0.45
getTextureMethod · 0.45

Tested by

no test coverage detected