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/. */
7 #ifndef GFX_UPDATEIMAGEHELPER_H
8 #define GFX_UPDATEIMAGEHELPER_H
11 #include "mozilla/layers/ImageClient.h"
12 #include "mozilla/layers/TextureClient.h"
13 #include "mozilla/layers/TextureClientRecycleAllocator.h"
14 #include "mozilla/layers/TextureWrapperImage.h"
15 #include "mozilla/gfx/Types.h"
20 class UpdateImageHelper
{
22 UpdateImageHelper(ImageContainer
* aImageContainer
, ImageClient
* aImageClient
,
23 gfx::IntSize aImageSize
, gfx::SurfaceFormat aFormat
)
24 : mImageContainer(aImageContainer
),
25 mImageClient(aImageClient
),
26 mImageSize(aImageSize
),
28 mTexture
= mImageClient
->GetTextureClientRecycler()->CreateOrRecycle(
29 aFormat
, mImageSize
, BackendSelector::Content
, TextureFlags::DEFAULT
);
34 mIsLocked
= mTexture
->Lock(OpenMode::OPEN_WRITE_ONLY
);
40 ~UpdateImageHelper() {
47 already_AddRefed
<gfx::DrawTarget
> GetDrawTarget() {
48 RefPtr
<gfx::DrawTarget
> target
;
50 target
= mTexture
->BorrowDrawTarget();
52 return target
.forget();
55 bool UpdateImage(wr::RenderRoot aRenderRoot
) {
65 RefPtr
<TextureWrapperImage
> image
= new TextureWrapperImage(
66 mTexture
, gfx::IntRect(gfx::IntPoint(0, 0), mImageSize
));
67 mImageContainer
->SetCurrentImageInTransaction(image
);
68 return mImageClient
->UpdateImage(mImageContainer
, /* unused */ 0,
73 RefPtr
<ImageContainer
> mImageContainer
;
74 RefPtr
<ImageClient
> mImageClient
;
75 gfx::IntSize mImageSize
;
76 RefPtr
<TextureClient
> mTexture
;
81 } // namespace mozilla
83 #endif // GFX_UPDATEIMAGEHELPER_H