Update configs. IGNORE BROKEN CHANGESETS CLOSED TREE NO BUG a=release ba=release
[gecko.git] / gfx / layers / UpdateImageHelper.h
blob57ac237efe34e515a01ec117f0893c47384a282e
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"
17 namespace mozilla {
18 namespace layers {
20 class UpdateImageHelper {
21 public:
22 UpdateImageHelper(ImageContainer* aImageContainer, ImageClient* aImageClient,
23 gfx::IntSize aImageSize, gfx::SurfaceFormat aFormat)
24 : mImageContainer(aImageContainer),
25 mImageClient(aImageClient),
26 mImageSize(aImageSize),
27 mIsLocked(false) {
28 mTexture = mImageClient->GetTextureClientRecycler()->CreateOrRecycle(
29 aFormat, mImageSize, BackendSelector::Content, TextureFlags::DEFAULT);
30 if (!mTexture) {
31 return;
34 mIsLocked = mTexture->Lock(OpenMode::OPEN_WRITE_ONLY);
35 if (!mIsLocked) {
36 return;
40 ~UpdateImageHelper() {
41 if (mIsLocked) {
42 mTexture->Unlock();
43 mIsLocked = false;
47 already_AddRefed<gfx::DrawTarget> GetDrawTarget() {
48 RefPtr<gfx::DrawTarget> target;
49 if (mTexture) {
50 target = mTexture->BorrowDrawTarget();
52 return target.forget();
55 bool UpdateImage() {
56 if (!mTexture) {
57 return false;
60 if (mIsLocked) {
61 mTexture->Unlock();
62 mIsLocked = false;
65 RefPtr<TextureWrapperImage> image = new TextureWrapperImage(
66 mTexture, gfx::IntRect(gfx::IntPoint(0, 0), mImageSize));
67 mImageContainer->SetCurrentImageInTransaction(image);
68 return mImageClient->UpdateImage(mImageContainer);
71 private:
72 RefPtr<ImageContainer> mImageContainer;
73 RefPtr<ImageClient> mImageClient;
74 gfx::IntSize mImageSize;
75 RefPtr<TextureClient> mTexture;
76 bool mIsLocked;
79 } // namespace layers
80 } // namespace mozilla
82 #endif // GFX_UPDATEIMAGEHELPER_H