OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkSmallAllocator.h" | 8 #include "SkSmallAllocator.h" |
9 #include "SkSpriteBlitter.h" | 9 #include "SkSpriteBlitter.h" |
10 | 10 |
11 SkSpriteBlitter::SkSpriteBlitter(const SkBitmap& source) : fSource(NULL) { | 11 SkSpriteBlitter::SkSpriteBlitter(const SkPixmap& source) : fSource(source) {} |
12 if (source.requestLock(&fUnlocker)) { | |
13 fSource = &fUnlocker.pixmap(); | |
14 } | |
15 } | |
16 | 12 |
17 bool SkSpriteBlitter::setup(const SkBitmap& device, int left, int top, const SkP
aint& paint) { | 13 void SkSpriteBlitter::setup(const SkBitmap& device, int left, int top, const SkP
aint& paint) { |
18 if (NULL == fSource) { | |
19 return false; | |
20 } | |
21 fDevice = &device; | 14 fDevice = &device; |
22 fLeft = left; | 15 fLeft = left; |
23 fTop = top; | 16 fTop = top; |
24 fPaint = &paint; | 17 fPaint = &paint; |
25 return true; | |
26 } | 18 } |
27 | 19 |
28 #ifdef SK_DEBUG | 20 #ifdef SK_DEBUG |
29 void SkSpriteBlitter::blitH(int x, int y, int width) { | 21 void SkSpriteBlitter::blitH(int x, int y, int width) { |
30 SkDEBUGFAIL("how did we get here?"); | 22 SkDEBUGFAIL("how did we get here?"); |
31 } | 23 } |
32 | 24 |
33 void SkSpriteBlitter::blitAntiH(int x, int y, const SkAlpha antialias[], | 25 void SkSpriteBlitter::blitAntiH(int x, int y, const SkAlpha antialias[], |
34 const int16_t runs[]) { | 26 const int16_t runs[]) { |
35 SkDEBUGFAIL("how did we get here?"); | 27 SkDEBUGFAIL("how did we get here?"); |
36 } | 28 } |
37 | 29 |
38 void SkSpriteBlitter::blitV(int x, int y, int height, SkAlpha alpha) { | 30 void SkSpriteBlitter::blitV(int x, int y, int height, SkAlpha alpha) { |
39 SkDEBUGFAIL("how did we get here?"); | 31 SkDEBUGFAIL("how did we get here?"); |
40 } | 32 } |
41 | 33 |
42 void SkSpriteBlitter::blitMask(const SkMask&, const SkIRect& clip) { | 34 void SkSpriteBlitter::blitMask(const SkMask&, const SkIRect& clip) { |
43 SkDEBUGFAIL("how did we get here?"); | 35 SkDEBUGFAIL("how did we get here?"); |
44 } | 36 } |
45 #endif | 37 #endif |
46 | 38 |
47 /////////////////////////////////////////////////////////////////////////////// | 39 /////////////////////////////////////////////////////////////////////////////// |
48 | 40 |
49 // returning null means the caller will call SkBlitter::Choose() and | 41 // returning null means the caller will call SkBlitter::Choose() and |
50 // have wrapped the source bitmap inside a shader | 42 // have wrapped the source bitmap inside a shader |
51 SkBlitter* SkBlitter::ChooseSprite(const SkBitmap& device, const SkPaint& paint, | 43 SkBlitter* SkBlitter::ChooseSprite(const SkBitmap& device, const SkPaint& paint, |
52 const SkBitmap& source, int left, int top, SkTBlitterAllocator* allocato
r) { | 44 const SkPixmap& source, int left, int top, SkTBlitterAllocator* allocato
r) { |
53 /* We currently ignore antialiasing and filtertype, meaning we will take ou
r | 45 /* We currently ignore antialiasing and filtertype, meaning we will take ou
r |
54 special blitters regardless of these settings. Ignoring filtertype seems
fine | 46 special blitters regardless of these settings. Ignoring filtertype seems
fine |
55 since by definition there is no scale in the matrix. Ignoring antialiasi
ng is | 47 since by definition there is no scale in the matrix. Ignoring antialiasi
ng is |
56 a bit of a hack, since we "could" pass in the fractional left/top for th
e bitmap, | 48 a bit of a hack, since we "could" pass in the fractional left/top for th
e bitmap, |
57 and respect that by blending the edges of the bitmap against the device.
To support | 49 and respect that by blending the edges of the bitmap against the device.
To support |
58 this we could either add more special blitters here, or detect antialias
ing in the | 50 this we could either add more special blitters here, or detect antialias
ing in the |
59 paint and return null if it is set, forcing the client to take the slow
shader case | 51 paint and return null if it is set, forcing the client to take the slow
shader case |
60 (which does respect soft edges). | 52 (which does respect soft edges). |
61 */ | 53 */ |
62 SkASSERT(allocator != NULL); | 54 SkASSERT(allocator != NULL); |
63 | 55 |
64 SkSpriteBlitter* blitter; | 56 SkSpriteBlitter* blitter; |
65 | 57 |
66 switch (device.colorType()) { | 58 switch (device.colorType()) { |
67 case kRGB_565_SkColorType: | 59 case kRGB_565_SkColorType: |
68 blitter = SkSpriteBlitter::ChooseD16(source, paint, allocator); | 60 blitter = SkSpriteBlitter::ChooseD16(source, paint, allocator); |
69 break; | 61 break; |
70 case kN32_SkColorType: | 62 case kN32_SkColorType: |
71 blitter = SkSpriteBlitter::ChooseD32(source, paint, allocator); | 63 blitter = SkSpriteBlitter::ChooseD32(source, paint, allocator); |
72 break; | 64 break; |
73 default: | 65 default: |
74 blitter = NULL; | 66 blitter = NULL; |
75 break; | 67 break; |
76 } | 68 } |
77 | 69 |
78 if (blitter) { | 70 if (blitter) { |
79 if (!blitter->setup(device, left, top, paint)) { | 71 blitter->setup(device, left, top, paint); |
80 // blitter was allocated by allocator, so we have to manually call i
ts destructor | |
81 blitter->~SkSpriteBlitter(); | |
82 blitter = NULL; | |
83 } | |
84 } | 72 } |
85 return blitter; | 73 return blitter; |
86 } | 74 } |
OLD | NEW |