Changeset 207863 in webkit
- Timestamp:
- Oct 25, 2016 6:57:44 PM (7 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r207860 r207863 1 2016-10-25 Brent Fulgham <bfulgham@apple.com> 2 3 [Win][Direct2D] Use smart pointers for Direct2D Path types 4 https://bugs.webkit.org/show_bug.cgi?id=163994 5 6 Reviewed by Alex Christensen. 7 8 Tested by existing path tests. 9 10 * platform/graphics/Path.h: 11 (WebCore::Path::platformPath): Use a COMPtr for m_path. 12 * platform/graphics/win/GraphicsContextDirect2D.cpp: 13 (WebCore::GraphicsContext::systemFactory): Present better D2D debug output 14 when running a debug build. 15 (WebCore::GraphicsContext::platformInit): Initialize a D2D device from a 16 native GDI device context. 17 (WebCore::GraphicsContext::platformStrokeStyle): Added. 18 (WebCore::GraphicsContext::clipBounds): Simplify clip boundary calculations and 19 avoid doing math on infinities. 20 * platform/graphics/win/PathDirect2D.cpp: 21 (WebCore::scratchRenderTarget): Added. 22 (WebCore::Path::~Path): Switch to COMPtr implementation. 23 (WebCore::Path::ensurePlatformPath): Ditto. 24 (WebCore::Path::appendGeometry): Ditto. 25 (WebCore::Path::operator=): Ditto. 26 (WebCore::Path::initializePathState): Ditto. 27 (WebCore::Path::strokeContains): Provide an implementation. 28 (WebCore::Path::transform): Ditto. 29 (WebCore::Path::addEllipse): No need for explicit construction of the 30 D2D1::Point2F object. 31 (WebCore::Path::clear): Switch to COMPtr implementation. 32 1 33 2016-10-25 Nan Wang <n_wang@apple.com> 2 34 -
trunk/Source/WebCore/platform/graphics/Path.h
r206815 r207863 166 166 // To keep Path() cheap, it does not allocate a PlatformPath immediately 167 167 // meaning Path::platformPath() can return null. 168 #if USE(DIRECT2D) 169 PlatformPathPtr platformPath() const { return m_path.get(); } 170 #else 168 171 PlatformPathPtr platformPath() const { return m_path; } 172 #endif 169 173 // ensurePlatformPath() will allocate a PlatformPath if it has not yet been and will never return null. 170 174 WEBCORE_EXPORT PlatformPathPtr ensurePlatformPath(); … … 200 204 201 205 private: 202 PlatformPathPtr m_path { nullptr };203 206 #if USE(DIRECT2D) 207 COMPtr<ID2D1GeometryGroup> m_path; 204 208 COMPtr<ID2D1PathGeometry> m_activePathGeometry; 205 209 COMPtr<ID2D1GeometrySink> m_activePath; 210 #else 211 PlatformPathPtr m_path { nullptr }; 206 212 #endif 207 213 }; -
trunk/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp
r207681 r207863 72 72 static ID2D1Factory* direct2DFactory = nullptr; 73 73 if (!direct2DFactory) { 74 #ifndef NDEBUG 75 D2D1_FACTORY_OPTIONS options = { }; 76 options.debugLevel = D2D1_DEBUG_LEVEL_INFORMATION; 77 HRESULT hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_MULTI_THREADED, options, &direct2DFactory); 78 #else 74 79 HRESULT hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_MULTI_THREADED, &direct2DFactory); 80 #endif 75 81 RELEASE_ASSERT(SUCCEEDED(hr)); 76 82 } … … 109 115 return; 110 116 111 COMPtr<ID2D1RenderTarget> renderTarget; 117 HBITMAP bitmap = static_cast<HBITMAP>(GetCurrentObject(hdc, OBJ_BITMAP)); 118 119 DIBPixelData pixelData(bitmap); 120 121 auto targetProperties = D2D1::RenderTargetProperties(); 122 targetProperties.pixelFormat = D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_IGNORE); 123 124 COMPtr<ID2D1DCRenderTarget> renderTarget; 125 HRESULT hr = systemFactory()->CreateDCRenderTarget(&targetProperties, &renderTarget); 126 if (!SUCCEEDED(hr)) 127 return; 128 129 RECT clientRect = IntRect(IntPoint(), pixelData.size()); 130 hr = renderTarget->BindDC(hdc, &clientRect); 131 if (!SUCCEEDED(hr)) 132 return; 133 112 134 m_data = new GraphicsContextPlatformPrivate(renderTarget.get()); 113 135 m_data->m_hdc = hdc; … … 672 694 } 673 695 696 ID2D1StrokeStyle* GraphicsContext::platformStrokeStyle() const 697 { 698 return m_data->strokeStyle(); 699 } 700 674 701 // This is only used to draw borders. 675 702 void GraphicsContext::drawLine(const FloatPoint& point1, const FloatPoint& point2) … … 1249 1276 } 1250 1277 1251 D2D1_RECT_F d2dClipBounds = D2D1::InfiniteRect(); 1252 FloatRect clipBounds(d2dClipBounds.left, d2dClipBounds.top, d2dClipBounds.right - d2dClipBounds.left, d2dClipBounds.bottom - d2dClipBounds.top); 1253 1254 if (m_data->clipLayer()) { 1255 auto clipSize = m_data->clipLayer()->GetSize(); 1256 clipBounds.setWidth(clipSize.width); 1257 clipBounds.setHeight(clipSize.height); 1258 } 1278 D2D1_SIZE_F clipSize; 1279 if (auto clipLayer = m_data->clipLayer()) 1280 clipSize = clipLayer->GetSize(); 1281 else 1282 clipSize = platformContext()->GetSize(); 1283 1284 FloatRect clipBounds(IntPoint(), clipSize); 1259 1285 1260 1286 return enclosingIntRect(clipBounds); -
trunk/Source/WebCore/platform/graphics/win/PathDirect2D.cpp
r207681 r207863 43 43 namespace WebCore { 44 44 45 static inline ID2D1RenderTarget* scratchRenderTarget() 46 { 47 static COMPtr<ID2D1RenderTarget> renderTarget = adoptCOM(GraphicsContext::defaultRenderTarget()); 48 return renderTarget.get(); 49 } 45 50 46 51 Path Path::polygonPathFromPoints(const Vector<FloatPoint>& points) … … 71 76 Path::~Path() 72 77 { 73 if (m_path)74 m_path->Release();75 78 } 76 79 … … 84 87 } 85 88 86 return m_path ;89 return m_path.get(); 87 90 } 88 91 … … 102 105 auto fillMode = m_path ? m_path->GetFillMode() : D2D1_FILL_MODE_WINDING; 103 106 104 COMPtr<ID2D1GeometryGroup> protectedPath = adoptCOM(m_path);107 COMPtr<ID2D1GeometryGroup> protectedPath = m_path; 105 108 m_path = nullptr; 106 109 … … 163 166 Path& Path::operator=(const Path& other) 164 167 { 165 if (m_path)166 m_path->Release();167 168 168 m_path = other.m_path; 169 if (m_path)170 m_path->AddRef();171 172 169 m_activePath = other.m_activePath; 173 170 m_activePathGeometry = other.m_activePathGeometry; … … 178 175 HRESULT Path::initializePathState() 179 176 { 180 if (m_path)181 m_path->Release();182 177 m_path = nullptr; 183 178 m_activePath = nullptr; … … 232 227 return false; 233 228 234 UNUSED_PARAM(applier); 235 UNUSED_PARAM(point); 236 notImplemented(); 237 return false; 229 ASSERT(applier); 230 231 GraphicsContext scratchContext(scratchRenderTarget()); 232 applier->strokeStyle(&scratchContext); 233 234 BOOL containsPoint = false; 235 HRESULT hr = m_path->StrokeContainsPoint(point, scratchContext.strokeThickness(), scratchContext.platformStrokeStyle(), nullptr, 1.0f, &containsPoint); 236 if (!SUCCEEDED(hr)) 237 return false; 238 239 return containsPoint; 238 240 } 239 241 … … 258 260 const D2D1_MATRIX_3X2_F& d2dTransform = static_cast<const D2D1_MATRIX_3X2_F>(transform); 259 261 COMPtr<ID2D1TransformedGeometry> transformedPath; 260 if (!SUCCEEDED(GraphicsContext::systemFactory()->CreateTransformedGeometry(m_path , d2dTransform, &transformedPath)))262 if (!SUCCEEDED(GraphicsContext::systemFactory()->CreateTransformedGeometry(m_path.get(), d2dTransform, &transformedPath))) 261 263 return; 262 264 … … 272 274 auto fillMode = m_path->GetFillMode(); 273 275 274 m_path->Release();275 276 m_path = nullptr; 276 277 … … 477 478 { 478 479 COMPtr<ID2D1EllipseGeometry> ellipse; 479 HRESULT hr = GraphicsContext::systemFactory()->CreateEllipseGeometry(D2D1::Ellipse( D2D1::Point2F(r.center().x(), r.center().y()), r.width(), r.height()), &ellipse);480 HRESULT hr = GraphicsContext::systemFactory()->CreateEllipseGeometry(D2D1::Ellipse(r.center(), r.width(), r.height()), &ellipse); 480 481 RELEASE_ASSERT(SUCCEEDED(hr)); 481 482 appendGeometry(ellipse.get()); … … 498 499 if (isNull()) 499 500 return; 500 501 if (m_path)502 m_path->Release();503 501 504 502 m_path = nullptr;
Note: See TracChangeset
for help on using the changeset viewer.