Source code

Revision control

Other Tools

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/. */
6
7
#ifndef GFX_COPYABLECANVASRENDERER_H
8
#define GFX_COPYABLECANVASRENDERER_H
9
10
#include <stdint.h> // for uint32_t
11
#include "CanvasRenderer.h"
12
#include "GLContextTypes.h" // for GLContext
13
#include "gfxContext.h" // for gfxContext, etc
14
#include "gfxTypes.h"
15
#include "gfxPlatform.h" // for gfxImageFormat
16
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
17
#include "mozilla/Preferences.h" // for Preferences
18
#include "mozilla/RefPtr.h" // for RefPtr
19
#include "mozilla/gfx/2D.h" // for DrawTarget
20
#include "mozilla/mozalloc.h" // for operator delete, etc
21
#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc
22
23
namespace mozilla {
24
25
namespace gl {
26
class SharedSurface;
27
} // namespace gl
28
29
namespace layers {
30
31
/**
32
* A shared CanvasRenderer implementation that supports copying
33
* its contents into a gfxASurface using RebackSurface.
34
*/
35
class CopyableCanvasRenderer : public CanvasRenderer {
36
public:
37
CopyableCanvasRenderer();
38
virtual ~CopyableCanvasRenderer();
39
40
public:
41
void Initialize(const CanvasInitializeData& aData) override;
42
bool IsDataValid(const CanvasInitializeData& aData) override;
43
44
void ClearCachedResources() override;
45
void Destroy() override;
46
47
CopyableCanvasRenderer* AsCopyableCanvasRenderer() override { return this; }
48
49
bool NeedsYFlip() const { return mOriginPos == gl::OriginPos::BottomLeft; }
50
bool HasGLContext() const { return !!mGLContext; }
51
bool IsOpaque() const { return mOpaque; }
52
53
PersistentBufferProvider* GetBufferProvider() { return mBufferProvider; }
54
55
already_AddRefed<gfx::SourceSurface> ReadbackSurface();
56
57
protected:
58
RefPtr<gl::GLContext> mGLContext;
59
RefPtr<PersistentBufferProvider> mBufferProvider;
60
RefPtr<AsyncCanvasRenderer> mAsyncRenderer;
61
RefPtr<OOPCanvasRenderer> mOOPRenderer;
62
63
bool mIsAlphaPremultiplied;
64
gl::OriginPos mOriginPos;
65
66
bool mOpaque;
67
68
RefPtr<gfx::DataSourceSurface> mCachedTempSurface;
69
70
gfx::DataSourceSurface* GetTempSurface(const gfx::IntSize& aSize,
71
const gfx::SurfaceFormat aFormat);
72
};
73
74
} // namespace layers
75
} // namespace mozilla
76
77
#endif