tor-browser

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

RenderTextureHost.cpp (5280B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      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 "RenderTextureHost.h"
      8 
      9 #include "GLContext.h"
     10 #include "mozilla/layers/CompositorThread.h"
     11 #include "mozilla/layers/TextureHost.h"
     12 #include "mozilla/ProfilerMarkers.h"
     13 #include "mozilla/webrender/RenderThread.h"
     14 #include "RenderThread.h"
     15 
     16 namespace mozilla {
     17 namespace wr {
     18 
     19 void ActivateBindAndTexParameteri(gl::GLContext* aGL, GLenum aActiveTexture,
     20                                  GLenum aBindTarget, GLuint aBindTexture) {
     21  aGL->fActiveTexture(aActiveTexture);
     22  aGL->fBindTexture(aBindTarget, aBindTexture);
     23  // Initialize the mip filters to linear by default.
     24  aGL->fTexParameteri(aBindTarget, LOCAL_GL_TEXTURE_MIN_FILTER,
     25                      LOCAL_GL_LINEAR);
     26  aGL->fTexParameteri(aBindTarget, LOCAL_GL_TEXTURE_MAG_FILTER,
     27                      LOCAL_GL_LINEAR);
     28 }
     29 
     30 void RenderTextureHostUsageInfo::OnVideoPresent(int aFrameId,
     31                                                uint32_t aDurationMs) {
     32  MOZ_ASSERT(RenderThread::IsInRenderThread());
     33 
     34  const auto maxPresentWaitDurationMs = 2;
     35  const auto maxSlowPresentCount = 5;
     36 
     37  mVideoPresentFrameId = aFrameId;
     38 
     39  if (aDurationMs < maxPresentWaitDurationMs) {
     40    mSlowPresentCount = 0;
     41    return;
     42  }
     43 
     44  mSlowPresentCount++;
     45 
     46  if (mSlowPresentCount <= maxSlowPresentCount) {
     47    return;
     48  }
     49 
     50  DisableVideoOverlay();
     51 
     52  gfxCriticalNoteOnce << "Video swapchain present is slow";
     53 
     54  nsPrintfCString marker("Video swapchain present is slow");
     55  PROFILER_MARKER_TEXT("DisableOverlay", GRAPHICS, {}, marker);
     56 }
     57 
     58 void RenderTextureHostUsageInfo::OnCompositorEndFrame(int aFrameId,
     59                                                      uint32_t aDurationMs) {
     60  MOZ_ASSERT(RenderThread::IsInRenderThread());
     61 
     62  const auto maxCommitWaitDurationMs = 20;
     63  const auto maxSlowCommitCount = 5;
     64 
     65  // Check if video was presented in current frame.
     66  if (mVideoPresentFrameId != aFrameId) {
     67    return;
     68  }
     69 
     70  if (aDurationMs < maxCommitWaitDurationMs) {
     71    mSlowCommitCount = 0;
     72    return;
     73  }
     74 
     75  mSlowCommitCount++;
     76 
     77  if (mSlowCommitCount <= maxSlowCommitCount) {
     78    return;
     79  }
     80 
     81  gfxCriticalNoteOnce << "Video swapchain is slow";
     82 
     83  nsPrintfCString marker("Video swapchain is slow");
     84  PROFILER_MARKER_TEXT("DisableOverlay", GRAPHICS, {}, marker);
     85 }
     86 
     87 RenderTextureHost::RenderTextureHost() : mIsFromDRMSource(false) {
     88  MOZ_COUNT_CTOR(RenderTextureHost);
     89 }
     90 
     91 RenderTextureHost::~RenderTextureHost() {
     92  MOZ_ASSERT(RenderThread::IsInRenderThread());
     93  MOZ_COUNT_DTOR(RenderTextureHost);
     94 }
     95 
     96 wr::WrExternalImage RenderTextureHost::Lock(uint8_t aChannelIndex,
     97                                            gl::GLContext* aGL) {
     98  return InvalidToWrExternalImage();
     99 }
    100 
    101 wr::WrExternalImage RenderTextureHost::LockSWGL(uint8_t aChannelIndex,
    102                                                void* aContext,
    103                                                RenderCompositor* aCompositor) {
    104  return InvalidToWrExternalImage();
    105 }
    106 
    107 RefPtr<layers::TextureSource> RenderTextureHost::CreateTextureSource(
    108    layers::TextureSourceProvider* aProvider) {
    109  return nullptr;
    110 }
    111 
    112 void RenderTextureHost::Destroy() {
    113  MOZ_ASSERT_UNREACHABLE("unexpected to be called");
    114 }
    115 
    116 RefPtr<RenderTextureHostUsageInfo> RenderTextureHost::GetOrMergeUsageInfo(
    117    const MutexAutoLock& aProofOfMapLock,
    118    RefPtr<RenderTextureHostUsageInfo> aUsageInfo) {
    119  MOZ_ASSERT(layers::CompositorThreadHolder::IsInCompositorThread());
    120 
    121  if (mRenderTextureHostUsageInfo && aUsageInfo) {
    122    if (mRenderTextureHostUsageInfo == aUsageInfo) {
    123      return mRenderTextureHostUsageInfo;
    124    }
    125 
    126    // Merge 2 RenderTextureHostUsageInfos to one RenderTextureHostUsageInfo.
    127 
    128    const bool overlayDisabled =
    129        mRenderTextureHostUsageInfo->VideoOverlayDisabled() ||
    130        aUsageInfo->VideoOverlayDisabled();
    131 
    132    // If mRenderTextureHostUsageInfo and aUsageInfo are different objects, keep
    133    // the older one.
    134    RefPtr<RenderTextureHostUsageInfo> usageInfo = [&]() {
    135      if (aUsageInfo->mCreationTimeStamp <
    136          mRenderTextureHostUsageInfo->mCreationTimeStamp) {
    137        return aUsageInfo;
    138      }
    139      return mRenderTextureHostUsageInfo;
    140    }();
    141 
    142    // Merge info.
    143    if (overlayDisabled) {
    144      usageInfo->DisableVideoOverlay();
    145    }
    146    mRenderTextureHostUsageInfo = usageInfo;
    147  } else if (aUsageInfo && !mRenderTextureHostUsageInfo) {
    148    mRenderTextureHostUsageInfo = aUsageInfo;
    149  }
    150 
    151  if (!mRenderTextureHostUsageInfo) {
    152    MOZ_ASSERT(!aUsageInfo);
    153    mRenderTextureHostUsageInfo = new RenderTextureHostUsageInfo;
    154  }
    155 
    156  MOZ_ASSERT(mRenderTextureHostUsageInfo);
    157  MOZ_ASSERT_IF(aUsageInfo && aUsageInfo->VideoOverlayDisabled(),
    158                mRenderTextureHostUsageInfo->VideoOverlayDisabled());
    159 
    160  return mRenderTextureHostUsageInfo;
    161 }
    162 
    163 RefPtr<RenderTextureHostUsageInfo> RenderTextureHost::GetTextureHostUsageInfo(
    164    const MutexAutoLock& aProofOfMapLock) {
    165  MOZ_ASSERT(RenderThread::IsInRenderThread());
    166 
    167  return mRenderTextureHostUsageInfo;
    168 }
    169 
    170 }  // namespace wr
    171 }  // namespace mozilla