180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/* 380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2006 The Android Open Source Project 480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be 680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file. 780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkSpriteBlitter.h" 1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkSpriteBlitter::SkSpriteBlitter(const SkBitmap& source) 1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru : fSource(&source) { 1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fSource->lockPixels(); 1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkSpriteBlitter::~SkSpriteBlitter() { 1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fSource->unlockPixels(); 1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkSpriteBlitter::setup(const SkBitmap& device, int left, int top, 2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkPaint& paint) { 2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fDevice = &device; 2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fLeft = left; 2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fTop = top; 2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fPaint = &paint; 2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifdef SK_DEBUG 3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkSpriteBlitter::blitH(int x, int y, int width) { 3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDEBUGFAIL("how did we get here?"); 3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkSpriteBlitter::blitAntiH(int x, int y, const SkAlpha antialias[], 3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const int16_t runs[]) { 3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDEBUGFAIL("how did we get here?"); 3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkSpriteBlitter::blitV(int x, int y, int height, SkAlpha alpha) { 4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDEBUGFAIL("how did we get here?"); 4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkSpriteBlitter::blitMask(const SkMask&, const SkIRect& clip) { 4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDEBUGFAIL("how did we get here?"); 4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/////////////////////////////////////////////////////////////////////////////// 4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// returning null means the caller will call SkBlitter::Choose() and 5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// have wrapped the source bitmap inside a shader 5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkBlitter* SkBlitter::ChooseSprite( const SkBitmap& device, 5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkPaint& paint, 5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkBitmap& source, 5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int left, int top, 5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void* storage, size_t storageSize) { 5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /* We currently ignore antialiasing and filtertype, meaning we will take our 5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru special blitters regardless of these settings. Ignoring filtertype seems fine 5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru since by definition there is no scale in the matrix. Ignoring antialiasing is 6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru a bit of a hack, since we "could" pass in the fractional left/top for the bitmap, 6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru and respect that by blending the edges of the bitmap against the device. To support 6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this we could either add more special blitters here, or detect antialiasing in the 6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru paint and return null if it is set, forcing the client to take the slow shader case 6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru (which does respect soft edges). 6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkSpriteBlitter* blitter; 6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru switch (device.getConfig()) { 7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru case SkBitmap::kRGB_565_Config: 7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru blitter = SkSpriteBlitter::ChooseD16(source, paint, storage, 7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru storageSize); 7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru break; 7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru case SkBitmap::kARGB_8888_Config: 7580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru blitter = SkSpriteBlitter::ChooseD32(source, paint, storage, 7680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru storageSize); 7780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru break; 7880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru default: 7980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru blitter = NULL; 8080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru break; 8180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 8280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 8380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (blitter) { 8480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru blitter->setup(device, left, top, paint); 8580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 8680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return blitter; 8780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 88