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

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

Issue 2837273003: ShapeDetection: use makeNonTextureImage() to support texture-backed sources (Closed)
Patch Set: removed unused specific ImagBitmap case Created 3 years, 7 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/Document.h" 8 #include "core/dom/Document.h"
9 #include "core/dom/ExecutionContext.h" 9 #include "core/dom/ExecutionContext.h"
10 #include "core/frame/ImageBitmap.h" 10 #include "core/frame/ImageBitmap.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 if (size.IsEmpty()) { 109 if (size.IsEmpty()) {
110 resolver->Resolve(HeapVector<Member<DOMRect>>()); 110 resolver->Resolve(HeapVector<Member<DOMRect>>());
111 return promise; 111 return promise;
112 } 112 }
113 113
114 SkPixmap pixmap; 114 SkPixmap pixmap;
115 RefPtr<Uint8Array> pixel_data; 115 RefPtr<Uint8Array> pixel_data;
116 uint8_t* pixel_data_ptr = nullptr; 116 uint8_t* pixel_data_ptr = nullptr;
117 WTF::CheckedNumeric<int> allocation_size = 0; 117 WTF::CheckedNumeric<int> allocation_size = 0;
118 118
119 sk_sp<SkImage> sk_image = image->ImageForCurrentFrame(); 119 // makeNonTextureImage() will make a raster copy of ImageForCurrentFrame() if
120 // Use |skImage|'s pixels if it has direct access to them. 120 // needed, otherwise returning the original SkImage.
121 if (sk_image->peekPixels(&pixmap)) { 121 const sk_sp<SkImage> sk_image =
122 image->ImageForCurrentFrame()->makeNonTextureImage();
123 if (sk_image && sk_image->peekPixels(&pixmap)) {
122 pixel_data_ptr = static_cast<uint8_t*>(pixmap.writable_addr()); 124 pixel_data_ptr = static_cast<uint8_t*>(pixmap.writable_addr());
123 allocation_size = pixmap.getSafeSize(); 125 allocation_size = pixmap.getSafeSize();
124 } else if (image_source.isImageBitmap()) {
125 ImageBitmap* image_bitmap = image_source.getAsImageBitmap();
126 pixel_data = image_bitmap->CopyBitmapData(image_bitmap->IsPremultiplied()
127 ? kPremultiplyAlpha
128 : kDontPremultiplyAlpha,
129 kN32ColorType);
130 pixel_data_ptr = pixel_data->Data();
131 allocation_size = image_bitmap->Size().Area() * 4 /* bytes per pixel */;
132 } else { 126 } else {
133 // TODO(mcasas): retrieve the pixels from elsewhere. 127 // TODO(mcasas): retrieve the pixels from elsewhere.
134 NOTREACHED(); 128 NOTREACHED();
135 resolver->Reject(DOMException::Create( 129 resolver->Reject(DOMException::Create(
136 kInvalidStateError, "Failed to get pixels for current frame.")); 130 kInvalidStateError, "Failed to get pixels for current frame."));
137 return promise; 131 return promise;
138 } 132 }
139 133
140 mojo::ScopedSharedBufferHandle shared_buffer_handle = GetSharedBufferOnData( 134 mojo::ScopedSharedBufferHandle shared_buffer_handle = GetSharedBufferOnData(
141 resolver, pixel_data_ptr, allocation_size.ValueOrDefault(0)); 135 resolver, pixel_data_ptr, allocation_size.ValueOrDefault(0));
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 kInvalidStateError, 225 kInvalidStateError,
232 "Failed to read pixels: Unable to decompress or unsupported format.")); 226 "Failed to read pixels: Unable to decompress or unsupported format."));
233 return promise; 227 return promise;
234 } 228 }
235 229
236 return DoDetect(resolver, std::move(shared_buffer_handle), 230 return DoDetect(resolver, std::move(shared_buffer_handle),
237 img->naturalWidth(), img->naturalHeight()); 231 img->naturalWidth(), img->naturalHeight());
238 } 232 }
239 233
240 } // namespace blink 234 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698