tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

D3D11TextureWrapper.cpp (1915B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "D3D11TextureWrapper.h"
      8 
      9 #include "FFmpegLibWrapper.h"
     10 #include "FFmpegLog.h"
     11 #include "libavutil/frame.h"
     12 #include "mozilla/Assertions.h"
     13 #include "mozilla/Logging.h"
     14 #include "mozilla/gfx/gfxVars.h"
     15 
     16 struct ID3D11Texture2D;
     17 
     18 extern mozilla::LazyLogModule sFFmpegVideoLog;
     19 
     20 #define LOG(...) \
     21  MOZ_LOG(sFFmpegVideoLog, mozilla::LogLevel::Verbose, (__VA_ARGS__))
     22 
     23 namespace mozilla {
     24 
     25 D3D11TextureWrapper::D3D11TextureWrapper(AVFrame* aAVFrame,
     26                                         const FFmpegLibWrapper* aLib,
     27                                         ID3D11Texture2D* aTexture,
     28                                         const gfx::SurfaceFormat aFormat,
     29                                         const unsigned int aArrayIdx,
     30                                         std::function<void()>&& aReleaseMethod)
     31    : mFormat(aFormat),
     32      mArrayIdx(aArrayIdx),
     33      mReleaseMethod(std::move(aReleaseMethod)),
     34      mLib(aLib),
     35      mTexture(aTexture) {
     36  MOZ_ASSERT(XRE_IsGPUProcess());
     37  MOZ_ASSERT(gfx::gfxVars::HwDecodedVideoZeroCopy());
     38  MOZ_ASSERT(mLib);
     39  MOZ_ASSERT(aAVFrame);
     40  MOZ_ASSERT(aTexture);
     41  mHWAVBuffer = aLib->av_buffer_ref(aAVFrame->buf[0]);
     42  MOZ_ASSERT(mHWAVBuffer);
     43  LOG("Locked D3D11 texture %p on index %u", mTexture, mArrayIdx);
     44 }
     45 
     46 D3D11TextureWrapper::~D3D11TextureWrapper() {
     47  MOZ_ASSERT(XRE_IsGPUProcess());
     48  MOZ_ASSERT(mLib);
     49  MOZ_ASSERT(mHWAVBuffer);
     50  mLib->av_buffer_unref(&mHWAVBuffer);
     51  mLib = nullptr;
     52  mReleaseMethod();
     53  LOG("Unlocked D3D11 texture %p on index %u", mTexture, mArrayIdx);
     54 }
     55 
     56 }  // namespace mozilla
     57 
     58 #undef LOG