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/. */
6 #ifndef GFX_COPYABLECANVASLAYER_H
7 #define GFX_COPYABLECANVASLAYER_H
9 #include <stdint.h> // for uint32_t
10 #include "GLContextTypes.h" // for GLContext
11 #include "Layers.h" // for CanvasLayer, etc
12 #include "gfxContext.h" // for gfxContext, etc
14 #include "gfxPlatform.h" // for gfxImageFormat
15 #include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
16 #include "mozilla/Preferences.h" // for Preferences
17 #include "mozilla/RefPtr.h" // for RefPtr
18 #include "mozilla/gfx/2D.h" // for DrawTarget
19 #include "mozilla/mozalloc.h" // for operator delete, etc
20 #include "nsAutoPtr.h" // for nsRefPtr
21 #include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc
30 class CanvasClientWebGL
;
33 * A shared CanvasLayer implementation that supports copying
34 * its contents into a gfxASurface using UpdateSurface.
36 class CopyableCanvasLayer
: public CanvasLayer
39 CopyableCanvasLayer(LayerManager
* aLayerManager
, void *aImplData
);
42 virtual ~CopyableCanvasLayer();
45 virtual void Initialize(const Data
& aData
);
47 virtual bool IsDataValid(const Data
& aData
);
49 bool IsGLLayer() { return !!mGLContext
; }
52 void UpdateTarget(gfx::DrawTarget
* aDestTarget
= nullptr);
54 RefPtr
<gfx::SourceSurface
> mSurface
;
55 nsRefPtr
<gl::GLContext
> mGLContext
;
56 mozilla::RefPtr
<mozilla::gfx::DrawTarget
> mDrawTarget
;
58 RefPtr
<gl::SurfaceStream
> mStream
;
60 uint32_t mCanvasFramebuffer
;
62 bool mIsAlphaPremultiplied
;
65 RefPtr
<gfx::DataSourceSurface
> mCachedTempSurface
;
67 gfx::DataSourceSurface
* GetTempSurface(const gfx::IntSize
& aSize
,
68 const gfx::SurfaceFormat aFormat
);
70 void DiscardTempSurface();