Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(511)

Side by Side Diff: src/core/SkMask.cpp

Issue 889303005: return reference to cache instead of copying the mask (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: reorder declarations Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/core/SkMaskFilter.h ('k') | src/core/SkMaskFilter.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2007 The Android Open Source Project 2 * Copyright 2007 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 "SkMask.h" 8 #include "SkMask.h"
9 9
10 //#define TRACK_SKMASK_LIFETIME
11
10 /** returns the product if it is positive and fits in 31 bits. Otherwise this 12 /** returns the product if it is positive and fits in 31 bits. Otherwise this
11 returns 0. 13 returns 0.
12 */ 14 */
13 static int32_t safeMul32(int32_t a, int32_t b) { 15 static int32_t safeMul32(int32_t a, int32_t b) {
14 int64_t size = sk_64_mul(a, b); 16 int64_t size = sk_64_mul(a, b);
15 if (size > 0 && sk_64_isS32(size)) { 17 if (size > 0 && sk_64_isS32(size)) {
16 return sk_64_asS32(size); 18 return sk_64_asS32(size);
17 } 19 }
18 return 0; 20 return 0;
19 } 21 }
20 22
21 size_t SkMask::computeImageSize() const { 23 size_t SkMask::computeImageSize() const {
22 return safeMul32(fBounds.height(), fRowBytes); 24 return safeMul32(fBounds.height(), fRowBytes);
23 } 25 }
24 26
25 size_t SkMask::computeTotalImageSize() const { 27 size_t SkMask::computeTotalImageSize() const {
26 size_t size = this->computeImageSize(); 28 size_t size = this->computeImageSize();
27 if (fFormat == SkMask::k3D_Format) { 29 if (fFormat == SkMask::k3D_Format) {
28 size = safeMul32(SkToS32(size), 3); 30 size = safeMul32(SkToS32(size), 3);
29 } 31 }
30 return size; 32 return size;
31 } 33 }
32 34
35 #ifdef TRACK_SKMASK_LIFETIME
36 static int gCounter;
37 #endif
38
33 /** We explicitly use this allocator for SkBimap pixels, so that we can 39 /** We explicitly use this allocator for SkBimap pixels, so that we can
34 freely assign memory allocated by one class to the other. 40 freely assign memory allocated by one class to the other.
35 */ 41 */
36 uint8_t* SkMask::AllocImage(size_t size) { 42 uint8_t* SkMask::AllocImage(size_t size) {
43 #ifdef TRACK_SKMASK_LIFETIME
44 SkDebugf("SkMask::AllocImage %d\n", gCounter++);
45 #endif
37 return (uint8_t*)sk_malloc_throw(SkAlign4(size)); 46 return (uint8_t*)sk_malloc_throw(SkAlign4(size));
38 } 47 }
39 48
40 /** We explicitly use this allocator for SkBimap pixels, so that we can 49 /** We explicitly use this allocator for SkBimap pixels, so that we can
41 freely assign memory allocated by one class to the other. 50 freely assign memory allocated by one class to the other.
42 */ 51 */
43 void SkMask::FreeImage(void* image) { 52 void SkMask::FreeImage(void* image) {
53 #ifdef TRACK_SKMASK_LIFETIME
54 if (image) {
55 SkDebugf("SkMask::FreeImage %d\n", --gCounter);
56 }
57 #endif
44 sk_free(image); 58 sk_free(image);
45 } 59 }
46 60
47 /////////////////////////////////////////////////////////////////////////////// 61 ///////////////////////////////////////////////////////////////////////////////
48 62
49 static const int gMaskFormatToShift[] = { 63 static const int gMaskFormatToShift[] = {
50 ~0, // BW -- not supported 64 ~0, // BW -- not supported
51 0, // A8 65 0, // A8
52 0, // 3D 66 0, // 3D
53 2, // ARGB32 67 2, // ARGB32
54 1, // LCD16 68 1, // LCD16
55 }; 69 };
56 70
57 static int maskFormatToShift(SkMask::Format format) { 71 static int maskFormatToShift(SkMask::Format format) {
58 SkASSERT((unsigned)format < SK_ARRAY_COUNT(gMaskFormatToShift)); 72 SkASSERT((unsigned)format < SK_ARRAY_COUNT(gMaskFormatToShift));
59 SkASSERT(SkMask::kBW_Format != format); 73 SkASSERT(SkMask::kBW_Format != format);
60 return gMaskFormatToShift[format]; 74 return gMaskFormatToShift[format];
61 } 75 }
62 76
63 void* SkMask::getAddr(int x, int y) const { 77 void* SkMask::getAddr(int x, int y) const {
64 SkASSERT(kBW_Format != fFormat); 78 SkASSERT(kBW_Format != fFormat);
65 SkASSERT(fBounds.contains(x, y)); 79 SkASSERT(fBounds.contains(x, y));
66 SkASSERT(fImage); 80 SkASSERT(fImage);
67 81
68 char* addr = (char*)fImage; 82 char* addr = (char*)fImage;
69 addr += (y - fBounds.fTop) * fRowBytes; 83 addr += (y - fBounds.fTop) * fRowBytes;
70 addr += (x - fBounds.fLeft) << maskFormatToShift(fFormat); 84 addr += (x - fBounds.fLeft) << maskFormatToShift(fFormat);
71 return addr; 85 return addr;
72 } 86 }
OLDNEW
« no previous file with comments | « include/core/SkMaskFilter.h ('k') | src/core/SkMaskFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698