From 2a68835e313962cee216007cc2f03c99a5beeece Mon Sep 17 00:00:00 2001 From: Kondapally Kalyan Date: Fri, 7 Jun 2013 02:16:33 +0300 Subject: [PATCH] Refactor ImageBufferCairo This patch makes changes in ImageBufferCairo to take GLPlatformSurface and Context into use. --- Source/WebCore/platform/graphics/ImageBuffer.h | 15 +- .../platform/graphics/cairo/ImageBufferCairo.cpp | 262 ++++----------------- .../platform/graphics/surfaces/x/X11Helper.cpp | 7 +- 3 files changed, 59 insertions(+), 225 deletions(-) diff --git a/Source/WebCore/platform/graphics/ImageBuffer.h b/Source/WebCore/platform/graphics/ImageBuffer.h index 8add808..e5ab467 100644 --- a/Source/WebCore/platform/graphics/ImageBuffer.h +++ b/Source/WebCore/platform/graphics/ImageBuffer.h @@ -22,7 +22,7 @@ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef ImageBuffer_h @@ -31,6 +31,9 @@ #include "AffineTransform.h" #include "ColorSpace.h" #include "FloatRect.h" +#if ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING) || ENABLE(TIZEN_CANVAS_SURFACE_LOCKING) +#include "GLPlatformSurface.h" +#endif #include "GraphicsContext.h" #if USE(ACCELERATED_COMPOSITING) #include "PlatformLayer.h" @@ -67,7 +70,6 @@ namespace WebCore { , AcceleratedMemorySaving #endif }; - enum BackingStoreCopy { CopyBackingStore, // Guarantee subsequent draws don't affect the copy. DontCopyBackingStore // Subsequent draws may affect the copy. @@ -111,9 +113,7 @@ namespace WebCore { PassRefPtr getPremultipliedImageData(const IntRect&, CoordinateSystem = LogicalCoordinateSystem) const; void putByteArray(Multiply multiplied, Uint8ClampedArray*, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, CoordinateSystem = LogicalCoordinateSystem); - void convertToLuminanceMask(); - String toDataURL(const String& mimeType, const double* quality = 0, CoordinateSystem = LogicalCoordinateSystem) const; #if !USE(CG) AffineTransform baseTransform() const { return AffineTransform(); } @@ -128,7 +128,7 @@ namespace WebCore { bool copyToPlatformTexture(GraphicsContext3D&, Platform3DObject, GC3Denum, bool, bool); #if ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING) || ENABLE(TIZEN_CANVAS_SURFACE_LOCKING) - int getPlatformSurfaceID() const { return m_platformSurfaceID; } + PlatformBufferHandle getPlatformSurfaceID() const { return m_offScreenSurface->handle(); } bool isLockable() const { return m_isLockable; } void swapPlatformSurfaces(); #endif @@ -169,13 +169,12 @@ namespace WebCore { #if ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING) || ENABLE(TIZEN_CANVAS_SURFACE_LOCKING) void initializeEGL(); + void destroy(); bool lockSurface() const; PassRefPtr querySurface() const; bool unlockSurface() const; - - int m_platformSurfaceID; - void* m_eglSurface; bool m_isLockable; + OwnPtr m_offScreenSurface; #endif // ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING) || ENABLE(TIZEN_CANVAS_SURFACE_LOCKING) }; diff --git a/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp b/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp index 9442d57..23a1327 100755 --- a/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp +++ b/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp @@ -32,6 +32,9 @@ #include "BitmapImage.h" #include "CairoUtilities.h" #include "Color.h" +#if ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING) +#include "GLPlatformContext.h" +#endif #include "GraphicsContext.h" #include "ImageData.h" #include "MIMETypeRegistry.h" @@ -47,40 +50,19 @@ #if ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING) #include #include -#include -#include -#include -#endif - -#if ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING) || ENABLE(TIZEN_CANVAS_SURFACE_LOCKING) -#include -#include -#include -#include #endif #if ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING) || ENABLE(TIZEN_CANVAS_SURFACE_LOCKING) -static PFNEGLLOCKSURFACEKHRPROC eglLockSurfaceKHR = 0; -static PFNEGLUNLOCKSURFACEKHRPROC eglUnlockSurfaceKHR = 0; +#include "EGLHelper.h" #endif using namespace std; namespace WebCore { -#if ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING) || ENABLE(TIZEN_CANVAS_SURFACE_LOCKING) -void* g_canvasNativeDisplay = 0; -int g_canvasNativeWindow = 0; -void* g_egl_display = 0; -void* g_egl_config = 0; -#endif - #if ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING) cairo_device_t* g_sharedCairoDevice = 0; -void* g_egl_context = 0; -static PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR = 0; -static PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES = 0; -static PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR = 0; +GLPlatformContext* m_offScreenContext = 0; #endif ImageBufferData::ImageBufferData(const IntSize& size) @@ -92,119 +74,35 @@ ImageBufferData::ImageBufferData(const IntSize& size) #if ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING) || ENABLE(TIZEN_CANVAS_SURFACE_LOCKING) void ImageBuffer::initializeEGL() { -#if ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING) -#if ENABLE(TIZEN_USE_XPIXMAP_DECODED_IMAGESOURCE) - if (g_sharedCairoDevice) { - EGLint num; - EGLint attr[] = { - EGL_RED_SIZE, 8, - EGL_GREEN_SIZE, 8, - EGL_BLUE_SIZE, 8, - EGL_ALPHA_SIZE, 8, - EGL_STENCIL_SIZE, 8, - EGL_DEPTH_SIZE, 8, - EGL_SAMPLES, 4, -#if ENABLE(TIZEN_CANVAS_SURFACE_LOCKING) - EGL_MATCH_FORMAT_KHR, EGL_FORMAT_RGBA_8888_EXACT_KHR, - EGL_SURFACE_TYPE, EGL_PIXMAP_BIT | EGL_LOCK_SURFACE_BIT_KHR, -#else - EGL_SURFACE_TYPE, EGL_PIXMAP_BIT, -#endif - EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, - EGL_NONE - }; - - if (!eglChooseConfig(g_egl_display, attr, &g_egl_config, 1, &num)) - return; - - return; - } -#else - if (g_sharedCairoDevice) - return; -#endif -#endif // ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING) - - if (!g_canvasNativeDisplay) { - g_canvasNativeDisplay = XOpenDisplay(0); + GLPlatformSurface::SurfaceAttributes sharedSurfaceAttributes = GLPlatformSurface::Default | GLPlatformSurface::SupportAlpha; - g_canvasNativeWindow = XCreateSimpleWindow(static_cast(g_canvasNativeDisplay), XDefaultRootWindow(static_cast(g_canvasNativeDisplay)), - 0, 0, 1, 1, 0, - BlackPixel(static_cast(g_canvasNativeDisplay), 0), WhitePixel(static_cast(g_canvasNativeDisplay), 0)); + if (m_isLockable) + sharedSurfaceAttributes |= GLPlatformSurface::Lockable; + else + sharedSurfaceAttributes |= GLPlatformSurface::SupportDepth | GLPlatformSurface::SupportStencil; - XFlush(static_cast(g_canvasNativeDisplay)); - } - - EGLint major, minor; + if (!EGLHelper::isVendor("mesa")) + sharedSurfaceAttributes |= GLPlatformSurface::SupportSamples; - if (!g_egl_display) { - g_egl_display = eglGetDisplay(static_cast(g_canvasNativeDisplay)); - if (g_egl_display == EGL_NO_DISPLAY) { -#if ENABLE(TIZEN_DLOG_SUPPORT) - TIZEN_LOGE("eglGetDisplay failed!\n"); -#endif - return; - } + m_offScreenSurface = GLPlatformSurface::createOffScreenSurface(sharedSurfaceAttributes, m_size); - if (eglInitialize(g_egl_display, &major, &minor) != EGL_TRUE) { -#if ENABLE(TIZEN_DLOG_SUPPORT) - TIZEN_LOGE("eglInitialize failed!\n"); -#endif - return; - } + if (!m_offScreenSurface) + return; - EGLint num = 0; - int i = 0; - EGLint attr[32]; - attr[i++] = EGL_RED_SIZE; - attr[i++] = 8; - attr[i++] = EGL_GREEN_SIZE; - attr[i++] = 8; - attr[i++] = EGL_BLUE_SIZE; - attr[i++] = 8; - attr[i++] = EGL_ALPHA_SIZE; - attr[i++] = 8; - if (m_isLockable) { - attr[i++] = EGL_MATCH_FORMAT_KHR; - attr[i++] = EGL_FORMAT_RGBA_8888_EXACT_KHR; - attr[i++] = EGL_SURFACE_TYPE; - attr[i++] = EGL_PIXMAP_BIT | EGL_LOCK_SURFACE_BIT_KHR; - } else { - attr[i++] = EGL_SURFACE_TYPE; - attr[i++] = EGL_PIXMAP_BIT; - attr[i++] = EGL_DEPTH_SIZE; - attr[i++] = 8; - attr[i++] = EGL_STENCIL_SIZE; - attr[i++] = 8; - attr[i++] = EGL_SAMPLES; - attr[i++] = 4; - } - attr[i++] = EGL_RENDERABLE_TYPE; - attr[i++] = EGL_OPENGL_ES2_BIT; - attr[i++] = EGL_NONE; +#if ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING) + if (g_sharedCairoDevice) + return; - if (!eglChooseConfig(g_egl_display, attr, &g_egl_config, 1, &num)) { -#if ENABLE(TIZEN_DLOG_SUPPORT) - TIZEN_LOGE("eglChooseConfig failed!\n"); -#endif - return; - } + OwnPtr context = GLPlatformContext::createContext(GraphicsContext3D::RenderOffscreen); + if (context && context->initialize(m_offScreenSurface.get()) + m_offScreenContext = context.release(); + else { + destroy(); + return; } -#if ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING) if (!g_sharedCairoDevice) { - EGLint ctxattr[] = { - EGL_CONTEXT_CLIENT_VERSION, 2, - EGL_NONE - }; - g_egl_context = eglCreateContext(g_egl_display, g_egl_config, NULL, ctxattr); - if (g_egl_context == EGL_NO_CONTEXT) { -#if ENABLE(TIZEN_DLOG_SUPPORT) - TIZEN_LOGE("eglCreateContext failed!\n"); -#endif - return; - } - g_sharedCairoDevice = cairo_egl_device_create(g_egl_display, g_egl_context); + g_sharedCairoDevice = cairo_egl_device_create(EGLHelper::eglDisplay(), m_offScreenContext->handle()); if (cairo_device_status(g_sharedCairoDevice) != CAIRO_STATUS_SUCCESS) { #if ENABLE(TIZEN_DLOG_SUPPORT) TIZEN_LOGE("cairo_egl_device_create failed!\n"); @@ -215,6 +113,15 @@ void ImageBuffer::initializeEGL() cairo_gl_device_set_thread_aware(g_sharedCairoDevice, 0); } #endif // ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING) + +} + +void ImageBuffer::destroy() +{ + if (m_offScreenSurface) { + m_offScreenSurface->destroy(); + m_offScreenSurface = nullptr; + } } ImageBuffer::ImageBuffer(const IntSize& size, float /* resolutionScale */, ColorSpace, RenderingMode renderingMode, DeferralMode, bool& success) @@ -225,10 +132,6 @@ ImageBuffer::ImageBuffer(const IntSize& size, float /* resolutionScale */, Color , m_bindingTexID(0) , m_eglImage(0) #endif -#if ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING) || ENABLE(TIZEN_CANVAS_SURFACE_LOCKING) - , m_platformSurfaceID(0) - , m_eglSurface(0) -#endif // ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING) || ENABLE(TIZEN_CANVAS_SURFACE_LOCKING) { success = false; // Make early return mean error. #if ENABLE(TIZEN_CANVAS_SURFACE_LOCKING) @@ -240,28 +143,17 @@ ImageBuffer::ImageBuffer(const IntSize& size, float /* resolutionScale */, Color if (renderingMode == Accelerated || renderingMode == AcceleratedMemorySaving) { initializeEGL(); - m_platformSurfaceID = XCreatePixmap(static_cast(g_canvasNativeDisplay), g_canvasNativeWindow, size.width(), size.height(), - XDefaultDepth(static_cast(g_canvasNativeDisplay), DefaultScreen(static_cast(g_canvasNativeDisplay)))); - // XCreatePixmap is asynchronous so we should make sure changes are flushed - // before passing the pixmap handle to eglCreatePixmapSurface(). - XFlush(static_cast(g_canvasNativeDisplay)); - - m_eglSurface = eglCreatePixmapSurface(g_egl_display, g_egl_config, m_platformSurfaceID, 0); - if (m_eglSurface == EGL_NO_SURFACE) { -#if ENABLE(TIZEN_DLOG_SUPPORT) - TIZEN_LOGE("eglCreatePixmapSurface() failed!\n"); -#endif + if (!m_offScreenSurface) return; - } - eglSwapInterval(g_egl_display, 0); + eglSwapInterval(EGLHelper::eglDisplay(), 0); } #if ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING) if (m_isLockable || renderingMode == Unaccelerated) m_data.m_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, size.width(), size.height()); else { - m_data.m_surface = cairo_gl_surface_create_for_egl(static_cast(g_sharedCairoDevice), m_eglSurface, size.width(), size.height()); + m_data.m_surface = cairo_gl_surface_create_for_egl(static_cast(g_sharedCairoDevice), m_offScreenSurface->drawable(), size.width(), size.height()); if (!setBindingTexture()) { #if ENABLE(TIZEN_DLOG_SUPPORT) TIZEN_LOGE("setBindingTexture() failed!\n"); @@ -310,7 +202,7 @@ ImageBuffer::ImageBuffer(const IntSize& size, float /* resolutionScale */, Color ImageBuffer::~ImageBuffer() { #if ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING) || ENABLE(TIZEN_CANVAS_SURFACE_LOCKING) - if (m_platformSurfaceID > 0) { + if (m_offScreenSurface) { #if ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING) if (!m_isLockable) { cairo_surface_flush(m_data.m_surface); @@ -318,19 +210,10 @@ ImageBuffer::~ImageBuffer() } if (m_bindingTexID) glDeleteTextures(1, &m_bindingTexID); - if (m_eglImage) { - if (!eglDestroyImageKHR) - eglDestroyImageKHR = reinterpret_cast(eglGetProcAddress("eglDestroyImageKHR")); - if (eglDestroyImageKHR(g_egl_display, m_eglImage) != EGL_TRUE) { -#if ENABLE(TIZEN_DLOG_SUPPORT) - TIZEN_LOGE("eglDestroyImageKHR failed!\n"); -#endif - } - } + if (m_eglImage) + EGLHelper::destroyEGLImage(m_eglImage); #endif - if (m_eglSurface) - eglDestroySurface(g_egl_display, m_eglSurface); - XFreePixmap(static_cast(g_canvasNativeDisplay), m_platformSurfaceID); + destroy(); } #endif @@ -347,28 +230,8 @@ bool ImageBuffer::setBindingTexture() cairo_paint(cr.get()); glGenTextures(1, &m_bindingTexID); - - if (!eglCreateImageKHR) { - eglCreateImageKHR = reinterpret_cast(eglGetProcAddress("eglCreateImageKHR")); - if (!eglCreateImageKHR) { -#if ENABLE(TIZEN_DLOG_SUPPORT) - TIZEN_LOGE("cannot get eglCreateImageKHR\n"); -#endif - return false; - } - } - if (!glEGLImageTargetTexture2DOES) { - glEGLImageTargetTexture2DOES = reinterpret_cast(eglGetProcAddress("glEGLImageTargetTexture2DOES")); - if (!glEGLImageTargetTexture2DOES) { -#if ENABLE(TIZEN_DLOG_SUPPORT) - TIZEN_LOGE("cannot get glEGLImageTargetTexture2DOES\n"); -#endif - return false; - } - } - - EGLint attr_pixmap[] = { EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE }; - m_eglImage = eglCreateImageKHR(g_egl_display, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, reinterpret_cast(m_platformSurfaceID), attr_pixmap); + static EGLint attr_pixmap[] = { EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE }; + EGLHelper::createEGLImage(&m_eglImage, EGL_NATIVE_PIXMAP_KHR, m_offScreenSurface->handle(), attr_pixmap); if (!m_eglImage) { #if ENABLE(TIZEN_DLOG_SUPPORT) TIZEN_LOGE("cannot create egl image\n"); @@ -380,7 +243,7 @@ bool ImageBuffer::setBindingTexture() glGetIntegerv(GL_TEXTURE_BINDING_2D, &boundTex); glBindTexture(GL_TEXTURE_2D, m_bindingTexID); - glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, static_cast(m_eglImage)); + EGLHelper::imageTargetTexture2DOES(m_eglImage); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); @@ -420,47 +283,24 @@ void ImageBuffer::swapPlatformSurfaces() bool ImageBuffer::lockSurface() const { - EGLint lockAttrib[] = { EGL_LOCK_USAGE_HINT_KHR, EGL_WRITE_SURFACE_BIT_KHR, EGL_NONE }; - if (!eglLockSurfaceKHR) - eglLockSurfaceKHR = reinterpret_cast(eglGetProcAddress("eglLockSurfaceKHR")); - - if (eglLockSurfaceKHR(g_egl_display, m_eglSurface, lockAttrib) != EGL_TRUE) { -#if ENABLE(TIZEN_DLOG_SUPPORT) - TIZEN_LOGE("eglLockSurfaceKHR failed!\n"); -#endif - return false; - } - - return true; + static EGLint lockAttrib[] = { EGL_LOCK_USAGE_HINT_KHR, EGL_WRITE_SURFACE_BIT_KHR, EGL_NONE }; + return EGLHelper::lockSurface(m_offScreenSurface->drawable(), lockAttrib); } bool ImageBuffer::unlockSurface() const { - if (!eglUnlockSurfaceKHR) - eglUnlockSurfaceKHR = reinterpret_cast(eglGetProcAddress("eglUnlockSurfaceKHR")); - - if (eglUnlockSurfaceKHR(g_egl_display, m_eglSurface) != EGL_TRUE) { -#if ENABLE(TIZEN_DLOG_SUPPORT) - TIZEN_LOGE("eglUnlockSurfaceKHR failed!\n"); -#endif - return false; - } - - return true; + return EGLHelper::unlockSurface(m_offScreenSurface->drawable()); } PassRefPtr ImageBuffer::querySurface() const { - int* bitmapPtr = 0; - if (eglQuerySurface(g_egl_display, m_eglSurface, EGL_BITMAP_POINTER_KHR, (EGLint*)&bitmapPtr) != EGL_TRUE) { -#if ENABLE(TIZEN_DLOG_SUPPORT) - TIZEN_LOGE("eglQuerySurface failed!\n"); -#endif + int* bitmapPtr; + if (!EGLHelper::querySurface(m_offScreenSurface->drawable(), EGL_BITMAP_POINTER_KHR, (EGLint*)&bitmapPtr)) return 0; - } int pitch = 0; - eglQuerySurface(g_egl_display, m_eglSurface, EGL_BITMAP_PITCH_KHR, static_cast(&pitch)); + if (!EGLHelper::querySurface(m_offScreenSurface->drawable(), EGL_BITMAP_PITCH_KHR, static_cast(&pitch))) + return 0; return adoptRef(cairo_image_surface_create_for_data(reinterpret_cast(bitmapPtr), CAIRO_FORMAT_ARGB32, m_size.width(), m_size.height(), pitch)); } diff --git a/Source/WebCore/platform/graphics/surfaces/x/X11Helper.cpp b/Source/WebCore/platform/graphics/surfaces/x/X11Helper.cpp index a3aa63a..e0c4271 100644 --- a/Source/WebCore/platform/graphics/surfaces/x/X11Helper.cpp +++ b/Source/WebCore/platform/graphics/surfaces/x/X11Helper.cpp @@ -26,10 +26,6 @@ #include "config.h" #include "X11Helper.h" -#include "GraphicsLayer.h" -#include "GraphicsTypes3D.h" -#include "PlatformString.h" - namespace WebCore { // Used for handling XError. @@ -331,13 +327,12 @@ void X11Helper::createPixmap(Pixmap* handleId, const EGLint id, bool hasAlpha, c int matchingCount = 0; OwnPtrX11 matchingVisuals(XGetVisualInfo(nativeDisplay(), VisualIDMask, &visualInfoTemplate, &matchingCount)); XVisualInfo* foundVisual = 0; - int requiredDepth = hasAlpha ? 32 : 24; if (matchingVisuals) { for (int i = 0; i< matchingCount; i++) { XVisualInfo* temp = &matchingVisuals[i]; - if (temp->visualid == visualId && temp->depth == requiredDepth) { + if (temp->visualid == visualId) { foundVisual = temp; break; } -- 2.7.4