LCOV - code coverage report
Current view: top level - gfx/layers - UpdateImageHelper.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 29 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 4 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
       2             :  * This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : #ifndef GFX_UPDATEIMAGEHELPER_H
       7             : #define GFX_UPDATEIMAGEHELPER_H
       8             : 
       9             : #include "Layers.h"
      10             : #include "mozilla/layers/ImageClient.h"
      11             : #include "mozilla/layers/TextureClient.h"
      12             : #include "mozilla/layers/TextureClientRecycleAllocator.h"
      13             : #include "mozilla/layers/TextureWrapperImage.h"
      14             : #include "mozilla/gfx/Types.h"
      15             : 
      16             : namespace mozilla {
      17             : namespace layers {
      18             : 
      19             : class UpdateImageHelper
      20             : {
      21             : public:
      22           0 :   UpdateImageHelper(ImageContainer* aImageContainer, ImageClient* aImageClient, gfx::IntSize aImageSize) :
      23             :     mImageContainer(aImageContainer),
      24             :     mImageClient(aImageClient),
      25             :     mImageSize(aImageSize),
      26           0 :     mIsLocked(false)
      27             :   {
      28           0 :     mTexture = mImageClient->GetTextureClientRecycler()->CreateOrRecycle(gfx::SurfaceFormat::B8G8R8A8,
      29             :                                                                          mImageSize,
      30             :                                                                          BackendSelector::Content,
      31           0 :                                                                          TextureFlags::DEFAULT);
      32           0 :     if (!mTexture) {
      33           0 :       return;
      34             :     }
      35             : 
      36           0 :     mIsLocked = mTexture->Lock(OpenMode::OPEN_WRITE_ONLY);
      37           0 :     if (!mIsLocked) {
      38           0 :       return;
      39             :     }
      40             :   }
      41             : 
      42           0 :   ~UpdateImageHelper()
      43           0 :   {
      44           0 :     if (mIsLocked) {
      45           0 :       mTexture->Unlock();
      46           0 :       mIsLocked = false;
      47             :     }
      48           0 :   }
      49             : 
      50           0 :   already_AddRefed<gfx::DrawTarget> GetDrawTarget()
      51             :   {
      52           0 :     RefPtr<gfx::DrawTarget> target;
      53           0 :     if (mTexture) {
      54           0 :       target = mTexture->BorrowDrawTarget();
      55             :     }
      56           0 :     return target.forget();
      57             :   }
      58             : 
      59           0 :   bool UpdateImage()
      60             :   {
      61           0 :     if (!mTexture) {
      62           0 :       return false;
      63             :     }
      64             : 
      65           0 :     if (mIsLocked) {
      66           0 :       mTexture->Unlock();
      67           0 :       mIsLocked = false;
      68             :     }
      69             : 
      70             :     RefPtr<TextureWrapperImage> image = new TextureWrapperImage(mTexture,
      71           0 :                                                                 gfx::IntRect(gfx::IntPoint(0, 0), mImageSize));
      72           0 :     mImageContainer->SetCurrentImageInTransaction(image);
      73           0 :     return mImageClient->UpdateImage(mImageContainer, /* unused */0);
      74             :   }
      75             : 
      76             : private:
      77             :   RefPtr<ImageContainer> mImageContainer;
      78             :   RefPtr<ImageClient> mImageClient;
      79             :   gfx::IntSize mImageSize;
      80             :   RefPtr<TextureClient> mTexture;
      81             :   bool mIsLocked;
      82             : };
      83             : 
      84             : } // namespace layers
      85             : } // namespace mozilla
      86             : 
      87             : #endif  // GFX_UPDATEIMAGEHELPER_H

Generated by: LCOV version 1.13