Changeset 250188 in webkit
- Timestamp:
- Sep 21, 2019 7:40:44 PM (5 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r250182 r250188 1 2019-09-21 Brent Fulgham <bfulgham@apple.com> 2 3 [FTW] Resolve crashes found while running canvas tests 4 https://bugs.webkit.org/show_bug.cgi?id=202062 5 6 Reviewed by Don Olmstead. 7 8 * platform/graphics/Pattern.h: 9 * platform/graphics/win/Direct2DOperations.cpp: 10 (WebCore::Direct2D::FillSource::FillSource): Take GraphicsContext as argument, rather than 11 a PlatformContextDirect2D since downstream operations require the former. 12 (WebCore::Direct2D::StrokeSource::StrokeSource): Ditto. 13 (WebCore::Direct2D::clip): Use new 'pushClip' helper function. 14 * platform/graphics/win/Direct2DOperations.h: 15 * platform/graphics/win/GraphicsContextDirect2D.cpp: 16 (WebCore::GraphicsContext::drawPath): 17 (WebCore::GraphicsContext::fillPath): 18 (WebCore::GraphicsContext::strokePath): 19 (WebCore::GraphicsContext::fillRect): 20 (WebCore::GraphicsContext::fillRectWithRoundedHole): 21 (WebCore::GraphicsContext::strokeRect): 22 * platform/graphics/win/GraphicsContextImplDirect2D.cpp: 23 (WebCore::GraphicsContextImplDirect2D::fillRect): Update to pass GraphicsContext. 24 (WebCore::GraphicsContextImplDirect2D::fillRectWithRoundedHole): Ditto. 25 (WebCore::GraphicsContextImplDirect2D::fillPath): Ditto. 26 (WebCore::GraphicsContextImplDirect2D::strokeRect): Ditto. 27 (WebCore::GraphicsContextImplDirect2D::strokePath): Ditto. 28 (WebCore::GraphicsContextImplDirect2D::drawGlyphs): Ditto. 29 * platform/graphics/win/ImageBufferDataDirect2D.cpp: 30 (WebCore::ImageBufferData::copyRectFromSourceToData): Correct return behavior. 31 (WebCore::ImageBufferData::compatibleBitmap): Make a copy if the render target is 32 backed by the ID2D1Bitmap we are trying to draw with. 33 * platform/graphics/win/PatternDirect2D.cpp: 34 (WebCore::Pattern::createPlatformPattern const): Remove 'PlatformContextDirect2D' contructor, 35 since we always need a GraphicsContext for the Image class. 36 * platform/graphics/win/PlatformContextDirect2D.cpp: 37 (WebCore::PlatformContextDirect2D::clipLayer const): Added. 38 (WebCore::PlatformContextDirect2D::clearClips): Added. 39 (WebCore::PlatformContextDirect2D::restore): Update to use m_stateStack, rather than 40 the m_renderStates vector. 41 (WebCore::PlatformContextDirect2D::save): Ditto. 42 (WebCore::PlatformContextDirect2D::pushRenderClip): Ditto. 43 (WebCore::PlatformContextDirect2D::setActiveLayer): Ditto. 44 (WebCore::PlatformContextDirect2D::endDraw): Ditto. 45 (WebCore::PlatformContextDirect2D::notifyPostDrawObserver): Ditto. 46 (WebCore::PlatformContextDirect2D::pushClip): Ditto. 47 * platform/graphics/win/PlatformContextDirect2D.h: 48 (WebCore::PlatformContextDirect2D::hasSavedState const): 49 (WebCore::PlatformContextDirect2D::clipLayer const): Deleted. 50 1 51 2019-09-20 Antoine Quint <graouts@apple.com> 2 52 -
trunk/Source/WebCore/platform/graphics/Pattern.h
r248020 r250188 67 67 PlatformPatternPtr createPlatformPattern(const AffineTransform& userSpaceTransformation) const; 68 68 #else 69 PlatformPatternPtr createPlatformPattern(PlatformGraphicsContext&, float alpha, const AffineTransform& userSpaceTransformation) const;70 69 PlatformPatternPtr createPlatformPattern(const GraphicsContext&, float alpha, const AffineTransform& userSpaceTransformation) const; 71 70 #endif -
trunk/Source/WebCore/platform/graphics/win/Direct2DOperations.cpp
r250085 r250188 290 290 } // namespace State 291 291 292 FillSource::FillSource(const GraphicsContextState& state, PlatformContextDirect2D& platformContext)292 FillSource::FillSource(const GraphicsContextState& state, const GraphicsContext& context) 293 293 : globalAlpha(state.alpha) 294 294 , color(state.fillColor) 295 295 , fillRule(state.fillRule) 296 296 { 297 ASSERT(context.hasPlatformContext()); 298 auto& platformContext = *context.platformContext(); 299 297 300 if (state.fillPattern) { 298 301 AffineTransform userToBaseCTM; // FIXME: This isn't really needed on Windows 299 brush = state.fillPattern->createPlatformPattern( platformContext, state.alpha, userToBaseCTM);300 } else if (state.fillGradient )302 brush = state.fillPattern->createPlatformPattern(context, state.alpha, userToBaseCTM); 303 } else if (state.fillGradient && !state.fillGradient->stops().isEmpty()) 301 304 brush = state.fillGradient->createPlatformGradientIfNecessary(platformContext.renderTarget()); 302 305 else … … 304 307 } 305 308 306 StrokeSource::StrokeSource(const GraphicsContextState& state, PlatformContextDirect2D& platformContext)309 StrokeSource::StrokeSource(const GraphicsContextState& state, const GraphicsContext& context) 307 310 : globalAlpha(state.alpha) 308 311 , thickness(state.strokeThickness) 309 312 , color(state.strokeColor) 310 313 { 314 ASSERT(context.hasPlatformContext()); 315 auto& platformContext = *context.platformContext(); 316 311 317 if (state.strokePattern) { 312 318 AffineTransform userToBaseCTM; // FIXME: This isn't really needed on Windows 313 brush = state.strokePattern->createPlatformPattern( platformContext, state.alpha, userToBaseCTM);319 brush = state.strokePattern->createPlatformPattern(context, state.alpha, userToBaseCTM); 314 320 } else if (state.strokeGradient) 315 321 brush = state.strokeGradient->createPlatformGradientIfNecessary(platformContext.renderTarget()); … … 1117 1123 void clip(PlatformContextDirect2D& platformContext, const FloatRect& rect) 1118 1124 { 1119 if (platformContext.m_renderStates.isEmpty())1120 save(platformContext);1121 1122 1125 platformContext.renderTarget()->PushAxisAlignedClip(rect, D2D1_ANTIALIAS_MODE_PER_PRIMITIVE); 1123 platformContext. m_renderStates.last().m_clips.append(PlatformContextDirect2D::AxisAlignedClip);1126 platformContext.pushClip(PlatformContextDirect2D::AxisAlignedClip); 1124 1127 1125 1128 if (auto* graphicsContextPrivate = platformContext.graphicsContextPrivate()) -
trunk/Source/WebCore/platform/graphics/win/Direct2DOperations.h
r249335 r250188 75 75 struct FillSource { 76 76 FillSource() = default; 77 explicit FillSource(const GraphicsContextState&, PlatformContextDirect2D&);77 explicit FillSource(const GraphicsContextState&, const GraphicsContext&); 78 78 79 79 float globalAlpha { 0 }; … … 86 86 struct StrokeSource { 87 87 StrokeSource() = default; 88 explicit StrokeSource(const GraphicsContextState&, PlatformContextDirect2D&);88 explicit StrokeSource(const GraphicsContextState&, const GraphicsContext&); 89 89 90 90 float globalAlpha { 0 }; -
trunk/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp
r249921 r250188 590 590 auto& state = this->state(); 591 591 auto& context = *platformContext(); 592 Direct2D::drawPath(context, path, Direct2D::StrokeSource(state, context), Direct2D::ShadowState(state));592 Direct2D::drawPath(context, path, Direct2D::StrokeSource(state, *this), Direct2D::ShadowState(state)); 593 593 } 594 594 … … 606 606 auto& state = this->state(); 607 607 auto& context = *platformContext(); 608 Direct2D::fillPath(context, path, Direct2D::FillSource(state, context), Direct2D::ShadowState(state));608 Direct2D::fillPath(context, path, Direct2D::FillSource(state, *this), Direct2D::ShadowState(state)); 609 609 } 610 610 … … 622 622 auto& state = this->state(); 623 623 auto& context = *platformContext(); 624 Direct2D::strokePath(context, path, Direct2D::StrokeSource(state, context), Direct2D::ShadowState(state));624 Direct2D::strokePath(context, path, Direct2D::StrokeSource(state, *this), Direct2D::ShadowState(state)); 625 625 } 626 626 … … 638 638 auto& state = this->state(); 639 639 auto& context = *platformContext(); 640 Direct2D::fillRect(context, rect, Direct2D::FillSource(state, context), Direct2D::ShadowState(state));640 Direct2D::fillRect(context, rect, Direct2D::FillSource(state, *this), Direct2D::ShadowState(state)); 641 641 } 642 642 … … 682 682 auto& state = this->state(); 683 683 auto& context = *platformContext(); 684 Direct2D::fillRectWithRoundedHole(context, rect, roundedHoleRect, Direct2D::FillSource(state, context), Direct2D::ShadowState(state));684 Direct2D::fillRectWithRoundedHole(context, rect, roundedHoleRect, Direct2D::FillSource(state, *this), Direct2D::ShadowState(state)); 685 685 } 686 686 … … 862 862 auto& state = this->state(); 863 863 auto& context = *platformContext(); 864 Direct2D::strokeRect(context, rect, lineWidth, Direct2D::StrokeSource(state, context), Direct2D::ShadowState(state));864 Direct2D::strokeRect(context, rect, lineWidth, Direct2D::StrokeSource(state, *this), Direct2D::ShadowState(state)); 865 865 } 866 866 -
trunk/Source/WebCore/platform/graphics/win/GraphicsContextImplDirect2D.cpp
r249335 r250188 146 146 { 147 147 auto& state = graphicsContext().state(); 148 Direct2D::fillRect(m_platformContext, rect, Direct2D::FillSource(state, m_platformContext), Direct2D::ShadowState(state));148 Direct2D::fillRect(m_platformContext, rect, Direct2D::FillSource(state, graphicsContext()), Direct2D::ShadowState(state)); 149 149 } 150 150 … … 193 193 auto& state = graphicsContext().state(); 194 194 195 Direct2D::FillSource fillSource(state, m_platformContext);195 Direct2D::FillSource fillSource(state, graphicsContext()); 196 196 fillSource.brush = m_platformContext.brushWithColor(color); 197 197 … … 202 202 { 203 203 auto& state = graphicsContext().state(); 204 Direct2D::fillPath(m_platformContext, path, Direct2D::FillSource(state, m_platformContext), Direct2D::ShadowState(state));204 Direct2D::fillPath(m_platformContext, path, Direct2D::FillSource(state, graphicsContext()), Direct2D::ShadowState(state)); 205 205 } 206 206 … … 215 215 { 216 216 auto& state = graphicsContext().state(); 217 Direct2D::strokeRect(m_platformContext, rect, lineWidth, Direct2D::StrokeSource(state, m_platformContext), Direct2D::ShadowState(state));217 Direct2D::strokeRect(m_platformContext, rect, lineWidth, Direct2D::StrokeSource(state, graphicsContext()), Direct2D::ShadowState(state)); 218 218 } 219 219 … … 221 221 { 222 222 auto& state = graphicsContext().state(); 223 Direct2D::strokePath(m_platformContext, path, Direct2D::StrokeSource(state, m_platformContext), Direct2D::ShadowState(state));223 Direct2D::strokePath(m_platformContext, path, Direct2D::StrokeSource(state, graphicsContext()), Direct2D::ShadowState(state)); 224 224 } 225 225 … … 264 264 265 265 auto& state = graphicsContext().state(); 266 Direct2D::drawGlyphs(m_platformContext, Direct2D::FillSource(state, m_platformContext), Direct2D::StrokeSource(state, m_platformContext),266 Direct2D::drawGlyphs(m_platformContext, Direct2D::FillSource(state, graphicsContext()), Direct2D::StrokeSource(state, graphicsContext()), 267 267 Direct2D::ShadowState(state), point, font, syntheticBoldOffset, glyphs, horizontalAdvances, glyphOffsets, xOffset, 268 268 state.textDrawingMode, state.strokeThickness, state.shadowOffset, state.shadowColor); -
trunk/Source/WebCore/platform/graphics/win/ImageBufferDataDirect2D.cpp
r250085 r250188 429 429 430 430 if (byteFormat == AlphaPremultiplication::Unpremultiplied) 431 copyRectFromSourceToDestAndSetPremultiplication<AlphaPremultiplication::Unpremultiplied>(sourceRect, sourceRect.size(), source.data(), backingStoreSize, data.data(), destBufferPosition);432 else 433 431 return copyRectFromSourceToDestAndSetPremultiplication<AlphaPremultiplication::Unpremultiplied>(sourceRect, sourceRect.size(), source.data(), backingStoreSize, data.data(), destBufferPosition); 432 433 return copyRectFromSourceToDestAndSetPremultiplication<AlphaPremultiplication::Premultiplied>(sourceRect, sourceRect.size(), source.data(), backingStoreSize, data.data(), destBufferPosition); 434 434 } 435 435 … … 479 479 return bitmap; 480 480 481 if (platformContext->renderTarget() == renderTarget) 482 return bitmap; 481 if (platformContext->renderTarget() == renderTarget) { 482 COMPtr<ID2D1BitmapRenderTarget> bitmapTarget(Query, renderTarget); 483 if (bitmapTarget) { 484 COMPtr<ID2D1Bitmap> backingBitmap; 485 if (SUCCEEDED(bitmapTarget->GetBitmap(&backingBitmap))) { 486 if (backingBitmap != bitmap) 487 return bitmap; 488 489 // We can't draw an ID2D1Bitmap to itself. Must return a copy. 490 COMPtr<ID2D1Bitmap> copiedBitmap; 491 if (SUCCEEDED(renderTarget->CreateBitmap(bitmap->GetPixelSize(), Direct2D::bitmapProperties(), &copiedBitmap))) { 492 if (SUCCEEDED(copiedBitmap->CopyFromBitmap(nullptr, bitmap.get(), nullptr))) 493 return copiedBitmap; 494 } 495 } 496 } 497 } 483 498 484 499 auto size = bitmap->GetPixelSize(); -
trunk/Source/WebCore/platform/graphics/win/PatternDirect2D.cpp
r249110 r250188 40 40 ID2D1BitmapBrush* Pattern::createPlatformPattern(const GraphicsContext& context, float alpha, const AffineTransform& userSpaceTransformation) const 41 41 { 42 auto platformContext = context.platformContext();43 RELEASE_ASSERT(platformContext);44 45 return createPlatformPattern(*platformContext, alpha, userSpaceTransformation);46 }47 48 ID2D1BitmapBrush* Pattern::createPlatformPattern(PlatformGraphicsContext& context, float alpha, const AffineTransform& userSpaceTransformation) const49 {50 42 AffineTransform patternTransform = userSpaceTransformation * m_patternSpaceTransformation; 51 43 auto bitmapBrushProperties = D2D1::BitmapBrushProperties(); … … 58 50 59 51 auto& patternImage = tileImage(); 60 auto nativeImage = patternImage.nativeImage(nullptr); 52 auto nativeImage = patternImage.nativeImage(&context); 53 if (!nativeImage) 54 return nullptr; 55 56 auto platformContext = context.platformContext(); 57 RELEASE_ASSERT(platformContext); 61 58 62 59 ID2D1BitmapBrush* patternBrush = nullptr; 63 HRESULT hr = context.renderTarget()->CreateBitmapBrush(nativeImage.get(), &bitmapBrushProperties, &brushProperties, &patternBrush);60 HRESULT hr = platformContext->renderTarget()->CreateBitmapBrush(nativeImage.get(), &bitmapBrushProperties, &brushProperties, &patternBrush); 64 61 ASSERT(SUCCEEDED(hr)); 65 62 return patternBrush; -
trunk/Source/WebCore/platform/graphics/win/PlatformContextDirect2D.cpp
r250085 r250188 39 39 public: 40 40 State() = default; 41 42 COMPtr<ID2D1DrawingStateBlock> m_drawingStateBlock; 43 COMPtr<ID2D1Layer> m_activeLayer; 44 Vector<Direct2DLayerType> m_clips; 41 45 }; 42 46 … … 50 54 } 51 55 56 ID2D1Layer* PlatformContextDirect2D::clipLayer() const 57 { 58 return m_state->m_activeLayer.get(); 59 } 60 61 void PlatformContextDirect2D::clearClips(Vector<Direct2DLayerType>& clips) 62 { 63 for (auto clipType = clips.rbegin(); clipType != clips.rend(); ++clipType) { 64 if (*clipType == AxisAlignedClip) 65 m_renderTarget->PopAxisAlignedClip(); 66 else 67 m_renderTarget->PopLayer(); 68 } 69 70 clips.clear(); 71 } 72 52 73 void PlatformContextDirect2D::restore() 53 74 { … … 61 82 return; 62 83 63 if (!m_renderStates.isEmpty()) {64 auto restoreState = m_renderStates.takeLast();84 auto& restoreState = m_stateStack.last(); 85 if (restoreState.m_drawingStateBlock) { 65 86 m_renderTarget->RestoreDrawingState(restoreState.m_drawingStateBlock.get()); 66 67 for (auto clipType = restoreState.m_clips.rbegin(); clipType != restoreState.m_clips.rend(); ++clipType) { 68 if (*clipType == AxisAlignedClip) 69 m_renderTarget->PopAxisAlignedClip(); 70 else 71 m_renderTarget->PopLayer(); 72 } 73 } 87 restoreState.m_drawingStateBlock = nullptr; 88 } 89 90 clearClips(restoreState.m_clips); 74 91 75 92 m_stateStack.removeLast(); … … 88 105 m_state = &m_stateStack.last(); 89 106 90 RenderState currentState; 91 GraphicsContext::systemFactory()->CreateDrawingStateBlock(¤tState.m_drawingStateBlock); 92 93 m_renderTarget->SaveDrawingState(currentState.m_drawingStateBlock.get()); 94 95 m_renderStates.append(currentState); 107 GraphicsContext::systemFactory()->CreateDrawingStateBlock(&m_state->m_drawingStateBlock); 108 109 m_renderTarget->SaveDrawingState(m_state->m_drawingStateBlock.get()); 96 110 } 97 111 … … 99 113 { 100 114 ASSERT(hasSavedState()); 101 m_ renderStates.last().m_clips.append(clipType);115 m_state->m_clips.append(clipType); 102 116 } 103 117 … … 105 119 { 106 120 ASSERT(hasSavedState()); 107 m_ renderStates.last().m_activeLayer = layer;121 m_state->m_activeLayer = layer; 108 122 } 109 123 … … 265 279 ASSERT(m_renderTarget); 266 280 267 while ( !m_renderStates.isEmpty())281 while (m_stateStack.size() > 1) 268 282 restore(); 283 284 clearClips(m_state->m_clips); 269 285 270 286 ASSERT(m_stateStack.size() >= 1); … … 299 315 } 300 316 317 void PlatformContextDirect2D::pushClip(Direct2DLayerType clipType) 318 { 319 m_state->m_clips.append(clipType); 320 } 321 301 322 } // namespace WebCore 302 323 -
trunk/Source/WebCore/platform/graphics/win/PlatformContextDirect2D.h
r249921 r250188 62 62 void setGraphicsContextPrivate(GraphicsContextPlatformPrivate* graphicsContextPrivate) { m_graphicsContextPrivate = graphicsContextPrivate; } 63 63 64 ID2D1Layer* clipLayer() const { return m_renderStates.last().m_activeLayer.get(); }64 ID2D1Layer* clipLayer() const; 65 65 ID2D1StrokeStyle* strokeStyle(); 66 66 D2D1_STROKE_STYLE_PROPERTIES strokeStyleProperties() const; … … 72 72 void restore(); 73 73 74 bool hasSavedState() const { return !m_ renderStates.isEmpty(); }74 bool hasSavedState() const { return !m_stateStack.isEmpty(); } 75 75 76 76 void beginDraw(); … … 83 83 void recomputeStrokeStyle(); 84 84 float strokeThickness() const { return m_strokeThickness; } 85 86 struct RenderState {87 COMPtr<ID2D1DrawingStateBlock> m_drawingStateBlock;88 COMPtr<ID2D1Layer> m_activeLayer;89 Vector<Direct2DLayerType> m_clips;90 };91 Vector<RenderState> m_renderStates;92 85 93 86 struct TransparencyLayerState { … … 118 111 void notifyPostDrawObserver(); 119 112 113 void pushClip(Direct2DLayerType); 114 120 115 private: 116 void clearClips(Vector<Direct2DLayerType>&); 117 121 118 GraphicsContextPlatformPrivate* m_graphicsContextPrivate { nullptr }; 122 119
Note: See TracChangeset
for help on using the changeset viewer.