- Revision
- 225454
- Author
- [email protected]
- Date
- 2017-12-02 15:11:12 -0800 (Sat, 02 Dec 2017)
Log Message
Make IOSurface::Locker and use it in ImageBufferDataCG
https://bugs.webkit.org/show_bug.cgi?id=180317
Reviewed by Zalan Bujtas.
Add an RAII IOSurface::Locker which can lock readonly or readwrite. Access
to the IOSurface base address is through the locker.
Add IOSurface::bytesPerRow() to wrap IOSurfaceGetBytesPerRow().
After this, there is only one location where we access the IOSurfaceRef
directly, in WebGL code.
* platform/graphics/cg/ImageBufferDataCG.cpp:
(WebCore::ImageBufferData::toBGRAData const):
(WebCore::ImageBufferData::getData const):
(WebCore::ImageBufferData::putData):
* platform/graphics/cocoa/IOSurface.h:
* platform/graphics/cocoa/IOSurface.mm:
(WebCore::IOSurface::bytesPerRow const):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (225453 => 225454)
--- trunk/Source/WebCore/ChangeLog 2017-12-02 20:35:46 UTC (rev 225453)
+++ trunk/Source/WebCore/ChangeLog 2017-12-02 23:11:12 UTC (rev 225454)
@@ -1,5 +1,28 @@
2017-12-02 Simon Fraser <[email protected]>
+ Make IOSurface::Locker and use it in ImageBufferDataCG
+ https://bugs.webkit.org/show_bug.cgi?id=180317
+
+ Reviewed by Zalan Bujtas.
+
+ Add an RAII IOSurface::Locker which can lock readonly or readwrite. Access
+ to the IOSurface base address is through the locker.
+
+ Add IOSurface::bytesPerRow() to wrap IOSurfaceGetBytesPerRow().
+
+ After this, there is only one location where we access the IOSurfaceRef
+ directly, in WebGL code.
+
+ * platform/graphics/cg/ImageBufferDataCG.cpp:
+ (WebCore::ImageBufferData::toBGRAData const):
+ (WebCore::ImageBufferData::getData const):
+ (WebCore::ImageBufferData::putData):
+ * platform/graphics/cocoa/IOSurface.h:
+ * platform/graphics/cocoa/IOSurface.mm:
+ (WebCore::IOSurface::bytesPerRow const):
+
+2017-12-02 Simon Fraser <[email protected]>
+
Add an AlphaPremultiplication enum and use it consistently
https://bugs.webkit.org/show_bug.cgi?id=180316
Modified: trunk/Source/WebCore/platform/graphics/cg/ImageBufferDataCG.cpp (225453 => 225454)
--- trunk/Source/WebCore/platform/graphics/cg/ImageBufferDataCG.cpp 2017-12-02 20:35:46 UTC (rev 225453)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageBufferDataCG.cpp 2017-12-02 23:11:12 UTC (rev 225454)
@@ -131,10 +131,8 @@
return result;
}
#if USE(IOSURFACE_CANVAS_BACKING_STORE)
- IOSurfaceRef surfaceRef = surface->surface();
- IOSurfaceLock(surfaceRef, kIOSurfaceLockReadOnly, nullptr);
- transferData(result.data(), IOSurfaceGetBaseAddress(surfaceRef), width, height, IOSurfaceGetBytesPerRow(surfaceRef));
- IOSurfaceUnlock(surfaceRef, kIOSurfaceLockReadOnly, nullptr);
+ IOSurface::Locker lock(*surface);
+ transferData(result.data(), lock.surfaceBaseAddress(), width, height, surface->bytesPerRow());
#else
ASSERT_NOT_REACHED();
#endif
@@ -303,14 +301,11 @@
}
} else {
#if USE(IOSURFACE_CANVAS_BACKING_STORE)
- // FIXME: WebCore::IOSurface should have a locking RAII object and base-address getter.
- IOSurfaceRef surfaceRef = surface->surface();
- IOSurfaceLock(surfaceRef, kIOSurfaceLockReadOnly, nullptr);
- srcBytesPerRow = IOSurfaceGetBytesPerRow(surfaceRef);
- srcRows = static_cast<uint8_t*>(IOSurfaceGetBaseAddress(surfaceRef)) + originy * srcBytesPerRow + originx * 4;
+ IOSurface::Locker lock(*surface);
+ srcBytesPerRow = surface->bytesPerRow();
+ srcRows = static_cast<uint8_t*>(lock.surfaceBaseAddress()) + originy * srcBytesPerRow + originx * 4;
#if USE(ACCELERATE)
-
vImage_Buffer src;
src.width = width.unsafeGet();
src.height = height.unsafeGet();
@@ -389,7 +384,6 @@
}
}
#endif // USE(ACCELERATE)
- IOSurfaceUnlock(surfaceRef, kIOSurfaceLockReadOnly, nullptr);
#else
ASSERT_NOT_REACHED();
#endif // USE(IOSURFACE_CANVAS_BACKING_STORE)
@@ -529,10 +523,9 @@
}
} else {
#if USE(IOSURFACE_CANVAS_BACKING_STORE)
- IOSurfaceRef surfaceRef = surface->surface();
- IOSurfaceLock(surfaceRef, 0, nullptr);
- destBytesPerRow = IOSurfaceGetBytesPerRow(surfaceRef);
- destRows = static_cast<uint8_t*>(IOSurfaceGetBaseAddress(surfaceRef)) + (desty * destBytesPerRow + destx * 4).unsafeGet();
+ IOSurface::Locker lock(*surface, IOSurface::Locker::AccessMode::ReadWrite);
+ destBytesPerRow = surface->bytesPerRow();
+ destRows = static_cast<uint8_t*>(lock.surfaceBaseAddress()) + (desty * destBytesPerRow + destx * 4).unsafeGet();
#if USE(ACCELERATE)
vImage_Buffer src;
@@ -595,8 +588,6 @@
srcRows += srcBytesPerRow;
}
#endif // USE(ACCELERATE)
-
- IOSurfaceUnlock(surfaceRef, 0, nullptr);
#else
ASSERT_NOT_REACHED();
#endif // USE(IOSURFACE_CANVAS_BACKING_STORE)
Modified: trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.h (225453 => 225454)
--- trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.h 2017-12-02 20:35:46 UTC (rev 225453)
+++ trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.h 2017-12-02 23:11:12 UTC (rev 225454)
@@ -48,7 +48,40 @@
RGB10,
RGB10A8,
};
+
+ class Locker {
+ public:
+ enum class AccessMode {
+ ReadOnly,
+ ReadWrite
+ };
+ Locker(IOSurface& surface, AccessMode mode = AccessMode::ReadOnly)
+ : m_surface(surface)
+ , m_flags(flagsFromMode(mode))
+ {
+ IOSurfaceLock(m_surface.surface(), m_flags, nullptr);
+ }
+
+ ~Locker()
+ {
+ IOSurfaceUnlock(m_surface.surface(), m_flags, nullptr);
+ }
+
+ void * surfaceBaseAddress() const
+ {
+ return IOSurfaceGetBaseAddress(m_surface.surface());
+ }
+
+ private:
+ static uint32_t flagsFromMode(AccessMode mode)
+ {
+ return mode == AccessMode::ReadOnly ? kIOSurfaceLockReadOnly : 0;
+ }
+ IOSurface& m_surface;
+ uint32_t m_flags;
+ };
+
WEBCORE_EXPORT static std::unique_ptr<IOSurface> create(IntSize, CGColorSpaceRef, Format = Format::RGBA);
WEBCORE_EXPORT static std::unique_ptr<IOSurface> create(IntSize, IntSize contextSize, CGColorSpaceRef, Format = Format::RGBA);
WEBCORE_EXPORT static std::unique_ptr<IOSurface> createFromSendRight(const MachSendRight&&, CGColorSpaceRef);
@@ -89,9 +122,11 @@
IntSize size() const { return m_size; }
size_t totalBytes() const { return m_totalBytes; }
+
CGColorSpaceRef colorSpace() const { return m_colorSpace.get(); }
WEBCORE_EXPORT Format format() const;
IOSurfaceID surfaceID() const;
+ size_t bytesPerRow() const;
WEBCORE_EXPORT bool isInUse() const;
Modified: trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.mm (225453 => 225454)
--- trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.mm 2017-12-02 20:35:46 UTC (rev 225453)
+++ trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.mm 2017-12-02 23:11:12 UTC (rev 225454)
@@ -372,6 +372,11 @@
#endif
}
+size_t IOSurface::bytesPerRow() const
+{
+ return IOSurfaceGetBytesPerRow(m_surface.get());
+}
+
bool IOSurface::isInUse() const
{
return IOSurfaceIsInUse(m_surface.get());