| OLD | NEW |
| 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 MojoAlphaTypeToSk(data.alpha_type()), | 173 MojoAlphaTypeToSk(data.alpha_type()), |
| 174 MojoProfileTypeToSk(data.profile_type())), | 174 MojoProfileTypeToSk(data.profile_type())), |
| 175 data.row_bytes())) { | 175 data.row_bytes())) { |
| 176 return false; | 176 return false; |
| 177 } | 177 } |
| 178 | 178 |
| 179 // If the image is empty, return success after setting the image info. | 179 // If the image is empty, return success after setting the image info. |
| 180 if (data.width() == 0 || data.height() == 0) | 180 if (data.width() == 0 || data.height() == 0) |
| 181 return true; | 181 return true; |
| 182 | 182 |
| 183 SkAutoPixmapUnlock pixmap; | |
| 184 mojo::ArrayDataView<uint8_t> data_view; | 183 mojo::ArrayDataView<uint8_t> data_view; |
| 185 data.GetPixelDataDataView(&data_view); | 184 data.GetPixelDataDataView(&data_view); |
| 186 if (static_cast<uint32_t>(b->width()) != data.width() || | 185 if (static_cast<uint32_t>(b->width()) != data.width() || |
| 187 static_cast<uint32_t>(b->height()) != data.height() || | 186 static_cast<uint32_t>(b->height()) != data.height() || |
| 188 static_cast<uint64_t>(b->rowBytes()) != data.row_bytes() || | 187 static_cast<uint64_t>(b->rowBytes()) != data.row_bytes() || |
| 189 b->getSize() != data_view.size() || !b->requestLock(&pixmap) || | 188 b->getSize() != data_view.size() || !b->readyToDraw()) { |
| 190 !b->readyToDraw()) { | |
| 191 return false; | 189 return false; |
| 192 } | 190 } |
| 193 | 191 |
| 194 BitmapBuffer bitmap_buffer = {0, b->getSize(), | 192 BitmapBuffer bitmap_buffer = {0, b->getSize(), |
| 195 static_cast<uint8_t*>(b->getPixels())}; | 193 static_cast<uint8_t*>(b->getPixels())}; |
| 196 if (!data.ReadPixelData(&bitmap_buffer) || bitmap_buffer.size != b->getSize()) | 194 if (!data.ReadPixelData(&bitmap_buffer) || bitmap_buffer.size != b->getSize()) |
| 197 return false; | 195 return false; |
| 198 | 196 |
| 199 b->notifyPixelsChanged(); | 197 b->notifyPixelsChanged(); |
| 200 return true; | 198 return true; |
| 201 } | 199 } |
| 202 | 200 |
| 203 // static | |
| 204 void* StructTraits<skia::mojom::BitmapDataView, SkBitmap>::SetUpContext( | |
| 205 const SkBitmap& b) { | |
| 206 b.lockPixels(); | |
| 207 return nullptr; | |
| 208 } | |
| 209 | |
| 210 // static | |
| 211 void StructTraits<skia::mojom::BitmapDataView, SkBitmap>::TearDownContext( | |
| 212 const SkBitmap& b, | |
| 213 void* context) { | |
| 214 b.unlockPixels(); | |
| 215 } | |
| 216 | |
| 217 } // namespace mojo | 201 } // namespace mojo |
| OLD | NEW |