epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 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.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 9 | |
| 10 | #include "SkSpriteBlitter.h" |
| 11 | |
| 12 | SkSpriteBlitter::SkSpriteBlitter(const SkBitmap& source) |
mike@reedtribe.org | ebe5bcd | 2011-04-20 11:01:37 +0000 | [diff] [blame] | 13 | : fSource(&source) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 14 | fSource->lockPixels(); |
| 15 | } |
| 16 | |
mike@reedtribe.org | ebe5bcd | 2011-04-20 11:01:37 +0000 | [diff] [blame] | 17 | SkSpriteBlitter::~SkSpriteBlitter() { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 18 | fSource->unlockPixels(); |
| 19 | } |
| 20 | |
| 21 | void SkSpriteBlitter::setup(const SkBitmap& device, int left, int top, |
mike@reedtribe.org | ebe5bcd | 2011-04-20 11:01:37 +0000 | [diff] [blame] | 22 | const SkPaint& paint) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 23 | fDevice = &device; |
| 24 | fLeft = left; |
| 25 | fTop = top; |
| 26 | fPaint = &paint; |
| 27 | } |
| 28 | |
| 29 | #ifdef SK_DEBUG |
mike@reedtribe.org | ebe5bcd | 2011-04-20 11:01:37 +0000 | [diff] [blame] | 30 | void SkSpriteBlitter::blitH(int x, int y, int width) { |
tomhudson@google.com | 0c00f21 | 2011-12-28 14:59:50 +0000 | [diff] [blame] | 31 | SkDEBUGFAIL("how did we get here?"); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 32 | } |
| 33 | |
mike@reedtribe.org | ebe5bcd | 2011-04-20 11:01:37 +0000 | [diff] [blame] | 34 | void SkSpriteBlitter::blitAntiH(int x, int y, const SkAlpha antialias[], |
| 35 | const int16_t runs[]) { |
tomhudson@google.com | 0c00f21 | 2011-12-28 14:59:50 +0000 | [diff] [blame] | 36 | SkDEBUGFAIL("how did we get here?"); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 37 | } |
| 38 | |
mike@reedtribe.org | ebe5bcd | 2011-04-20 11:01:37 +0000 | [diff] [blame] | 39 | void SkSpriteBlitter::blitV(int x, int y, int height, SkAlpha alpha) { |
tomhudson@google.com | 0c00f21 | 2011-12-28 14:59:50 +0000 | [diff] [blame] | 40 | SkDEBUGFAIL("how did we get here?"); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 41 | } |
| 42 | |
mike@reedtribe.org | ebe5bcd | 2011-04-20 11:01:37 +0000 | [diff] [blame] | 43 | void SkSpriteBlitter::blitMask(const SkMask&, const SkIRect& clip) { |
tomhudson@google.com | 0c00f21 | 2011-12-28 14:59:50 +0000 | [diff] [blame] | 44 | SkDEBUGFAIL("how did we get here?"); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 45 | } |
| 46 | #endif |
| 47 | |
mike@reedtribe.org | ebe5bcd | 2011-04-20 11:01:37 +0000 | [diff] [blame] | 48 | /////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 49 | |
| 50 | // returning null means the caller will call SkBlitter::Choose() and |
| 51 | // have wrapped the source bitmap inside a shader |
| 52 | SkBlitter* SkBlitter::ChooseSprite( const SkBitmap& device, |
| 53 | const SkPaint& paint, |
| 54 | const SkBitmap& source, |
| 55 | int left, int top, |
mike@reedtribe.org | ebe5bcd | 2011-04-20 11:01:37 +0000 | [diff] [blame] | 56 | void* storage, size_t storageSize) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 57 | /* 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.com | 900ecf2 | 2014-02-20 20:55:37 +0000 | [diff] [blame^] | 69 | switch (device.colorType()) { |
| 70 | case kRGB_565_SkColorType: |
mike@reedtribe.org | ebe5bcd | 2011-04-20 11:01:37 +0000 | [diff] [blame] | 71 | blitter = SkSpriteBlitter::ChooseD16(source, paint, storage, |
| 72 | storageSize); |
| 73 | break; |
reed@google.com | 900ecf2 | 2014-02-20 20:55:37 +0000 | [diff] [blame^] | 74 | case kPMColor_SkColorType: |
mike@reedtribe.org | ebe5bcd | 2011-04-20 11:01:37 +0000 | [diff] [blame] | 75 | blitter = SkSpriteBlitter::ChooseD32(source, paint, storage, |
| 76 | storageSize); |
| 77 | break; |
| 78 | default: |
| 79 | blitter = NULL; |
| 80 | break; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 81 | } |
| 82 | |
mike@reedtribe.org | ebe5bcd | 2011-04-20 11:01:37 +0000 | [diff] [blame] | 83 | if (blitter) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 84 | blitter->setup(device, left, top, paint); |
mike@reedtribe.org | ebe5bcd | 2011-04-20 11:01:37 +0000 | [diff] [blame] | 85 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 86 | return blitter; |
| 87 | } |