1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef mozilla_dom_CanvasGradient_h
6 #define mozilla_dom_CanvasGradient_h
8 #include "mozilla/Attributes.h"
10 #include "mozilla/RefPtr.h"
11 #include "mozilla/dom/CanvasRenderingContext2DBinding.h"
12 #include "mozilla/dom/CanvasRenderingContext2D.h"
13 #include "mozilla/gfx/2D.h"
14 #include "nsWrapperCache.h"
15 #include "gfxGradientCache.h"
20 class CanvasGradient
: public nsWrapperCache
{
22 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(CanvasGradient
)
23 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(CanvasGradient
)
25 enum class Type
: uint8_t { LINEAR
= 0, RADIAL
};
27 Type
GetType() { return mType
; }
29 mozilla::gfx::GradientStops
* GetGradientStopsForTarget(
30 mozilla::gfx::DrawTarget
* aRT
) {
31 if (mStops
&& mStops
->GetBackendType() == aRT
->GetBackendType()) {
35 mStops
= gfx::gfxGradientCache::GetOrCreateGradientStops(
36 aRT
, mRawStops
, gfx::ExtendMode::CLAMP
);
42 void AddColorStop(float offset
, const nsACString
& colorstr
, ErrorResult
& rv
);
44 JSObject
* WrapObject(JSContext
* aCx
,
45 JS::Handle
<JSObject
*> aGivenProto
) override
{
46 return CanvasGradient_Binding::Wrap(aCx
, this, aGivenProto
);
49 CanvasRenderingContext2D
* GetParentObject() { return mContext
; }
52 friend struct CanvasBidiProcessor
;
54 CanvasGradient(CanvasRenderingContext2D
* aContext
, Type aType
)
55 : mContext(aContext
), mType(aType
) {}
57 RefPtr
<CanvasRenderingContext2D
> mContext
;
58 nsTArray
<mozilla::gfx::GradientStop
> mRawStops
;
59 RefPtr
<mozilla::gfx::GradientStops
> mStops
;
61 virtual ~CanvasGradient() {}
65 } // namespace mozilla
67 #endif // mozilla_dom_CanvasGradient_h