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
10 #include "mozilla/layers/CompositorTypes.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();
65 RefPtr
<TextureWrapperImage
> image
= new TextureWrapperImage(
66 mTexture
, gfx::IntRect(gfx::IntPoint(0, 0), mImageSize
));
67 mImageContainer
->SetCurrentImageInTransaction(image
);
68 return mImageClient
->UpdateImage(mImageContainer
);
72 RefPtr
<ImageContainer
> mImageContainer
;
73 RefPtr
<ImageClient
> mImageClient
;
74 gfx::IntSize mImageSize
;
75 RefPtr
<TextureClient
> mTexture
;
80 } // namespace mozilla
82 #endif // GFX_UPDATEIMAGEHELPER_H