#include "frame_texture.h" #include "shim_log.h" #include 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(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(this); AddRef(); return S_OK; } *ppv = nullptr; return E_NOINTERFACE; } ULONG STDMETHODCALLTYPE NuiFrameTexture::AddRef() { return static_cast(InterlockedIncrement(&ref_count_)); } ULONG STDMETHODCALLTYPE NuiFrameTexture::Release() { const LONG count = InterlockedDecrement(&ref_count_); if (count == 0) { delete this; } return static_cast(count); } int STDMETHODCALLTYPE NuiFrameTexture::BufferLen() { return static_cast(bits_.size()); } int STDMETHODCALLTYPE NuiFrameTexture::Pitch() { return static_cast(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(width_ * bytes_per_pixel_); pLockedRect->size = static_cast(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; } }