Bug 1632310 [wpt PR 23186] - Add test for computed versus resolved style., a=testonly
[gecko.git] / gfx / layers / UpdateImageHelper.h
blobe86eae7b3de962664333ada025e4597ccd201ba3
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 "Layers.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(wr::RenderRoot aRenderRoot) {
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, /* unused */ 0,
69 Some(aRenderRoot));
72 private:
73 RefPtr<ImageContainer> mImageContainer;
74 RefPtr<ImageClient> mImageClient;
75 gfx::IntSize mImageSize;
76 RefPtr<TextureClient> mTexture;
77 bool mIsLocked;
80 } // namespace layers
81 } // namespace mozilla
83 #endif // GFX_UPDATEIMAGEHELPER_H