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

Side by Side Diff: third_party/WebKit/Source/modules/shapedetection/ShapeDetector.cpp

Issue 2727133002: Remove ColorBehavior argument to Image::imageForCurrentFrame (Closed)
Patch Set: Rebase Created 3 years, 9 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 "modules/shapedetection/ShapeDetector.h" 5 #include "modules/shapedetection/ShapeDetector.h"
6 6
7 #include "core/dom/DOMException.h" 7 #include "core/dom/DOMException.h"
8 #include "core/dom/DOMRect.h" 8 #include "core/dom/DOMRect.h"
9 #include "core/dom/Document.h" 9 #include "core/dom/Document.h"
10 #include "core/frame/ImageBitmap.h" 10 #include "core/frame/ImageBitmap.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 if (size.isEmpty()) { 106 if (size.isEmpty()) {
107 resolver->resolve(HeapVector<Member<DOMRect>>()); 107 resolver->resolve(HeapVector<Member<DOMRect>>());
108 return promise; 108 return promise;
109 } 109 }
110 110
111 SkPixmap pixmap; 111 SkPixmap pixmap;
112 RefPtr<Uint8Array> pixelData; 112 RefPtr<Uint8Array> pixelData;
113 uint8_t* pixelDataPtr = nullptr; 113 uint8_t* pixelDataPtr = nullptr;
114 WTF::CheckedNumeric<int> allocationSize = 0; 114 WTF::CheckedNumeric<int> allocationSize = 0;
115 115
116 // TODO(ccameron): ShapeDetector can ignore color conversion. 116 sk_sp<SkImage> skImage = image->imageForCurrentFrame();
117 sk_sp<SkImage> skImage =
118 image->imageForCurrentFrame(ColorBehavior::transformToGlobalTarget());
119 // Use |skImage|'s pixels if it has direct access to them. 117 // Use |skImage|'s pixels if it has direct access to them.
120 if (skImage->peekPixels(&pixmap)) { 118 if (skImage->peekPixels(&pixmap)) {
121 pixelDataPtr = static_cast<uint8_t*>(pixmap.writable_addr()); 119 pixelDataPtr = static_cast<uint8_t*>(pixmap.writable_addr());
122 allocationSize = pixmap.getSafeSize(); 120 allocationSize = pixmap.getSafeSize();
123 } else if (imageSource.isImageBitmap()) { 121 } else if (imageSource.isImageBitmap()) {
124 ImageBitmap* imageBitmap = imageSource.getAsImageBitmap(); 122 ImageBitmap* imageBitmap = imageSource.getAsImageBitmap();
125 pixelData = imageBitmap->copyBitmapData(imageBitmap->isPremultiplied() 123 pixelData = imageBitmap->copyBitmapData(imageBitmap->isPremultiplied()
126 ? PremultiplyAlpha 124 ? PremultiplyAlpha
127 : DontPremultiplyAlpha, 125 : DontPremultiplyAlpha,
128 N32ColorType); 126 N32ColorType);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 return promise; 182 return promise;
185 } 183 }
186 184
187 Image* const blinkImage = imageResource->getImage(); 185 Image* const blinkImage = imageResource->getImage();
188 if (!blinkImage) { 186 if (!blinkImage) {
189 resolver->reject(DOMException::create( 187 resolver->reject(DOMException::create(
190 InvalidStateError, "Failed to get image from resource.")); 188 InvalidStateError, "Failed to get image from resource."));
191 return promise; 189 return promise;
192 } 190 }
193 191
194 // TODO(ccameron): ShapeDetector can ignore color conversion. 192 const sk_sp<SkImage> image = blinkImage->imageForCurrentFrame();
195 const sk_sp<SkImage> image = blinkImage->imageForCurrentFrame(
196 ColorBehavior::transformToGlobalTarget());
197 DCHECK_EQ(img->naturalWidth(), static_cast<unsigned>(image->width())); 193 DCHECK_EQ(img->naturalWidth(), static_cast<unsigned>(image->width()));
198 DCHECK_EQ(img->naturalHeight(), static_cast<unsigned>(image->height())); 194 DCHECK_EQ(img->naturalHeight(), static_cast<unsigned>(image->height()));
199 195
200 if (!image) { 196 if (!image) {
201 resolver->reject(DOMException::create( 197 resolver->reject(DOMException::create(
202 InvalidStateError, "Failed to get image from current frame.")); 198 InvalidStateError, "Failed to get image from current frame."));
203 return promise; 199 return promise;
204 } 200 }
205 201
206 const SkImageInfo skiaInfo = 202 const SkImageInfo skiaInfo =
(...skipping 23 matching lines...) Expand all
230 InvalidStateError, 226 InvalidStateError,
231 "Failed to read pixels: Unable to decompress or unsupported format.")); 227 "Failed to read pixels: Unable to decompress or unsupported format."));
232 return promise; 228 return promise;
233 } 229 }
234 230
235 return doDetect(resolver, std::move(sharedBufferHandle), img->naturalWidth(), 231 return doDetect(resolver, std::move(sharedBufferHandle), img->naturalWidth(),
236 img->naturalHeight()); 232 img->naturalHeight());
237 } 233 }
238 234
239 } // namespace blink 235 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698