michael@0: /* michael@0: * Copyright 2006 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #include "SkSmallAllocator.h" michael@0: #include "SkSpriteBlitter.h" michael@0: michael@0: SkSpriteBlitter::SkSpriteBlitter(const SkBitmap& source) michael@0: : fSource(&source) { michael@0: fSource->lockPixels(); michael@0: } michael@0: michael@0: SkSpriteBlitter::~SkSpriteBlitter() { michael@0: fSource->unlockPixels(); michael@0: } michael@0: michael@0: void SkSpriteBlitter::setup(const SkBitmap& device, int left, int top, michael@0: const SkPaint& paint) { michael@0: fDevice = &device; michael@0: fLeft = left; michael@0: fTop = top; michael@0: fPaint = &paint; michael@0: } michael@0: michael@0: #ifdef SK_DEBUG michael@0: void SkSpriteBlitter::blitH(int x, int y, int width) { michael@0: SkDEBUGFAIL("how did we get here?"); michael@0: } michael@0: michael@0: void SkSpriteBlitter::blitAntiH(int x, int y, const SkAlpha antialias[], michael@0: const int16_t runs[]) { michael@0: SkDEBUGFAIL("how did we get here?"); michael@0: } michael@0: michael@0: void SkSpriteBlitter::blitV(int x, int y, int height, SkAlpha alpha) { michael@0: SkDEBUGFAIL("how did we get here?"); michael@0: } michael@0: michael@0: void SkSpriteBlitter::blitMask(const SkMask&, const SkIRect& clip) { michael@0: SkDEBUGFAIL("how did we get here?"); michael@0: } michael@0: #endif michael@0: michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: // returning null means the caller will call SkBlitter::Choose() and michael@0: // have wrapped the source bitmap inside a shader michael@0: SkBlitter* SkBlitter::ChooseSprite(const SkBitmap& device, const SkPaint& paint, michael@0: const SkBitmap& source, int left, int top, SkTBlitterAllocator* allocator) { michael@0: /* We currently ignore antialiasing and filtertype, meaning we will take our michael@0: special blitters regardless of these settings. Ignoring filtertype seems fine michael@0: since by definition there is no scale in the matrix. Ignoring antialiasing is michael@0: a bit of a hack, since we "could" pass in the fractional left/top for the bitmap, michael@0: and respect that by blending the edges of the bitmap against the device. To support michael@0: this we could either add more special blitters here, or detect antialiasing in the michael@0: paint and return null if it is set, forcing the client to take the slow shader case michael@0: (which does respect soft edges). michael@0: */ michael@0: SkASSERT(allocator != NULL); michael@0: michael@0: SkSpriteBlitter* blitter; michael@0: michael@0: switch (device.colorType()) { michael@0: case kRGB_565_SkColorType: michael@0: blitter = SkSpriteBlitter::ChooseD16(source, paint, allocator); michael@0: break; michael@0: case kPMColor_SkColorType: michael@0: blitter = SkSpriteBlitter::ChooseD32(source, paint, allocator); michael@0: break; michael@0: default: michael@0: blitter = NULL; michael@0: break; michael@0: } michael@0: michael@0: if (blitter) { michael@0: blitter->setup(device, left, top, paint); michael@0: } michael@0: return blitter; michael@0: }