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

Side by Side Diff: ui/gfx/image/image_util.cc

Issue 2823003002: SkBitmap and SkPixelRef no longer need lock/unlock (Closed)
Patch Set: win fix after rebase Created 3 years, 8 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 | « ui/gfx/image/image_unittest_util.cc ('k') | ui/gfx/ipc/skia/OWNERS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/image/image_util.h" 5 #include "ui/gfx/image/image_util.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 55
56 bool JPEG1xEncodedDataFromSkiaRepresentation(const Image& image, 56 bool JPEG1xEncodedDataFromSkiaRepresentation(const Image& image,
57 int quality, 57 int quality,
58 std::vector<unsigned char>* dst) { 58 std::vector<unsigned char>* dst) {
59 const gfx::ImageSkiaRep& image_skia_rep = 59 const gfx::ImageSkiaRep& image_skia_rep =
60 image.AsImageSkia().GetRepresentation(1.0f); 60 image.AsImageSkia().GetRepresentation(1.0f);
61 if (image_skia_rep.scale() != 1.0f) 61 if (image_skia_rep.scale() != 1.0f)
62 return false; 62 return false;
63 63
64 const SkBitmap& bitmap = image_skia_rep.sk_bitmap(); 64 const SkBitmap& bitmap = image_skia_rep.sk_bitmap();
65 SkAutoLockPixels bitmap_lock(bitmap);
66
67 if (!bitmap.readyToDraw()) 65 if (!bitmap.readyToDraw())
68 return false; 66 return false;
69 67
70 return gfx::JPEGCodec::Encode( 68 return gfx::JPEGCodec::Encode(
71 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), 69 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)),
72 gfx::JPEGCodec::FORMAT_SkBitmap, bitmap.width(), 70 gfx::JPEGCodec::FORMAT_SkBitmap, bitmap.width(),
73 bitmap.height(), 71 bitmap.height(),
74 static_cast<int>(bitmap.rowBytes()), quality, 72 static_cast<int>(bitmap.rowBytes()), quality,
75 dst); 73 dst);
76 } 74 }
77 #endif // !defined(OS_IOS) 75 #endif // !defined(OS_IOS)
78 76
79 void GetVisibleMargins(const ImageSkia& image, int* left, int* right) { 77 void GetVisibleMargins(const ImageSkia& image, int* left, int* right) {
80 *left = 0; 78 *left = 0;
81 *right = 0; 79 *right = 0;
82 if (!image.HasRepresentation(1.f)) 80 if (!image.HasRepresentation(1.f))
83 return; 81 return;
84 const SkBitmap& bitmap = image.GetRepresentation(1.f).sk_bitmap(); 82 const SkBitmap& bitmap = image.GetRepresentation(1.f).sk_bitmap();
85 if (bitmap.drawsNothing() || bitmap.isOpaque()) 83 if (bitmap.drawsNothing() || bitmap.isOpaque())
86 return; 84 return;
87 85
88 SkAutoLockPixels lock(bitmap);
89 int x = 0; 86 int x = 0;
90 for (; x < bitmap.width(); ++x) { 87 for (; x < bitmap.width(); ++x) {
91 if (ColumnHasVisiblePixels(bitmap, x)) { 88 if (ColumnHasVisiblePixels(bitmap, x)) {
92 *left = x; 89 *left = x;
93 break; 90 break;
94 } 91 }
95 } 92 }
96 93
97 if (x == bitmap.width()) { 94 if (x == bitmap.width()) {
98 // Image is fully transparent. Divide the width in half, giving the leading 95 // Image is fully transparent. Divide the width in half, giving the leading
99 // region the extra pixel for odd widths. 96 // region the extra pixel for odd widths.
100 *left = (bitmap.width() + 1) / 2; 97 *left = (bitmap.width() + 1) / 2;
101 *right = bitmap.width() - *left; 98 *right = bitmap.width() - *left;
102 return; 99 return;
103 } 100 }
104 101
105 // Since we already know column *left is non-transparent, we can avoid 102 // Since we already know column *left is non-transparent, we can avoid
106 // rechecking that column; hence the '>' here. 103 // rechecking that column; hence the '>' here.
107 for (x = bitmap.width() - 1; x > *left; --x) { 104 for (x = bitmap.width() - 1; x > *left; --x) {
108 if (ColumnHasVisiblePixels(bitmap, x)) 105 if (ColumnHasVisiblePixels(bitmap, x))
109 break; 106 break;
110 } 107 }
111 *right = bitmap.width() - 1 - x; 108 *right = bitmap.width() - 1 - x;
112 } 109 }
113 110
114 } // namespace gfx 111 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/image/image_unittest_util.cc ('k') | ui/gfx/ipc/skia/OWNERS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698