1 /* 2 * Copyright 2011, The Android Open Source Project 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * * Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * * Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #define LOG_TAG "GaneshRenderer" 27 #define LOG_NDEBUG 1 28 29 #include "config.h" 30 #include "GaneshRenderer.h" 31 32 #if USE(ACCELERATED_COMPOSITING) 33 34 #include "AndroidLog.h" 35 #include "GaneshContext.h" 36 #include "SkCanvas.h" 37 #include "SkGpuDevice.h" 38 #include "TilesManager.h" 39 #include "TransferQueue.h" 40 41 namespace WebCore { 42 43 GaneshRenderer::GaneshRenderer() : BaseRenderer(BaseRenderer::Ganesh) 44 { 45 #ifdef DEBUG_COUNT 46 ClassTracker::instance()->increment("GaneshRenderer"); 47 #endif 48 } 49 50 GaneshRenderer::~GaneshRenderer() 51 { 52 #ifdef DEBUG_COUNT 53 ClassTracker::instance()->decrement("GaneshRenderer"); 54 #endif 55 } 56 57 void GaneshRenderer::setupCanvas(const TileRenderInfo& renderInfo, SkCanvas* canvas) 58 { 59 GaneshContext* ganesh = GaneshContext::instance(); 60 61 TransferQueue* tileQueue = TilesManager::instance()->transferQueue(); 62 63 tileQueue->lockQueue(); 64 65 bool ready = tileQueue->readyForUpdate(); 66 if (!ready) { 67 ALOGV("!ready"); 68 tileQueue->unlockQueue(); 69 return; 70 } 71 72 SkDevice* device = NULL; 73 if (renderInfo.tileSize.width() == TilesManager::tileWidth() 74 && renderInfo.tileSize.height() == TilesManager::tileHeight()) { 75 device = ganesh->getDeviceForTile(renderInfo); 76 } else { 77 // TODO support arbitrary sizes for layers 78 ALOGV("ERROR: expected (%d,%d) actual (%d,%d)", 79 TilesManager::tileWidth(), TilesManager::tileHeight(), 80 renderInfo.tileSize.width(), renderInfo.tileSize.height()); 81 } 82 83 // set the GPU device to the canvas 84 canvas->setDevice(device); 85 } 86 87 void GaneshRenderer::renderingComplete(const TileRenderInfo& renderInfo, SkCanvas* canvas) 88 { 89 ALOGV("rendered to tile (%d,%d)", renderInfo.x, renderInfo.y); 90 91 GaneshContext::instance()->flush(); 92 93 // In SurfaceTextureMode we must call swapBuffers to unlock and post the 94 // tile's ANativeWindow (i.e. Surface) buffer 95 TransferQueue* tileQueue = TilesManager::instance()->transferQueue(); 96 eglSwapBuffers(eglGetCurrentDisplay(), tileQueue->m_eglSurface); 97 SkBitmap dummyBitmap; 98 tileQueue->addItemInTransferQueue(&renderInfo, GpuUpload, dummyBitmap); 99 tileQueue->unlockQueue(); 100 } 101 102 } // namespace WebCore 103 104 #endif // USE(ACCELERATED_COMPOSITING) 105