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