Changeset 208019 in webkit
- Timestamp:
- Oct 27, 2016 5:21:31 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r208014 r208019 1 2016-10-25 Brent Fulgham <bfulgham@apple.com> 2 3 [Win][Direct2D] Create a RAII Helper Class for the Render Target 4 https://bugs.webkit.org/show_bug.cgi?id=164005 5 6 Reviewed by Alex Christensen. 7 8 Tested by existing SVG, image, and Canvas layout tests. 9 10 * platform/graphics/GraphicsContext.h: 11 * platform/graphics/win/GradientDirect2D.cpp: 12 (WebCore::Gradient::fill): Use new convenience helper class. 13 * platform/graphics/win/GraphicsContextDirect2D.cpp: 14 (WebCore::GraphicsContext::didBeginDraw): 15 (WebCore::GraphicsContextPlatformPrivate::GraphicsContextPlatformPrivate): 16 (WebCore::GraphicsContextPlatformPrivate::~GraphicsContextPlatformPrivate): Add an 17 assertion that we are in a valid state when cleaning up the graphics context. 18 (WebCore::GraphicsContextPlatformPrivate::clip): Clipping can only happen in a Draw operation. 19 Open a new BeginDraw if asked to Clip. The Begin must stay active when this method returns, 20 as the Clip layer is only valid during a Draw operation. 21 (WebCore::GraphicsContextPlatformPrivate::beginDraw): Added. 22 (WebCore::GraphicsContextPlatformPrivate::endDraw): Added. 23 (WebCore::GraphicsContext::beginDrawIfNeeded): Added. 24 (WebCore::GraphicsContext::endDraw): Added. 25 (WebCore::GraphicsContext::drawWithoutShadow): Revise to use new RenderTargetHelper class. 26 (WebCore::GraphicsContext::drawWithShadow): Ditto. 27 (WebCore::GraphicsContext::platformFillRoundedRect): Ditto. 28 (WebCore::GraphicsContext::fillRectWithRoundedHole): Ditto. 29 (WebCore::GraphicsContext::setDidBeginDraw): Deleted. 30 * platform/graphics/win/GraphicsContextPlatformPrivateDirect2D.h: 31 (WebCore::GraphicsContextPlatformPrivate::didBeginDraw): Revise to use count instead of 32 a separate boolean. 33 * platform/graphics/win/ImageBufferDataDirect2D.cpp: 34 (WebCore::ImageBufferData::getData): Revise to use new RenderTargetHelper class. 35 * platform/graphics/win/NativeImageDirect2D.cpp: 36 (WebCore::drawNativeImage): Ditto. 37 * platform/graphics/win/RenderTargetHelper.h: Added. 38 (WebCore::RenderTargetHelper::RenderTargetHelper): 39 (WebCore::RenderTargetHelper::~RenderTargetHelper): 40 (WebCore::RenderTargetHelper::endDraw): 41 * svg/graphics/SVGImage.cpp: 42 (WebCore::SVGImage::nativeImage): Revise to use new RenderTargetHelper class. 43 1 44 2016-10-27 Wenson Hsieh <wenson_hsieh@apple.com> 2 45 -
trunk/Source/WebCore/platform/graphics/GraphicsContext.h
r207868 r208019 553 553 WEBCORE_EXPORT static ID2D1RenderTarget* defaultRenderTarget(); 554 554 555 WEBCORE_EXPORT void setDidBeginDraw(bool);555 WEBCORE_EXPORT bool beginDrawIfNeeded(); 556 556 WEBCORE_EXPORT bool didBeginDraw() const; 557 557 D2D1_COLOR_F colorWithGlobalAlpha(const Color&) const; 558 WEBCORE_EXPORT void endDraw(); 558 559 559 560 ID2D1Brush* solidStrokeBrush() const; -
trunk/Source/WebCore/platform/graphics/win/GradientDirect2D.cpp
r207681 r208019 29 29 #include "FloatPoint.h" 30 30 #include "GraphicsContext.h" 31 #include "RenderTargetScopedDrawing.h" 31 32 #include <d2d1.h> 32 33 #include <wtf/RetainPtr.h> … … 121 122 generateGradient(d2dContext); 122 123 123 if (!context->didBeginDraw()) 124 d2dContext->BeginDraw(); 124 RenderTargetScopedDrawing scopedDraw(*context); 125 125 126 126 d2dContext->SetTags(GRADIENT_DRAWING, __LINE__); … … 129 129 d2dContext->FillRectangle(&d2dRect, m_gradient); 130 130 131 if (!context->didBeginDraw()) {132 D2D1_TAG first, second;133 HRESULT hr = d2dContext->EndDraw(&first, &second);134 RELEASE_ASSERT(SUCCEEDED(hr));135 }136 137 131 if (needScaling) 138 132 context->restore(); -
trunk/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp
r208013 r208019 35 35 #include "Logging.h" 36 36 #include "NotImplemented.h" 37 #include "RenderTargetScopedDrawing.h" 37 38 #include "URL.h" 38 39 #include <d2d1.h> … … 99 100 } 100 101 101 void GraphicsContext::setDidBeginDraw(bool didBeginDraw)102 {103 RELEASE_ASSERT(m_data);104 m_data->m_didBeginDraw = didBeginDraw;105 }106 107 102 bool GraphicsContext::didBeginDraw() const 108 103 { 109 return m_data-> m_didBeginDraw;104 return m_data->didBeginDraw(); 110 105 } 111 106 … … 278 273 ASSERT(SUCCEEDED(hr)); 279 274 280 if (!didBeginDraw()) 281 platformContext()->BeginDraw(); 282 275 RenderTargetScopedDrawing scopedDraw(*this); 283 276 platformContext()->DrawBitmap(bitmap.get(), dstRect); 284 277 285 if (!didBeginDraw())286 hr = platformContext()->EndDraw();287 288 278 ::DeleteDC(hdc); 289 279 } … … 307 297 void GraphicsContext::drawLineForDocumentMarker(const FloatPoint& point, float width, DocumentMarkerLineStyle style) 308 298 { 299 } 300 301 GraphicsContextPlatformPrivate::GraphicsContextPlatformPrivate(ID2D1RenderTarget* renderTarget) 302 : m_renderTarget(renderTarget) 303 { 304 } 305 306 GraphicsContextPlatformPrivate::~GraphicsContextPlatformPrivate() 307 { 308 if (!m_renderTarget) 309 return; 310 311 ASSERT(!m_beginDrawCount.unsafeGet()); 309 312 } 310 313 … … 341 344 void GraphicsContextPlatformPrivate::clip(const FloatRect& rect) 342 345 { 346 // In D2D, we can only clip in the context of a 'BeginDraw', and the clip can 347 // only live as long as the draw is happening. 348 beginDrawIfNeeded(); 349 343 350 if (m_renderStates.isEmpty()) 344 351 save(); … … 355 362 void GraphicsContextPlatformPrivate::clip(ID2D1Geometry* path) 356 363 { 364 // In D2D, we can only clip in the context of a 'BeginDraw', and the clip can 365 // only live as long as the draw is happening. 366 beginDrawIfNeeded(); 367 357 368 ASSERT(m_renderStates.size()); 358 369 if (!m_renderStates.size()) … … 390 401 } 391 402 403 void GraphicsContextPlatformPrivate::beginDrawIfNeeded() 404 { 405 ASSERT(m_renderTarget.get()); 406 if (didBeginDraw()) 407 return; 408 409 m_renderTarget->BeginDraw(); 410 411 ++m_beginDrawCount; 412 } 413 392 414 void GraphicsContextPlatformPrivate::endDraw() 393 415 { … … 398 420 if (!SUCCEEDED(hr)) 399 421 WTFLogAlways("Failed in GraphicsContextPlatformPrivate::endDraw: hr=%ld, first=%ld, second=%ld", hr, first, second); 422 423 --m_beginDrawCount; 400 424 } 401 425 … … 492 516 { 493 517 return m_data->m_patternFillBrush.get(); 518 } 519 520 bool GraphicsContext::beginDrawIfNeeded() 521 { 522 bool neededToBeginDraw = !m_data->didBeginDraw(); 523 524 m_data->beginDrawIfNeeded(); 525 return neededToBeginDraw; 526 } 527 528 void GraphicsContext::endDraw() 529 { 530 m_data->endDraw(); 494 531 } 495 532 … … 878 915 void GraphicsContext::drawWithoutShadow(const FloatRect& /*boundingRect*/, const std::function<void(ID2D1RenderTarget*)>& drawCommands) 879 916 { 880 auto context = platformContext(); 881 882 if (!didBeginDraw()) 883 context->BeginDraw(); 884 885 drawCommands(context); 886 887 if (!didBeginDraw()) 888 m_data->endDraw(); 917 RenderTargetScopedDrawing scopedDraw(*this); 918 drawCommands(platformContext()); 889 919 } 890 920 891 921 void GraphicsContext::drawWithShadow(const FloatRect& boundingRect, const std::function<void(ID2D1RenderTarget*)>& drawCommands) 892 922 { 923 RenderTargetScopedDrawing scopedDraw(*this); 924 893 925 auto context = platformContext(); 894 926 … … 943 975 deviceContext->SetTransform(ctm * flip * translate); 944 976 945 deviceContext->BeginDraw();946 977 deviceContext->DrawImage(compositor.get(), D2D1_INTERPOLATION_MODE_LINEAR); 947 hr = deviceContext->EndDraw();948 ASSERT(SUCCEEDED(hr));949 978 } 950 979 … … 1137 1166 } 1138 1167 1139 if (!didBeginDraw()) 1140 context->BeginDraw(); 1141 1168 RenderTargetScopedDrawing scopedDraw(*this); 1169 1142 1170 context->SetTags(1, __LINE__); 1143 1171 … … 1159 1187 } 1160 1188 1161 if (!didBeginDraw())1162 m_data->endDraw();1163 1164 1189 if (drawOwnShadow) 1165 1190 stateSaver.restore(); … … 1178 1203 auto context = platformContext(); 1179 1204 1180 if (!didBeginDraw()) 1181 context->BeginDraw(); 1205 RenderTargetScopedDrawing scopedDraw(*this); 1182 1206 1183 1207 context->SetTags(1, __LINE__); … … 1208 1232 1209 1233 fillPath(path); 1210 1211 if (!didBeginDraw())1212 m_data->endDraw();1213 1234 1214 1235 if (drawOwnShadow) -
trunk/Source/WebCore/platform/graphics/win/GraphicsContextPlatformPrivateDirect2D.h
r207140 r208019 33 33 #include <d2d1helper.h> 34 34 #include <windows.h> 35 #include <wtf/CheckedArithmetic.h> 35 36 #include <wtf/TinyLRUCache.h> 36 37 … … 40 41 WTF_MAKE_FAST_ALLOCATED; 41 42 public: 42 GraphicsContextPlatformPrivate(ID2D1RenderTarget* renderTarget) 43 : m_renderTarget(renderTarget) 44 { 45 } 43 GraphicsContextPlatformPrivate(ID2D1RenderTarget*); 44 ~GraphicsContextPlatformPrivate(); 46 45 47 46 enum Direct2DLayerType { AxisAlignedClip, LayerClip }; … … 50 49 void clip(const Path&); 51 50 void clip(ID2D1Geometry*); 51 void beginDrawIfNeeded(); 52 52 void endDraw(); 53 53 void flush(); … … 76 76 COMPtr<ID2D1SolidColorBrush> brushWithColor(const D2D1_COLOR_F&); 77 77 78 bool didBeginDraw() const { return m_beginDrawCount.unsafeGet(); } 79 78 80 HDC m_hdc { nullptr }; 79 81 D2D1_BLEND_MODE m_blendMode { D2D1_BLEND_MODE_MULTIPLY }; 80 82 D2D1_COMPOSITE_MODE m_compositeMode { D2D1_COMPOSITE_MODE_SOURCE_OVER }; 83 Checked<unsigned> m_beginDrawCount { 0 }; 81 84 bool m_shouldIncludeChildWindows { false }; 82 bool m_didBeginDraw { false };83 85 bool m_strokeSyleIsDirty { false }; 84 86 -
trunk/Source/WebCore/platform/graphics/win/ImageBufferDataDirect2D.cpp
r207708 r208019 34 34 #include "IntRect.h" 35 35 #include "NotImplemented.h" 36 #include "RenderTargetScopedDrawing.h" 36 37 #include <d2d1.h> 37 38 #include <runtime/JSCInlines.h> … … 64 65 HGDIOBJ oldBitmap = ::SelectObject(bitmapDC.get(), bitmap.get()); 65 66 66 HRESULT hr;67 BOOL ok = TRUE; 67 68 68 COMPtr<ID2D1GdiInteropRenderTarget> gdiRenderTarget; 69 hr = platformContext->QueryInterface(__uuidof(ID2D1GdiInteropRenderTarget), (void**)&gdiRenderTarget); 70 if (FAILED(hr)) 71 return nullptr; 69 { 70 RenderTargetScopedDrawing scopedDraw(*context); 72 71 73 platformContext->BeginDraw(); 72 COMPtr<ID2D1GdiInteropRenderTarget> gdiRenderTarget; 73 HRESULT hr = platformContext->QueryInterface(__uuidof(ID2D1GdiInteropRenderTarget), (void**)&gdiRenderTarget); 74 if (FAILED(hr)) 75 return nullptr; 74 76 75 HDC hdc = nullptr;76 hr = gdiRenderTarget->GetDC(D2D1_DC_INITIALIZE_MODE_COPY, &hdc);77 HDC hdc = nullptr; 78 hr = gdiRenderTarget->GetDC(D2D1_DC_INITIALIZE_MODE_COPY, &hdc); 77 79 78 BOOLok = ::BitBlt(bitmapDC.get(), 0, 0, rect.width(), rect.height(), hdc, rect.x(), rect.y(), SRCCOPY);80 ok = ::BitBlt(bitmapDC.get(), 0, 0, rect.width(), rect.height(), hdc, rect.x(), rect.y(), SRCCOPY); 79 81 80 hr = gdiRenderTarget->ReleaseDC(nullptr); 81 82 hr = platformContext->EndDraw(); 82 hr = gdiRenderTarget->ReleaseDC(nullptr); 83 } 83 84 84 85 if (!ok) -
trunk/Source/WebCore/platform/graphics/win/NativeImageDirect2D.cpp
r207357 r208019 33 33 #include "IntSize.h" 34 34 #include "NotImplemented.h" 35 #include "RenderTargetScopedDrawing.h" 35 36 #include <d2d1.h> 36 37 … … 86 87 float opacity = 1.0f; 87 88 88 if (!context.didBeginDraw()) 89 platformContext->BeginDraw(); 89 bool temporaryDraw = context.beginDrawIfNeeded(); 90 90 91 91 platformContext->DrawBitmap(image.get(), destRect, opacity, D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR, adjustedSrcRect); 92 92 93 93 HRESULT hr = S_OK; 94 if ( !context.didBeginDraw())95 hr = platformContext->EndDraw();94 if (temporaryDraw) 95 context.endDraw(); 96 96 else 97 97 hr = platformContext->Flush(); -
trunk/Source/WebCore/svg/graphics/SVGImage.cpp
r207386 r208019 1 1 /* 2 2 * Copyright (C) 2006 Eric Seidel <eric@webkit.org> 3 * Copyright (C) 2008 , 2009, 2015Apple Inc. All rights reserved.3 * Copyright (C) 2008-2009, 2015-2016 Apple Inc. All rights reserved. 4 4 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 5 5 * … … 57 57 #if USE(DIRECT2D) 58 58 #include "COMPtr.h" 59 #include "RenderTargetScopedDrawing.h" 59 60 #include <d2d1.h> 60 61 #endif … … 225 226 ASSERT(SUCCEEDED(hr)); 226 227 227 nativeImageTarget->BeginDraw();228 228 GraphicsContext localContext(nativeImageTarget.get()); 229 localContext.setDidBeginDraw(true); 230 231 draw(localContext, rect(), rect(), CompositeSourceOver, BlendModeNormal, ImageOrientationDescription()); 232 233 hr = nativeImageTarget->Flush(); 234 ASSERT(SUCCEEDED(hr)); 229 230 { 231 RenderTargetScopedDrawing scopedDraw(localContext); 232 draw(localContext, rect(), rect(), CompositeSourceOver, BlendModeNormal, ImageOrientationDescription()); 233 } 235 234 236 235 COMPtr<ID2D1Bitmap> nativeImage; -
trunk/Source/WebKit/win/ChangeLog
r208014 r208019 1 2016-10-25 Brent Fulgham <bfulgham@apple.com> 2 3 [Win][Direct2D] Create a RAII Helper Class for the Render Target 4 https://bugs.webkit.org/show_bug.cgi?id=164005 5 6 Reviewed by Alex Christensen. 7 8 * WebView.cpp: 9 (WebView::sizeChanged): Construct RenderTarget with higher-resolution display timer. 10 (WebView::paintWithDirect2D): Revise to use new RenderTargetHelper class. 11 1 12 2016-10-27 Wenson Hsieh <wenson_hsieh@apple.com> 2 13 -
trunk/Source/WebKit/win/WebView.cpp
r207585 r208019 165 165 #include <WebCore/WindowsTouch.h> 166 166 #include <bindings/ScriptValue.h> 167 #include <comdef.h> 167 168 #include <d2d1.h> 168 169 #include <wtf/MainThread.h> … … 195 196 #if ENABLE(FULLSCREEN_API) 196 197 #include <WebCore/FullScreenController.h> 198 #endif 199 200 #if USE(DIRECT2D) 201 #include <WebCore/RenderTargetScopedDrawing.h> 197 202 #endif 198 203 … … 1064 1069 auto renderTargetProperties = D2D1::RenderTargetProperties(); 1065 1070 renderTargetProperties.usage = D2D1_RENDER_TARGET_USAGE_GDI_COMPATIBLE; 1066 auto hwndRenderTargetProperties = D2D1::HwndRenderTargetProperties(m_viewWindow, newSize );1071 auto hwndRenderTargetProperties = D2D1::HwndRenderTargetProperties(m_viewWindow, newSize, D2D1_PRESENT_OPTIONS_IMMEDIATELY); 1067 1072 HRESULT hr = GraphicsContext::systemFactory()->CreateHwndRenderTarget(&renderTargetProperties, &hwndRenderTargetProperties, &m_renderTarget); 1068 1073 ASSERT(SUCCEEDED(hr)); … … 1218 1223 void WebView::paintWithDirect2D() 1219 1224 { 1220 #if USE(DIRECT2D)1221 1225 Frame* coreFrame = core(m_mainFrame); 1222 1226 if (!coreFrame) … … 1237 1241 auto pixelSize = D2D1::SizeU(clientRect.width(), clientRect.height()); 1238 1242 1239 auto hwndRenderTargetProperties = D2D1::HwndRenderTargetProperties(m_viewWindow, pixelSize );1243 auto hwndRenderTargetProperties = D2D1::HwndRenderTargetProperties(m_viewWindow, pixelSize, D2D1_PRESENT_OPTIONS_IMMEDIATELY); 1240 1244 HRESULT hr = GraphicsContext::systemFactory()->CreateHwndRenderTarget(&renderTargetProperties, &hwndRenderTargetProperties, &m_renderTarget); 1241 1245 if (!SUCCEEDED(hr)) … … 1243 1247 } 1244 1248 1245 m_renderTarget->BeginDraw(); 1246 1247 m_renderTarget->SetTags(WEBKIT_DRAWING, __LINE__); 1248 m_renderTarget->Clear(); 1249 1250 // Direct2D honors the scale factor natively. 1251 float scaleFactor = 1.0f; 1252 float inverseScaleFactor = 1.0f / scaleFactor; 1253 1254 RECT clientRect; 1255 GetClientRect(m_viewWindow, &clientRect); 1256 1257 IntRect dirtyRectPixels(0, 0, clientRect.right, clientRect.bottom); 1258 FloatRect logicalDirtyRectFloat = dirtyRectPixels; 1259 logicalDirtyRectFloat.scale(inverseScaleFactor); 1260 IntRect logicalDirtyRect(enclosingIntRect(logicalDirtyRectFloat)); 1261 1249 RECT clientRect = {}; 1262 1250 GraphicsContext gc(m_renderTarget.get()); 1263 gc.setDidBeginDraw(true); 1264 1265 if (frameView && frameView->frame().contentRenderer()) { 1266 gc.save(); 1267 gc.scale(FloatSize(scaleFactor, scaleFactor)); 1268 gc.clip(logicalDirtyRect); 1269 frameView->paint(gc, logicalDirtyRect); 1270 gc.restore(); 1271 if (m_shouldInvertColors) 1272 gc.fillRect(logicalDirtyRect, Color::white, CompositeDifference); 1273 } 1274 1275 HRESULT hr = m_renderTarget->EndDraw(); 1276 // FIXME: Recognize and recover from error state: 1277 UNUSED_PARAM(hr); 1251 1252 { 1253 WebCore::RenderTargetScopedDrawing scopedDraw(gc); 1254 1255 m_renderTarget->SetTags(WEBKIT_DRAWING, __LINE__); 1256 m_renderTarget->Clear(); 1257 1258 // Direct2D honors the scale factor natively. 1259 float scaleFactor = 1.0f; 1260 float inverseScaleFactor = 1.0f / scaleFactor; 1261 1262 GetClientRect(m_viewWindow, &clientRect); 1263 1264 IntRect dirtyRectPixels(0, 0, clientRect.right, clientRect.bottom); 1265 FloatRect logicalDirtyRectFloat = dirtyRectPixels; 1266 logicalDirtyRectFloat.scale(inverseScaleFactor); 1267 IntRect logicalDirtyRect(enclosingIntRect(logicalDirtyRectFloat)); 1268 1269 if (frameView && frameView->frame().contentRenderer()) { 1270 gc.save(); 1271 gc.scale(FloatSize(scaleFactor, scaleFactor)); 1272 gc.clip(logicalDirtyRect); 1273 frameView->paint(gc, logicalDirtyRect); 1274 gc.restore(); 1275 if (m_shouldInvertColors) 1276 gc.fillRect(logicalDirtyRect, Color::white, CompositeDifference); 1277 } 1278 } 1278 1279 1279 1280 ::ValidateRect(m_viewWindow, &clientRect); … … 3152 3153 3153 3154 setSmartInsertDeleteEnabled(TRUE); 3155 3154 3156 return hr; 3155 3157 } -
trunk/Tools/TestWebKitAPI/PlatformWin.cmake
r206153 r208019 29 29 Crypt32 30 30 D2d1 31 Dwrite 32 dxguid 31 33 Iphlpapi 32 34 Psapi … … 36 38 WebCoreDerivedSources${DEBUG_SUFFIX} 37 39 WebKit${DEBUG_SUFFIX} 40 WindowsCodecs 38 41 gtest 39 42 )
Note: See TracChangeset
for help on using the changeset viewer.