1 /* 2 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Library General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Library General Public License for more details. 13 * 14 * You should have received a copy of the GNU Library General Public License 15 * along with this library; see the file COPYING.LIB. If not, write to 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * Boston, MA 02110-1301, USA. 18 */ 19 20 #include "config.h" 21 #include "ImageDecoder.h" 22 23 #include "IntRect.h" 24 #include "IntSize.h" 25 #include "SurfaceOpenVG.h" 26 #include "TiledImageOpenVG.h" 27 #include "VGUtils.h" 28 29 #if PLATFORM(EGL) 30 #include "EGLDisplayOpenVG.h" 31 #endif 32 33 #include <openvg.h> 34 35 namespace WebCore { 36 37 NativeImagePtr ImageFrame::asNewNativeImage() const 38 { 39 static const VGImageFormat bufferFormat = VG_sARGB_8888_PRE; 40 // Save memory by using 16-bit images for fully opaque images. 41 const VGImageFormat imageFormat = hasAlpha() ? bufferFormat : VG_sRGB_565; 42 43 #if PLATFORM(EGL) 44 EGLDisplayOpenVG::current()->sharedPlatformSurface()->makeCurrent(); 45 #endif 46 47 const IntSize vgMaxImageSize(vgGeti(VG_MAX_IMAGE_WIDTH), vgGeti(VG_MAX_IMAGE_HEIGHT)); 48 ASSERT_VG_NO_ERROR(); 49 50 TiledImageOpenVG* tiledImage = new TiledImageOpenVG(IntSize(width(), height()), vgMaxImageSize); 51 52 const int numColumns = tiledImage->numColumns(); 53 const int numRows = tiledImage->numRows(); 54 55 for (int yIndex = 0; yIndex < numRows; ++yIndex) { 56 for (int xIndex = 0; xIndex < numColumns; ++xIndex) { 57 IntRect tileRect = tiledImage->tileRect(xIndex, yIndex); 58 VGImage image = vgCreateImage(imageFormat, 59 tileRect.width(), tileRect.height(), VG_IMAGE_QUALITY_FASTER); 60 ASSERT_VG_NO_ERROR(); 61 62 PixelData* pixelData = const_cast<PixelData*>(m_bytes); 63 pixelData += (tileRect.y() * width()) + tileRect.x(); 64 65 vgImageSubData(image, reinterpret_cast<unsigned char*>(pixelData), 66 width() * sizeof(PixelData), bufferFormat, 67 0, 0, tileRect.width(), tileRect.height()); 68 ASSERT_VG_NO_ERROR(); 69 70 tiledImage->setTile(xIndex, yIndex, image); 71 } 72 } 73 74 return tiledImage; 75 } 76 77 } 78