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 _MOZILLA_GFX_DRAWTARGETWEBGL_H
8 #define _MOZILLA_GFX_DRAWTARGETWEBGL_H
10 #include "mozilla/gfx/2D.h"
11 #include "mozilla/gfx/PathSkia.h"
12 #include "mozilla/LinkedList.h"
13 #include "mozilla/WeakPtr.h"
14 #include "mozilla/ThreadLocal.h"
15 #include "mozilla/ipc/Shmem.h"
24 class ClientWebGLContext
;
26 class WebGLFramebufferJS
;
28 class WebGLRenderbufferJS
;
30 class WebGLUniformLocationJS
;
31 class WebGLVertexArrayJS
;
34 class SurfaceDescriptor
;
39 class DataSourceSurface
;
41 class DrawTargetWebgl
;
43 class SourceSurfaceSkia
;
44 class SourceSurfaceWebgl
;
48 class SharedTextureHandle
;
49 class StandaloneTexture
;
52 struct PathVertexRange
;
54 // DrawTargetWebgl implements a subset of the DrawTarget API suitable for use
55 // by CanvasRenderingContext2D. It maps these to a client WebGL context so that
56 // they can be accelerated where possible by WebGL. It manages both routing to
57 // appropriate shaders and texture allocation/caching for surfaces. For commands
58 // that are not feasible to accelerate with WebGL, it mirrors state to a backup
59 // DrawTargetSkia that can be used as a fallback software renderer. Multiple
60 // instances of DrawTargetWebgl within a process will actually share a single
61 // WebGL context so that data can be more easily interchanged between them and
62 // also to enable more reasonable limiting of resource usage.
63 class DrawTargetWebgl
: public DrawTarget
, public SupportsWeakPtr
{
64 friend class SharedTextureHandle
;
65 friend class StandaloneTexture
;
66 friend class TextureHandle
;
67 friend class SourceSurfaceWebgl
;
68 friend class AutoSaveContext
;
71 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawTargetWebgl
, override
)
75 RefPtr
<WebGLFramebufferJS
> mFramebuffer
;
76 RefPtr
<WebGLTextureJS
> mTex
;
77 RefPtr
<WebGLTextureJS
> mClipMask
;
78 // The integer-aligned, scissor-compatible conservative bounds of the clip.
80 // The fractional, AA'd bounds of the clip rect, if applicable.
82 RefPtr
<DrawTargetSkia
> mSkia
;
83 // Skia DT pointing to the same pixel data, but without any applied clips.
84 RefPtr
<DrawTargetSkia
> mSkiaNoClip
;
85 // The Shmem backing the Skia DT, if applicable.
86 mozilla::ipc::Shmem mShmem
;
87 // The currently cached snapshot of the WebGL context
88 RefPtr
<DataSourceSurface
> mSnapshot
;
89 // Whether the framebuffer is still in the initially clear state.
91 // Whether or not the Skia target has valid contents and is being drawn to
92 bool mSkiaValid
= false;
93 // Whether or not Skia layering over the WebGL context is enabled
94 bool mSkiaLayer
= false;
95 // Whether the WebGL target was clear when the Skia layer was established.
96 bool mSkiaLayerClear
= false;
97 // Whether or not the WebGL context has valid contents and is being drawn to
98 bool mWebglValid
= true;
99 // Whether or not the clip state has changed since last used by SharedContext.
100 bool mClipChanged
= true;
101 // Whether or not the clip state needs to be refreshed. Sometimes the clip
102 // state may be overwritten and require a refresh later, even though it has
104 bool mRefreshClipState
= true;
105 // The framebuffer has been modified and should be copied to the swap chain.
106 bool mNeedsPresent
= true;
107 // The number of layers currently pushed.
108 int32_t mLayerDepth
= 0;
110 RefPtr
<TextureHandle
> mSnapshotTexture
;
112 // Store a log of clips currently pushed so that they can be used to init
113 // the clip state of temporary DTs.
117 RefPtr
<const Path
> mPath
;
119 bool operator==(const ClipStack
& aOther
) const;
122 std::vector
<ClipStack
> mClipStack
;
124 // The previous state of the clip stack when a mask was generated.
125 std::vector
<ClipStack
> mCachedClipStack
;
127 // UsageProfile stores per-frame counters for significant profiling events
128 // that assist in determining whether acceleration should still be used for
130 struct UsageProfile
{
131 uint32_t mFailedFrames
= 0;
132 uint32_t mFrameCount
= 0;
133 uint32_t mCacheMisses
= 0;
134 uint32_t mCacheHits
= 0;
135 uint32_t mUncachedDraws
= 0;
136 uint32_t mLayers
= 0;
137 uint32_t mReadbacks
= 0;
138 uint32_t mFallbacks
= 0;
142 bool RequiresRefresh() const;
144 void OnCacheMiss() { ++mCacheMisses
; }
145 void OnCacheHit() { ++mCacheHits
; }
146 void OnUncachedDraw() { ++mUncachedDraws
; }
147 void OnLayer() { ++mLayers
; }
148 void OnReadback() { ++mReadbacks
; }
149 void OnFallback() { ++mFallbacks
; }
152 UsageProfile mProfile
;
154 // SharedContext stores most of the actual WebGL state that may be used by
155 // any number of DrawTargetWebgl's that use it. Foremost, it holds the actual
156 // WebGL client context, programs, and buffers for mapping to WebGL.
157 // Secondarily, it holds shared caches for surfaces, glyphs, paths, and
158 // shadows so that each DrawTargetWebgl does not require its own cache. It is
159 // important that SetTarget is called to install the current DrawTargetWebgl
160 // before actually using the SharedContext, as the individual framebuffers
161 // and viewport are still maintained in DrawTargetWebgl itself.
162 class SharedContext
: public mozilla::RefCounted
<SharedContext
>,
163 public mozilla::SupportsWeakPtr
{
165 MOZ_DECLARE_REFCOUNTED_TYPENAME(SharedContext
)
170 WeakPtr
<DrawTargetWebgl
> mCurrentTarget
;
171 IntSize mViewportSize
;
172 // The current integer-aligned scissor rect.
174 // The current fractional AA'd clip rect bounds.
177 RefPtr
<ClientWebGLContext
> mWebgl
;
179 // Avoid spurious state changes by caching last used state.
180 RefPtr
<WebGLProgramJS
> mLastProgram
;
181 RefPtr
<WebGLTextureJS
> mLastTexture
;
182 RefPtr
<WebGLTextureJS
> mLastClipMask
;
183 // Whether the shader viewport state requires updating.
184 bool mDirtyViewport
= true;
185 // Whether the shader anti-aliasing state requires updating.
186 bool mDirtyAA
= true;
187 // Whether the shader clip AA bounds require updating.
188 bool mDirtyClip
= true;
190 // WebGL shader resources
191 RefPtr
<WebGLBufferJS
> mPathVertexBuffer
;
192 RefPtr
<WebGLVertexArrayJS
> mPathVertexArray
;
193 // The current insertion offset into the GPU path buffer.
194 uint32_t mPathVertexOffset
= 0;
195 // The maximum size of the GPU path buffer.
196 uint32_t mPathVertexCapacity
= 0;
197 // The maximum supported type complexity of a GPU path.
198 uint32_t mPathMaxComplexity
= 0;
199 // Whether to accelerate stroked paths with AAStroke.
200 bool mPathAAStroke
= true;
201 // Whether to accelerate stroked paths with WGR.
202 bool mPathWGRStroke
= false;
203 // Temporary buffer for generating WGR output into.
204 UniquePtr
<WGR::OutputVertex
[]> mWGROutputBuffer
;
205 RefPtr
<WebGLProgramJS
> mSolidProgram
;
206 RefPtr
<WebGLUniformLocationJS
> mSolidProgramViewport
;
207 RefPtr
<WebGLUniformLocationJS
> mSolidProgramAA
;
208 RefPtr
<WebGLUniformLocationJS
> mSolidProgramTransform
;
209 RefPtr
<WebGLUniformLocationJS
> mSolidProgramColor
;
210 RefPtr
<WebGLUniformLocationJS
> mSolidProgramClipMask
;
211 RefPtr
<WebGLUniformLocationJS
> mSolidProgramClipBounds
;
212 RefPtr
<WebGLProgramJS
> mImageProgram
;
213 RefPtr
<WebGLUniformLocationJS
> mImageProgramViewport
;
214 RefPtr
<WebGLUniformLocationJS
> mImageProgramAA
;
215 RefPtr
<WebGLUniformLocationJS
> mImageProgramTransform
;
216 RefPtr
<WebGLUniformLocationJS
> mImageProgramTexMatrix
;
217 RefPtr
<WebGLUniformLocationJS
> mImageProgramTexBounds
;
218 RefPtr
<WebGLUniformLocationJS
> mImageProgramColor
;
219 RefPtr
<WebGLUniformLocationJS
> mImageProgramSwizzle
;
220 RefPtr
<WebGLUniformLocationJS
> mImageProgramSampler
;
221 RefPtr
<WebGLUniformLocationJS
> mImageProgramClipMask
;
222 RefPtr
<WebGLUniformLocationJS
> mImageProgramClipBounds
;
224 // Scratch framebuffer used to wrap textures for miscellaneous utility ops.
225 RefPtr
<WebGLFramebufferJS
> mScratchFramebuffer
;
226 // Buffer filled with zero data for initializing textures.
227 RefPtr
<WebGLBufferJS
> mZeroBuffer
;
228 size_t mZeroSize
= 0;
229 // 1x1 texture with solid white mask for disabling clipping
230 RefPtr
<WebGLTextureJS
> mNoClipMask
;
232 uint32_t mMaxTextureSize
= 0;
233 bool mRasterizationTruncates
= false;
235 // The current blending operation.
236 CompositionOp mLastCompositionOp
= CompositionOp::OP_SOURCE
;
237 // The constant blend color used for the blending operation.
238 Maybe
<DeviceColor
> mLastBlendColor
;
240 // The cached scissor state. Operations that rely on scissor state should
241 // take care to enable or disable the cached scissor state as necessary.
242 bool mScissorEnabled
= false;
243 IntRect mLastScissor
= {-1, -1, -1, -1};
245 // A most-recently-used list of allocated texture handles.
246 LinkedList
<RefPtr
<TextureHandle
>> mTextureHandles
;
247 size_t mNumTextureHandles
= 0;
248 // User data key linking a SourceSurface with its TextureHandle.
249 UserDataKey mTextureHandleKey
= {0};
250 // User data key linking a SourceSurface with its shadow blur TextureHandle.
251 UserDataKey mShadowTextureKey
= {0};
252 // User data key linking a ScaledFont with its GlyphCache.
253 UserDataKey mGlyphCacheKey
= {0};
254 // List of all GlyphCaches currently allocated to fonts.
255 LinkedList
<GlyphCache
> mGlyphCaches
;
256 // Cache of rasterized paths.
257 UniquePtr
<PathCache
> mPathCache
;
258 // Collection of allocated shared texture pages that may be shared amongst
260 std::vector
<RefPtr
<SharedTexture
>> mSharedTextures
;
261 // Collection of allocated standalone textures that have a single assigned
263 std::vector
<RefPtr
<StandaloneTexture
>> mStandaloneTextures
;
264 size_t mUsedTextureMemory
= 0;
265 size_t mTotalTextureMemory
= 0;
266 // The total reserved memory for empty texture pages that are kept around
267 // for future allocations.
268 size_t mEmptyTextureMemory
= 0;
269 // A memory pressure event may signal from another thread that caches should
270 // be cleared if possible.
271 Atomic
<bool> mShouldClearCaches
;
272 // Whether the Shmem is currently being processed by the remote side. If so,
273 // we need to wait for processing to complete before any further commands
274 // modifying the Skia DT can proceed.
275 bool mWaitForShmem
= false;
277 const Matrix
& GetTransform() const { return mCurrentTarget
->mTransform
; }
279 bool IsContextLost() const;
282 bool CreateShaders();
283 void ResetPathVertexBuffer(bool aChanged
= true);
285 void SetBlendState(CompositionOp aOp
,
286 const Maybe
<DeviceColor
>& aBlendColor
= Nothing());
288 void SetClipRect(const Rect
& aClipRect
);
289 void SetClipRect(const IntRect
& aClipRect
) { SetClipRect(Rect(aClipRect
)); }
290 bool SetClipMask(const RefPtr
<WebGLTextureJS
>& aTex
);
291 bool SetNoClipMask();
292 bool HasClipMask() const {
293 return mLastClipMask
&& mLastClipMask
!= mNoClipMask
;
296 bool IsCurrentTarget(DrawTargetWebgl
* aDT
) const {
297 return aDT
== mCurrentTarget
;
299 bool SetTarget(DrawTargetWebgl
* aDT
);
301 // Reset the current target.
302 void ClearTarget() { mCurrentTarget
= nullptr; }
303 // Reset the last used texture to force binding next use.
304 void ClearLastTexture();
306 bool SupportsPattern(const Pattern
& aPattern
);
308 void EnableScissor(const IntRect
& aRect
);
309 void DisableScissor();
311 void SetTexFilter(WebGLTextureJS
* aTex
, bool aFilter
);
312 void InitTexParameters(WebGLTextureJS
* aTex
, bool aFilter
= true);
314 bool ReadInto(uint8_t* aDstData
, int32_t aDstStride
, SurfaceFormat aFormat
,
315 const IntRect
& aBounds
, TextureHandle
* aHandle
= nullptr);
316 already_AddRefed
<DataSourceSurface
> ReadSnapshot(
317 TextureHandle
* aHandle
= nullptr);
318 already_AddRefed
<TextureHandle
> WrapSnapshot(const IntSize
& aSize
,
319 SurfaceFormat aFormat
,
320 RefPtr
<WebGLTextureJS
> aTex
);
321 already_AddRefed
<TextureHandle
> CopySnapshot(
322 const IntRect
& aRect
, TextureHandle
* aHandle
= nullptr);
324 already_AddRefed
<WebGLTextureJS
> GetCompatibleSnapshot(
325 SourceSurface
* aSurface
) const;
326 bool IsCompatibleSurface(SourceSurface
* aSurface
) const;
328 bool UploadSurface(DataSourceSurface
* aData
, SurfaceFormat aFormat
,
329 const IntRect
& aSrcRect
, const IntPoint
& aDstOffset
,
330 bool aInit
, bool aZero
= false,
331 const RefPtr
<WebGLTextureJS
>& aTex
= nullptr);
332 already_AddRefed
<TextureHandle
> AllocateTextureHandle(
333 SurfaceFormat aFormat
, const IntSize
& aSize
, bool aAllowShared
= true,
334 bool aRenderable
= false);
335 bool DrawRectAccel(const Rect
& aRect
, const Pattern
& aPattern
,
336 const DrawOptions
& aOptions
,
337 Maybe
<DeviceColor
> aMaskColor
= Nothing(),
338 RefPtr
<TextureHandle
>* aHandle
= nullptr,
339 bool aTransformed
= true, bool aClipped
= true,
340 bool aAccelOnly
= false, bool aForceUpdate
= false,
341 const StrokeOptions
* aStrokeOptions
= nullptr,
342 const PathVertexRange
* aVertexRange
= nullptr);
344 already_AddRefed
<TextureHandle
> DrawStrokeMask(
345 const PathVertexRange
& aVertexRange
, const IntSize
& aSize
);
346 bool DrawPathAccel(const Path
* aPath
, const Pattern
& aPattern
,
347 const DrawOptions
& aOptions
,
348 const StrokeOptions
* aStrokeOptions
= nullptr,
349 bool aAllowStrokeAlpha
= false,
350 const ShadowOptions
* aShadow
= nullptr,
351 bool aCacheable
= true);
353 bool DrawGlyphsAccel(ScaledFont
* aFont
, const GlyphBuffer
& aBuffer
,
354 const Pattern
& aPattern
, const DrawOptions
& aOptions
,
355 const StrokeOptions
* aStrokeOptions
,
356 bool aUseSubpixelAA
);
358 void PruneTextureHandle(const RefPtr
<TextureHandle
>& aHandle
);
359 bool PruneTextureMemory(size_t aMargin
= 0, bool aPruneUnused
= true);
361 bool RemoveSharedTexture(const RefPtr
<SharedTexture
>& aTexture
);
362 bool RemoveStandaloneTexture(const RefPtr
<StandaloneTexture
>& aTexture
);
364 void UnlinkSurfaceTextures();
365 void UnlinkSurfaceTexture(const RefPtr
<TextureHandle
>& aHandle
);
366 void UnlinkGlyphCaches();
368 void OnMemoryPressure();
369 void ClearAllTextures();
370 void ClearEmptyTextureMemory();
371 void ClearCachesIfNecessary();
373 void WaitForShmem(DrawTargetWebgl
* aTarget
);
378 RefPtr
<SharedContext
> mSharedContext
;
380 static MOZ_THREAD_LOCAL(SharedContext
*) sSharedContext
;
382 // Try to keep around the shared context for the main thread in case canvases
383 // are rapidly recreated and destroyed.
384 static RefPtr
<SharedContext
> sMainSharedContext
;
390 static already_AddRefed
<DrawTargetWebgl
> Create(const IntSize
& aSize
,
391 SurfaceFormat aFormat
);
393 bool Init(const IntSize
& aSize
, SurfaceFormat aFormat
);
395 bool IsValid() const override
;
397 DrawTargetType
GetType() const override
{
398 return DrawTargetType::HARDWARE_RASTER
;
400 BackendType
GetBackendType() const override
{ return BackendType::WEBGL
; }
401 IntSize
GetSize() const override
{ return mSize
; }
403 already_AddRefed
<SourceSurface
> GetDataSnapshot();
404 already_AddRefed
<SourceSurface
> Snapshot() override
;
405 already_AddRefed
<SourceSurface
> GetOptimizedSnapshot(DrawTarget
* aTarget
);
406 already_AddRefed
<SourceSurface
> GetBackingSurface() override
;
407 void DetachAllSnapshots() override
;
409 void BeginFrame(const IntRect
& aPersistedRect
);
411 bool RequiresRefresh() const { return mProfile
.RequiresRefresh(); }
413 bool LockBits(uint8_t** aData
, IntSize
* aSize
, int32_t* aStride
,
414 SurfaceFormat
* aFormat
, IntPoint
* aOrigin
= nullptr) override
;
415 void ReleaseBits(uint8_t* aData
) override
;
417 void Flush() override
{}
419 SourceSurface
* aSurface
, const Rect
& aDest
, const Rect
& aSource
,
420 const DrawSurfaceOptions
& aSurfOptions
= DrawSurfaceOptions(),
421 const DrawOptions
& aOptions
= DrawOptions()) override
;
422 void DrawFilter(FilterNode
* aNode
, const Rect
& aSourceRect
,
423 const Point
& aDestPoint
,
424 const DrawOptions
& aOptions
= DrawOptions()) override
;
425 void DrawSurfaceWithShadow(SourceSurface
* aSurface
, const Point
& aDest
,
426 const ShadowOptions
& aShadow
,
427 CompositionOp aOperator
) override
;
428 void DrawShadow(const Path
* aPath
, const Pattern
& aPattern
,
429 const ShadowOptions
& aShadow
, const DrawOptions
& aOptions
,
430 const StrokeOptions
* aStrokeOptions
= nullptr) override
;
432 void ClearRect(const Rect
& aRect
) override
;
433 void CopySurface(SourceSurface
* aSurface
, const IntRect
& aSourceRect
,
434 const IntPoint
& aDestination
) override
;
435 void FillRect(const Rect
& aRect
, const Pattern
& aPattern
,
436 const DrawOptions
& aOptions
= DrawOptions()) override
;
437 void StrokeRect(const Rect
& aRect
, const Pattern
& aPattern
,
438 const StrokeOptions
& aStrokeOptions
= StrokeOptions(),
439 const DrawOptions
& aOptions
= DrawOptions()) override
;
440 bool StrokeLineAccel(const Point
& aStart
, const Point
& aEnd
,
441 const Pattern
& aPattern
,
442 const StrokeOptions
& aStrokeOptions
,
443 const DrawOptions
& aOptions
, bool aClosed
= false);
444 void StrokeLine(const Point
& aStart
, const Point
& aEnd
,
445 const Pattern
& aPattern
,
446 const StrokeOptions
& aStrokeOptions
= StrokeOptions(),
447 const DrawOptions
& aOptions
= DrawOptions()) override
;
448 void Stroke(const Path
* aPath
, const Pattern
& aPattern
,
449 const StrokeOptions
& aStrokeOptions
= StrokeOptions(),
450 const DrawOptions
& aOptions
= DrawOptions()) override
;
451 void Fill(const Path
* aPath
, const Pattern
& aPattern
,
452 const DrawOptions
& aOptions
= DrawOptions()) override
;
454 void SetPermitSubpixelAA(bool aPermitSubpixelAA
) override
;
455 void FillGlyphs(ScaledFont
* aFont
, const GlyphBuffer
& aBuffer
,
456 const Pattern
& aPattern
,
457 const DrawOptions
& aOptions
= DrawOptions()) override
;
458 void StrokeGlyphs(ScaledFont
* aFont
, const GlyphBuffer
& aBuffer
,
459 const Pattern
& aPattern
,
460 const StrokeOptions
& aStrokeOptions
= StrokeOptions(),
461 const DrawOptions
& aOptions
= DrawOptions()) override
;
462 void Mask(const Pattern
& aSource
, const Pattern
& aMask
,
463 const DrawOptions
& aOptions
= DrawOptions()) override
;
464 void MaskSurface(const Pattern
& aSource
, SourceSurface
* aMask
, Point aOffset
,
465 const DrawOptions
& aOptions
= DrawOptions()) override
;
466 bool Draw3DTransformedSurface(SourceSurface
* aSurface
,
467 const Matrix4x4
& aMatrix
) override
;
468 void PushClip(const Path
* aPath
) override
;
469 void PushClipRect(const Rect
& aRect
) override
;
470 void PushDeviceSpaceClipRects(const IntRect
* aRects
,
471 uint32_t aCount
) override
;
472 void PopClip() override
;
473 bool RemoveAllClips() override
;
474 void PushLayer(bool aOpaque
, Float aOpacity
, SourceSurface
* aMask
,
475 const Matrix
& aMaskTransform
,
476 const IntRect
& aBounds
= IntRect(),
477 bool aCopyBackground
= false) override
;
478 void PushLayerWithBlend(
479 bool aOpaque
, Float aOpacity
, SourceSurface
* aMask
,
480 const Matrix
& aMaskTransform
, const IntRect
& aBounds
= IntRect(),
481 bool aCopyBackground
= false,
482 CompositionOp aCompositionOp
= CompositionOp::OP_OVER
) override
;
483 void PopLayer() override
;
484 already_AddRefed
<SourceSurface
> CreateSourceSurfaceFromData(
485 unsigned char* aData
, const IntSize
& aSize
, int32_t aStride
,
486 SurfaceFormat aFormat
) const override
;
487 already_AddRefed
<SourceSurface
> OptimizeSourceSurface(
488 SourceSurface
* aSurface
) const override
;
489 already_AddRefed
<SourceSurface
> OptimizeSourceSurfaceForUnknownAlpha(
490 SourceSurface
* aSurface
) const override
;
491 already_AddRefed
<SourceSurface
> CreateSourceSurfaceFromNativeSurface(
492 const NativeSurface
& aSurface
) const override
;
493 already_AddRefed
<DrawTarget
> CreateSimilarDrawTarget(
494 const IntSize
& aSize
, SurfaceFormat aFormat
) const override
;
495 bool CanCreateSimilarDrawTarget(const IntSize
& aSize
,
496 SurfaceFormat aFormat
) const override
;
497 RefPtr
<DrawTarget
> CreateClippedDrawTarget(const Rect
& aBounds
,
498 SurfaceFormat aFormat
) override
;
500 already_AddRefed
<PathBuilder
> CreatePathBuilder(
501 FillRule aFillRule
= FillRule::FILL_WINDING
) const override
;
502 already_AddRefed
<GradientStops
> CreateGradientStops(
503 GradientStop
* aStops
, uint32_t aNumStops
,
504 ExtendMode aExtendMode
= ExtendMode::CLAMP
) const override
;
505 already_AddRefed
<FilterNode
> CreateFilter(FilterType aType
) override
;
506 void SetTransform(const Matrix
& aTransform
) override
;
507 void* GetNativeSurface(NativeSurfaceType aType
) override
;
509 Maybe
<layers::SurfaceDescriptor
> GetFrontBuffer();
511 void OnMemoryPressure() { mSharedContext
->OnMemoryPressure(); }
513 operator std::string() const {
514 std::stringstream stream
;
515 stream
<< "DrawTargetWebgl(" << this << ")";
520 bool SupportsPattern(const Pattern
& aPattern
) {
521 return mSharedContext
->SupportsPattern(aPattern
);
524 bool SetSimpleClipRect();
525 bool GenerateComplexClipMask();
526 bool PrepareContext(bool aClipped
= true);
528 void DrawRectFallback(const Rect
& aRect
, const Pattern
& aPattern
,
529 const DrawOptions
& aOptions
,
530 Maybe
<DeviceColor
> aMaskColor
= Nothing(),
531 bool aTransform
= true, bool aClipped
= true,
532 const StrokeOptions
* aStrokeOptions
= nullptr);
533 bool DrawRect(const Rect
& aRect
, const Pattern
& aPattern
,
534 const DrawOptions
& aOptions
,
535 Maybe
<DeviceColor
> aMaskColor
= Nothing(),
536 RefPtr
<TextureHandle
>* aHandle
= nullptr,
537 bool aTransformed
= true, bool aClipped
= true,
538 bool aAccelOnly
= false, bool aForceUpdate
= false,
539 const StrokeOptions
* aStrokeOptions
= nullptr);
541 ColorPattern
GetClearPattern() const;
543 bool RectContainsViewport(const Rect
& aRect
) const;
545 bool ShouldAccelPath(const DrawOptions
& aOptions
,
546 const StrokeOptions
* aStrokeOptions
);
547 void DrawPath(const Path
* aPath
, const Pattern
& aPattern
,
548 const DrawOptions
& aOptions
,
549 const StrokeOptions
* aStrokeOptions
= nullptr,
550 bool aAllowStrokeAlpha
= false);
556 bool FlushFromSkia();
558 void WaitForShmem() {
559 if (mSharedContext
->mWaitForShmem
) {
560 mSharedContext
->WaitForShmem(this);
564 void MarkSkiaChanged(bool aOverwrite
= false) {
569 } else if (!mSkiaValid
) {
571 } else if (mSkiaLayer
) {
578 void MarkSkiaChanged(const DrawOptions
& aOptions
);
580 bool ShouldUseSubpixelAA(ScaledFont
* aFont
, const DrawOptions
& aOptions
);
582 bool ReadInto(uint8_t* aDstData
, int32_t aDstStride
);
583 already_AddRefed
<DataSourceSurface
> ReadSnapshot();
584 already_AddRefed
<TextureHandle
> CopySnapshot(const IntRect
& aRect
);
585 already_AddRefed
<TextureHandle
> CopySnapshot() {
586 return CopySnapshot(GetRect());
589 void ClearSnapshot(bool aCopyOnWrite
= true, bool aNeedHandle
= false);
591 bool CreateFramebuffer();
593 // PrepareContext may sometimes be used recursively. When this occurs, ensure
594 // that clip state is restored after the context is used.
595 struct AutoRestoreContext
{
596 DrawTargetWebgl
* mTarget
;
598 RefPtr
<WebGLTextureJS
> mLastClipMask
;
600 explicit AutoRestoreContext(DrawTargetWebgl
* aTarget
);
602 ~AutoRestoreContext();
607 } // namespace mozilla
609 #endif // _MOZILLA_GFX_DRAWTARGETWEBGL_H