Files
kinect/fallback/windows-nui/src/frame_texture.cpp
T
kinect-bot df737fbe80
ci / Linux C++ core (cmake + ctest) (push) Canceled after 0s
ci / Python root tests (pytest, no tracker deps) (push) Canceled after 0s
ci / Python tracker (pytest, tracker/.venv) (push) Canceled after 0s
diag(windows-nui): log NuiImageFrameGetDepthImagePixelFrameTexture + LockRect to find pixel-access path
2026-11-25 16:11:04 -05:00

103 lines
2.8 KiB
C++

#include "frame_texture.h"
#include "shim_log.h"
#include <cstring>
namespace nui_shim {
NuiFrameTexture::NuiFrameTexture(uint32_t width,
uint32_t height,
uint32_t bytes_per_pixel)
: width_(width),
height_(height),
bytes_per_pixel_(bytes_per_pixel),
bits_(static_cast<std::size_t>(width) * height * bytes_per_pixel, 0) {}
void NuiFrameTexture::set_bits(const uint8_t* data, std::size_t size) {
const std::size_t n = size < bits_.size() ? size : bits_.size();
if (data != nullptr && n != 0) {
std::memcpy(bits_.data(), data, n);
}
if (n < bits_.size()) {
std::memset(bits_.data() + n, 0, bits_.size() - n);
}
}
uint8_t* NuiFrameTexture::data() { return bits_.data(); }
HRESULT STDMETHODCALLTYPE NuiFrameTexture::QueryInterface(REFIID riid,
void** ppv) {
if (ppv == nullptr) {
return E_POINTER;
}
if (IsEqualIID(riid, IID_IUnknown)) {
*ppv = static_cast<IUnknown*>(this);
AddRef();
return S_OK;
}
*ppv = nullptr;
return E_NOINTERFACE;
}
ULONG STDMETHODCALLTYPE NuiFrameTexture::AddRef() {
return static_cast<ULONG>(InterlockedIncrement(&ref_count_));
}
ULONG STDMETHODCALLTYPE NuiFrameTexture::Release() {
const LONG count = InterlockedDecrement(&ref_count_);
if (count == 0) {
delete this;
}
return static_cast<ULONG>(count);
}
int STDMETHODCALLTYPE NuiFrameTexture::BufferLen() {
return static_cast<int>(bits_.size());
}
int STDMETHODCALLTYPE NuiFrameTexture::Pitch() {
return static_cast<int>(width_ * bytes_per_pixel_);
}
HRESULT STDMETHODCALLTYPE NuiFrameTexture::LockRect(UINT Level,
NUI_LOCKED_RECT* pLockedRect,
RECT*,
DWORD) {
if (pLockedRect == nullptr) {
return E_POINTER;
}
if (Level != 0) {
return E_INVALIDARG;
}
pLockedRect->Pitch = static_cast<INT>(width_ * bytes_per_pixel_);
pLockedRect->size = static_cast<INT>(bits_.size());
pLockedRect->pBits = bits_.data();
static unsigned lr = 0;
if (lr < 8) {
ShimLog("LockRect#%u %ux%u bpp=%u pitch=%d size=%d", lr, width_, height_,
bytes_per_pixel_, pLockedRect->Pitch, pLockedRect->size);
}
++lr;
return S_OK;
}
HRESULT STDMETHODCALLTYPE NuiFrameTexture::GetLevelDesc(UINT Level,
NUI_SURFACE_DESC* pDesc) {
if (pDesc == nullptr) {
return E_POINTER;
}
if (Level != 0) {
return E_INVALIDARG;
}
pDesc->Width = width_;
pDesc->Height = height_;
return S_OK;
}
HRESULT STDMETHODCALLTYPE NuiFrameTexture::UnlockRect(UINT Level) {
return Level == 0 ? S_OK : E_INVALIDARG;
}
}