tor-browser

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

DMABUFSurfaceImage.cpp (2854B)


      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 "DMABUFSurfaceImage.h"
      8 #include "mozilla/widget/DMABufSurface.h"
      9 #include "mozilla/layers/CompositableClient.h"
     10 #include "mozilla/layers/CompositableForwarder.h"
     11 #include "mozilla/layers/DMABUFTextureClientOGL.h"
     12 #include "mozilla/layers/TextureForwarder.h"
     13 #include "mozilla/StaticMutex.h"
     14 #include "GLContext.h"
     15 #include "GLContextProvider.h"
     16 #include "GLBlitHelper.h"
     17 #include "GLReadTexImageHelper.h"
     18 #include "GLContextTypes.h"  // for GLContext, etc
     19 #include "GLContextEGL.h"
     20 #include "GLContextProvider.h"
     21 #include "ScopedGLHelpers.h"
     22 
     23 using namespace mozilla;
     24 using namespace mozilla::layers;
     25 using namespace mozilla::gfx;
     26 using namespace mozilla::gl;
     27 
     28 #ifdef MOZ_LOGGING
     29 #  undef DMABUF_LOG
     30 extern mozilla::LazyLogModule gDmabufLog;
     31 #  define DMABUF_LOG(str, ...) \
     32    MOZ_LOG(gDmabufLog, mozilla::LogLevel::Debug, (str, ##__VA_ARGS__))
     33 #else
     34 #  define DMABUF_LOG(args)
     35 #endif /* MOZ_LOGGING */
     36 
     37 DMABUFSurfaceImage::DMABUFSurfaceImage(DMABufSurface* aSurface)
     38    : Image(nullptr, ImageFormat::DMABUF), mSurface(aSurface) {
     39  DMABUF_LOG("DMABUFSurfaceImage::DMABUFSurfaceImage (%p) aSurface %p UID %d\n",
     40             this, aSurface, aSurface->GetUID());
     41  mSurface->GlobalRefAdd();
     42 }
     43 
     44 DMABUFSurfaceImage::~DMABUFSurfaceImage() {
     45  DMABUF_LOG(
     46      "DMABUFSurfaceImage::~DMABUFSurfaceImage (%p) mSurface %p UID %d\n", this,
     47      (void*)mSurface.get(), mSurface->GetUID());
     48  mSurface->GlobalRefRelease();
     49 }
     50 
     51 already_AddRefed<gfx::SourceSurface> DMABUFSurfaceImage::GetAsSourceSurface() {
     52  return mSurface->GetAsSourceSurface();
     53 }
     54 
     55 nsresult DMABUFSurfaceImage::BuildSurfaceDescriptorBuffer(
     56    SurfaceDescriptorBuffer& aSdBuffer, BuildSdbFlags aFlags,
     57    const std::function<MemoryOrShmem(uint32_t)>& aAllocate) {
     58  nsresult rv =
     59      mSurface->BuildSurfaceDescriptorBuffer(aSdBuffer, aFlags, aAllocate);
     60  if (rv != NS_ERROR_NOT_IMPLEMENTED) {
     61    // TODO(aosmond): Add support for the RGBA case.
     62    return rv;
     63  }
     64 
     65  return Image::BuildSurfaceDescriptorBuffer(aSdBuffer, aFlags, aAllocate);
     66 }
     67 
     68 TextureClient* DMABUFSurfaceImage::GetTextureClient(
     69    KnowsCompositor* aKnowsCompositor) {
     70  if (!mTextureClient) {
     71    BackendType backend = BackendType::NONE;
     72    mTextureClient = TextureClient::CreateWithData(
     73        DMABUFTextureData::Create(mSurface, backend), TextureFlags::DEFAULT,
     74        aKnowsCompositor->GetTextureForwarder());
     75  }
     76  return mTextureClient;
     77 }
     78 
     79 gfx::IntSize DMABUFSurfaceImage::GetSize() const {
     80  return gfx::IntSize::Truncate(mSurface->GetWidth(), mSurface->GetHeight());
     81 }