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

Side by Side Diff: skia/public/interfaces/bitmap_skbitmap_struct_traits.cc

Issue 2046563005: Add ArrayTraits<CArray<T>> utility template (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed tsepez's comments Created 4 years, 6 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "skia/public/interfaces/bitmap_skbitmap_struct_traits.h" 5 #include "skia/public/interfaces/bitmap_skbitmap_struct_traits.h"
6 6
7 namespace mojo { 7 namespace mojo {
8 8
9 namespace { 9 namespace {
10 10
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 case kSRGB_SkColorProfileType: 105 case kSRGB_SkColorProfileType:
106 return skia::mojom::ColorProfileType::SRGB; 106 return skia::mojom::ColorProfileType::SRGB;
107 } 107 }
108 NOTREACHED(); 108 NOTREACHED();
109 return skia::mojom::ColorProfileType::LINEAR; 109 return skia::mojom::ColorProfileType::LINEAR;
110 } 110 }
111 111
112 } // namespace 112 } // namespace
113 113
114 // static 114 // static
115 size_t ArrayTraits<BitmapBuffer>::GetSize(const BitmapBuffer& b) {
116 return b.size;
117 }
118
119 // static
120 uint8_t* ArrayTraits<BitmapBuffer>::GetData(BitmapBuffer& b) {
121 return b.data;
122 }
123
124 // static
125 const uint8_t* ArrayTraits<BitmapBuffer>::GetData(const BitmapBuffer& b) {
126 return b.data;
127 }
128
129 // static
130 uint8_t& ArrayTraits<BitmapBuffer>::GetAt(BitmapBuffer& b, size_t i) {
131 return *(b.data + i);
132 }
133
134 // static
135 const uint8_t& ArrayTraits<BitmapBuffer>::GetAt(const BitmapBuffer& b,
136 size_t i) {
137 return *(b.data + i);
138 }
139
140 // static
141 bool ArrayTraits<BitmapBuffer>::Resize(BitmapBuffer& b, size_t size) {
142 return b.size == size;
143 }
144
145 // static
146 bool StructTraits<skia::mojom::Bitmap, SkBitmap>::IsNull(const SkBitmap& b) { 115 bool StructTraits<skia::mojom::Bitmap, SkBitmap>::IsNull(const SkBitmap& b) {
147 return b.isNull(); 116 return b.isNull();
148 } 117 }
149 118
150 // static 119 // static
151 void StructTraits<skia::mojom::Bitmap, SkBitmap>::SetToNull(SkBitmap* b) { 120 void StructTraits<skia::mojom::Bitmap, SkBitmap>::SetToNull(SkBitmap* b) {
152 b->reset(); 121 b->reset();
153 } 122 }
154 123
155 // static 124 // static
(...skipping 21 matching lines...) Expand all
177 146
178 // static 147 // static
179 uint32_t StructTraits<skia::mojom::Bitmap, SkBitmap>::height( 148 uint32_t StructTraits<skia::mojom::Bitmap, SkBitmap>::height(
180 const SkBitmap& b) { 149 const SkBitmap& b) {
181 return b.height() < 0 ? 0 : static_cast<uint32_t>(b.height()); 150 return b.height() < 0 ? 0 : static_cast<uint32_t>(b.height());
182 } 151 }
183 152
184 // static 153 // static
185 BitmapBuffer StructTraits<skia::mojom::Bitmap, SkBitmap>::pixel_data( 154 BitmapBuffer StructTraits<skia::mojom::Bitmap, SkBitmap>::pixel_data(
186 const SkBitmap& b) { 155 const SkBitmap& b) {
187 BitmapBuffer bitmap_buffer; 156 return {b.getSize(), b.getSize(), static_cast<uint8_t*>(b.getPixels())};
188 bitmap_buffer.data = static_cast<uint8_t*>(b.getPixels());
189 bitmap_buffer.size = b.getSize();
190 return bitmap_buffer;
191 } 157 }
192 158
193 // static 159 // static
194 bool StructTraits<skia::mojom::Bitmap, SkBitmap>::Read( 160 bool StructTraits<skia::mojom::Bitmap, SkBitmap>::Read(
195 skia::mojom::BitmapDataView data, 161 skia::mojom::BitmapDataView data,
196 SkBitmap* b) { 162 SkBitmap* b) {
197 // TODO: Ensure width and height are reasonable, eg. <= kMaxBitmapSize? 163 // TODO: Ensure width and height are reasonable, eg. <= kMaxBitmapSize?
198 *b = SkBitmap(); 164 *b = SkBitmap();
199 if (!b->tryAllocPixels(SkImageInfo::Make( 165 if (!b->tryAllocPixels(SkImageInfo::Make(
200 data.width(), data.height(), MojoColorTypeToSk(data.color_type()), 166 data.width(), data.height(), MojoColorTypeToSk(data.color_type()),
201 MojoAlphaTypeToSk(data.alpha_type()), 167 MojoAlphaTypeToSk(data.alpha_type()),
202 MojoProfileTypeToSk(data.profile_type())))) { 168 MojoProfileTypeToSk(data.profile_type())))) {
203 return false; 169 return false;
204 } 170 }
205 171
206 // If the image is empty, return success after setting the image info. 172 // If the image is empty, return success after setting the image info.
207 if (data.width() == 0 || data.height() == 0) 173 if (data.width() == 0 || data.height() == 0)
208 return true; 174 return true;
209 175
210 SkAutoPixmapUnlock pixmap; 176 SkAutoPixmapUnlock pixmap;
211 if (static_cast<uint32_t>(b->width()) != data.width() || 177 if (static_cast<uint32_t>(b->width()) != data.width() ||
212 static_cast<uint32_t>(b->height()) != data.height() || 178 static_cast<uint32_t>(b->height()) != data.height() ||
213 !b->requestLock(&pixmap) || !b->lockPixelsAreWritable() || 179 !b->requestLock(&pixmap) || !b->lockPixelsAreWritable() ||
214 !b->readyToDraw()) { 180 !b->readyToDraw()) {
215 return false; 181 return false;
216 } 182 }
217 183
218 BitmapBuffer bitmap_buffer; 184 BitmapBuffer bitmap_buffer = {0, b->getSize(),
219 bitmap_buffer.data = static_cast<uint8_t*>(b->getPixels()); 185 static_cast<uint8_t*>(b->getPixels())};
220 bitmap_buffer.size = b->getSize(); 186 if (!data.ReadPixelData(&bitmap_buffer) || bitmap_buffer.size != b->getSize())
221 if (!data.ReadPixelData(&bitmap_buffer))
222 return false; 187 return false;
223 188
224 b->notifyPixelsChanged(); 189 b->notifyPixelsChanged();
225 return true; 190 return true;
226 } 191 }
227 192
228 // static 193 // static
229 void* StructTraits<skia::mojom::Bitmap, SkBitmap>::SetUpContext( 194 void* StructTraits<skia::mojom::Bitmap, SkBitmap>::SetUpContext(
230 const SkBitmap& b) { 195 const SkBitmap& b) {
231 b.lockPixels(); 196 b.lockPixels();
232 return nullptr; 197 return nullptr;
233 } 198 }
234 199
235 // static 200 // static
236 void StructTraits<skia::mojom::Bitmap, SkBitmap>::TearDownContext( 201 void StructTraits<skia::mojom::Bitmap, SkBitmap>::TearDownContext(
237 const SkBitmap& b, 202 const SkBitmap& b,
238 void* context) { 203 void* context) {
239 b.unlockPixels(); 204 b.unlockPixels();
240 } 205 }
241 206
242 } // namespace mojo 207 } // namespace mojo
OLDNEW
« no previous file with comments | « skia/public/interfaces/bitmap_skbitmap_struct_traits.h ('k') | ui/events/mojo/latency_info_struct_traits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698