LCOV - code coverage report
Current view: top level - widget/gtk - WindowSurfaceProvider.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 30 43 69.8 %
Date: 2017-07-14 16:53:18 Functions: 5 6 83.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
       2             :  *
       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 "WindowSurfaceProvider.h"
       8             : 
       9             : #include "gfxPlatformGtk.h"
      10             : #include "mozilla/layers/LayersTypes.h"
      11             : #include "WindowSurfaceX11Image.h"
      12             : #include "WindowSurfaceX11SHM.h"
      13             : #include "WindowSurfaceXRender.h"
      14             : 
      15             : namespace mozilla {
      16             : namespace widget {
      17             : 
      18             : using namespace mozilla::gfx;
      19             : using namespace mozilla::layers;
      20             : 
      21           3 : WindowSurfaceProvider::WindowSurfaceProvider()
      22             :     : mXDisplay(nullptr)
      23             :     , mXWindow(0)
      24             :     , mXVisual(nullptr)
      25             :     , mXDepth(0)
      26           3 :     , mWindowSurface(nullptr)
      27             : {
      28           3 : }
      29             : 
      30           3 : void WindowSurfaceProvider::Initialize(
      31             :       Display* aDisplay,
      32             :       Window aWindow,
      33             :       Visual* aVisual,
      34             :       int aDepth)
      35             : {
      36             :   // We should not be initialized
      37           3 :   MOZ_ASSERT(!mXDisplay);
      38             : 
      39             :   // This should also be a valid initialization
      40           3 :   MOZ_ASSERT(aDisplay && aWindow != X11None && aVisual);
      41             : 
      42           3 :   mXDisplay = aDisplay;
      43           3 :   mXWindow = aWindow;
      44           3 :   mXVisual = aVisual;
      45           3 :   mXDepth = aDepth;
      46           3 : }
      47           0 : void WindowSurfaceProvider::CleanupResources()
      48             : {
      49           0 :   mWindowSurface = nullptr;
      50           0 : }
      51             : 
      52             : UniquePtr<WindowSurface>
      53           1 : WindowSurfaceProvider::CreateWindowSurface()
      54             : {
      55             :   // We should be initialized
      56           1 :   MOZ_ASSERT(mXDisplay);
      57             : 
      58             :   // Blit to the window with the following priority:
      59             :   // 1. XRender (iff XRender is enabled && we are in-process)
      60             :   // 2. MIT-SHM
      61             :   // 3. XPutImage
      62             : 
      63             : #ifdef MOZ_WIDGET_GTK
      64           1 :   if (gfxVars::UseXRender()) {
      65           0 :     LOGDRAW(("Drawing to nsWindow %p using XRender\n", (void*)this));
      66           0 :     return MakeUnique<WindowSurfaceXRender>(mXDisplay, mXWindow, mXVisual, mXDepth);
      67             :   }
      68             : #endif // MOZ_WIDGET_GTK
      69             : 
      70             : #ifdef MOZ_HAVE_SHMIMAGE
      71           1 :   if (nsShmImage::UseShm()) {
      72           1 :     LOGDRAW(("Drawing to nsWindow %p using MIT-SHM\n", (void*)this));
      73           1 :     return MakeUnique<WindowSurfaceX11SHM>(mXDisplay, mXWindow, mXVisual, mXDepth);
      74             :   }
      75             : #endif // MOZ_HAVE_SHMIMAGE
      76             : 
      77           0 :   LOGDRAW(("Drawing to nsWindow %p using XPutImage\n", (void*)this));
      78           0 :   return MakeUnique<WindowSurfaceX11Image>(mXDisplay, mXWindow, mXVisual, mXDepth);
      79             : }
      80             : 
      81             : already_AddRefed<gfx::DrawTarget>
      82          27 : WindowSurfaceProvider::StartRemoteDrawingInRegion(LayoutDeviceIntRegion& aInvalidRegion,
      83             :                                                 layers::BufferMode* aBufferMode)
      84             : {
      85          27 :   if (aInvalidRegion.IsEmpty())
      86           0 :     return nullptr;
      87             : 
      88          27 :   if (!mWindowSurface) {
      89           1 :     mWindowSurface = CreateWindowSurface();
      90           1 :     if (!mWindowSurface)
      91           0 :       return nullptr;
      92             :   }
      93             : 
      94          27 :   *aBufferMode = BufferMode::BUFFER_NONE;
      95          54 :   RefPtr<DrawTarget> dt = nullptr;
      96          27 :   if (!(dt = mWindowSurface->Lock(aInvalidRegion)) &&
      97           0 :       !mWindowSurface->IsFallback()) {
      98           0 :     gfxWarningOnce() << "Failed to lock WindowSurface, falling back to XPutImage backend.";
      99           0 :     mWindowSurface = MakeUnique<WindowSurfaceX11Image>(mXDisplay, mXWindow, mXVisual, mXDepth);
     100           0 :     dt = mWindowSurface->Lock(aInvalidRegion);
     101             :   }
     102          27 :   return dt.forget();
     103             : }
     104             : 
     105             : void
     106          27 : WindowSurfaceProvider::EndRemoteDrawingInRegion(gfx::DrawTarget* aDrawTarget,
     107             :                                               LayoutDeviceIntRegion& aInvalidRegion)
     108             : {
     109          27 :   if (mWindowSurface)
     110          27 :     mWindowSurface->Commit(aInvalidRegion);
     111          27 : }
     112             : 
     113             : } // namespace mozilla
     114             : } // namespace widget

Generated by: LCOV version 1.13