blob: 86251ff59f501fe064c3c59f9208990970f82bb1 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2006 The Android Open Source Project
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
reed@android.com8a1c16f2008-12-17 15:59:43 +00009
10#include "SkSpriteBlitter.h"
11
12SkSpriteBlitter::SkSpriteBlitter(const SkBitmap& source)
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000013 : fSource(&source) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000014 fSource->lockPixels();
15}
16
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000017SkSpriteBlitter::~SkSpriteBlitter() {
reed@android.com8a1c16f2008-12-17 15:59:43 +000018 fSource->unlockPixels();
19}
20
21void SkSpriteBlitter::setup(const SkBitmap& device, int left, int top,
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000022 const SkPaint& paint) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000023 fDevice = &device;
24 fLeft = left;
25 fTop = top;
26 fPaint = &paint;
27}
28
29#ifdef SK_DEBUG
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000030void SkSpriteBlitter::blitH(int x, int y, int width) {
tomhudson@google.com0c00f212011-12-28 14:59:50 +000031 SkDEBUGFAIL("how did we get here?");
reed@android.com8a1c16f2008-12-17 15:59:43 +000032}
33
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000034void SkSpriteBlitter::blitAntiH(int x, int y, const SkAlpha antialias[],
35 const int16_t runs[]) {
tomhudson@google.com0c00f212011-12-28 14:59:50 +000036 SkDEBUGFAIL("how did we get here?");
reed@android.com8a1c16f2008-12-17 15:59:43 +000037}
38
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000039void SkSpriteBlitter::blitV(int x, int y, int height, SkAlpha alpha) {
tomhudson@google.com0c00f212011-12-28 14:59:50 +000040 SkDEBUGFAIL("how did we get here?");
reed@android.com8a1c16f2008-12-17 15:59:43 +000041}
42
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000043void SkSpriteBlitter::blitMask(const SkMask&, const SkIRect& clip) {
tomhudson@google.com0c00f212011-12-28 14:59:50 +000044 SkDEBUGFAIL("how did we get here?");
reed@android.com8a1c16f2008-12-17 15:59:43 +000045}
46#endif
47
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000048///////////////////////////////////////////////////////////////////////////////
reed@android.com8a1c16f2008-12-17 15:59:43 +000049
50// returning null means the caller will call SkBlitter::Choose() and
51// have wrapped the source bitmap inside a shader
52SkBlitter* SkBlitter::ChooseSprite( const SkBitmap& device,
53 const SkPaint& paint,
54 const SkBitmap& source,
55 int left, int top,
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000056 void* storage, size_t storageSize) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000057 /* We currently ignore antialiasing and filtertype, meaning we will take our
58 special blitters regardless of these settings. Ignoring filtertype seems fine
59 since by definition there is no scale in the matrix. Ignoring antialiasing is
60 a bit of a hack, since we "could" pass in the fractional left/top for the bitmap,
61 and respect that by blending the edges of the bitmap against the device. To support
62 this we could either add more special blitters here, or detect antialiasing in the
63 paint and return null if it is set, forcing the client to take the slow shader case
64 (which does respect soft edges).
65 */
66
67 SkSpriteBlitter* blitter;
68
reed@google.com900ecf22014-02-20 20:55:37 +000069 switch (device.colorType()) {
70 case kRGB_565_SkColorType:
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000071 blitter = SkSpriteBlitter::ChooseD16(source, paint, storage,
72 storageSize);
73 break;
reed@google.com900ecf22014-02-20 20:55:37 +000074 case kPMColor_SkColorType:
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000075 blitter = SkSpriteBlitter::ChooseD32(source, paint, storage,
76 storageSize);
77 break;
78 default:
79 blitter = NULL;
80 break;
reed@android.com8a1c16f2008-12-17 15:59:43 +000081 }
82
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000083 if (blitter) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000084 blitter->setup(device, left, top, paint);
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000085 }
reed@android.com8a1c16f2008-12-17 15:59:43 +000086 return blitter;
87}