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

Side by Side Diff: sky/engine/core/frame/ImageBitmap.cpp

Issue 701663002: Remove HTMLVideoElement. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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 | « sky/engine/core/frame/ImageBitmap.h ('k') | sky/engine/core/frame/UseCounter.h » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "config.h" 5 #include "config.h"
6 #include "core/frame/ImageBitmap.h" 6 #include "core/frame/ImageBitmap.h"
7 7
8 #include "core/html/HTMLCanvasElement.h" 8 #include "core/html/HTMLCanvasElement.h"
9 #include "core/html/HTMLVideoElement.h"
10 #include "core/html/ImageData.h" 9 #include "core/html/ImageData.h"
11 #include "core/html/canvas/CanvasRenderingContext.h" 10 #include "core/html/canvas/CanvasRenderingContext.h"
12 #include "platform/graphics/BitmapImage.h" 11 #include "platform/graphics/BitmapImage.h"
13 #include "platform/graphics/GraphicsContext.h" 12 #include "platform/graphics/GraphicsContext.h"
14 #include "platform/graphics/ImageBuffer.h" 13 #include "platform/graphics/ImageBuffer.h"
15 #include "wtf/RefPtr.h" 14 #include "wtf/RefPtr.h"
16 15
17 namespace blink { 16 namespace blink {
18 17
19 static inline IntRect normalizeRect(const IntRect& rect) 18 static inline IntRect normalizeRect(const IntRect& rect)
(...skipping 25 matching lines...) Expand all
45 m_bitmapOffset = srcRect.location(); 44 m_bitmapOffset = srcRect.location();
46 45
47 if (!srcRect.width() || !srcRect.height()) 46 if (!srcRect.width() || !srcRect.height())
48 m_imageElement = nullptr; 47 m_imageElement = nullptr;
49 else 48 else
50 m_imageElement->addClient(this); 49 m_imageElement->addClient(this);
51 50
52 ScriptWrappable::init(this); 51 ScriptWrappable::init(this);
53 } 52 }
54 53
55 ImageBitmap::ImageBitmap(HTMLVideoElement* video, const IntRect& cropRect)
56 : m_imageElement(nullptr)
57 , m_cropRect(cropRect)
58 , m_bitmapOffset(IntPoint())
59 {
60 IntSize playerSize;
61
62 if (video->webMediaPlayer())
63 playerSize = video->webMediaPlayer()->naturalSize();
64
65 IntRect videoRect = IntRect(IntPoint(), playerSize);
66 IntRect srcRect = intersection(cropRect, videoRect);
67 IntRect dstRect(IntPoint(), srcRect.size());
68
69 OwnPtr<ImageBuffer> buf = ImageBuffer::create(videoRect.size());
70 if (!buf)
71 return;
72 GraphicsContext* c = buf->context();
73 c->clip(dstRect);
74 c->translate(-srcRect.x(), -srcRect.y());
75 video->paintCurrentFrameInContext(c, videoRect);
76 m_bitmap = buf->copyImage(DontCopyBackingStore);
77 m_bitmapRect = IntRect(IntPoint(std::max(0, -cropRect.x()), std::max(0, -cro pRect.y())), srcRect.size());
78
79 ScriptWrappable::init(this);
80 }
81
82 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect) 54 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect)
83 : m_imageElement(nullptr) 55 : m_imageElement(nullptr)
84 , m_cropRect(cropRect) 56 , m_cropRect(cropRect)
85 , m_bitmapOffset(IntPoint()) 57 , m_bitmapOffset(IntPoint())
86 { 58 {
87 CanvasRenderingContext* sourceContext = canvas->renderingContext(); 59 CanvasRenderingContext* sourceContext = canvas->renderingContext();
88 if (sourceContext && sourceContext->is3d()) 60 if (sourceContext && sourceContext->is3d())
89 sourceContext->paintRenderingResultsToCanvas(); 61 sourceContext->paintRenderingResultsToCanvas();
90 62
91 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), canvas->size()) ); 63 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), canvas->size()) );
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 m_imageElement->removeClient(this); 125 m_imageElement->removeClient(this);
154 #endif 126 #endif
155 } 127 }
156 128
157 PassRefPtr<ImageBitmap> ImageBitmap::create(HTMLImageElement* image, const IntRe ct& cropRect) 129 PassRefPtr<ImageBitmap> ImageBitmap::create(HTMLImageElement* image, const IntRe ct& cropRect)
158 { 130 {
159 IntRect normalizedCropRect = normalizeRect(cropRect); 131 IntRect normalizedCropRect = normalizeRect(cropRect);
160 return adoptRef(new ImageBitmap(image, normalizedCropRect)); 132 return adoptRef(new ImageBitmap(image, normalizedCropRect));
161 } 133 }
162 134
163 PassRefPtr<ImageBitmap> ImageBitmap::create(HTMLVideoElement* video, const IntRe ct& cropRect)
164 {
165 IntRect normalizedCropRect = normalizeRect(cropRect);
166 return adoptRef(new ImageBitmap(video, normalizedCropRect));
167 }
168
169 PassRefPtr<ImageBitmap> ImageBitmap::create(HTMLCanvasElement* canvas, const Int Rect& cropRect) 135 PassRefPtr<ImageBitmap> ImageBitmap::create(HTMLCanvasElement* canvas, const Int Rect& cropRect)
170 { 136 {
171 IntRect normalizedCropRect = normalizeRect(cropRect); 137 IntRect normalizedCropRect = normalizeRect(cropRect);
172 return adoptRef(new ImageBitmap(canvas, normalizedCropRect)); 138 return adoptRef(new ImageBitmap(canvas, normalizedCropRect));
173 } 139 }
174 140
175 PassRefPtr<ImageBitmap> ImageBitmap::create(ImageData* data, const IntRect& crop Rect) 141 PassRefPtr<ImageBitmap> ImageBitmap::create(ImageData* data, const IntRect& crop Rect)
176 { 142 {
177 IntRect normalizedCropRect = normalizeRect(cropRect); 143 IntRect normalizedCropRect = normalizeRect(cropRect);
178 return adoptRef(new ImageBitmap(data, normalizedCropRect)); 144 return adoptRef(new ImageBitmap(data, normalizedCropRect));
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 return FloatSize(width(), height()); 195 return FloatSize(width(), height());
230 } 196 }
231 197
232 void ImageBitmap::trace(Visitor* visitor) 198 void ImageBitmap::trace(Visitor* visitor)
233 { 199 {
234 visitor->trace(m_imageElement); 200 visitor->trace(m_imageElement);
235 ImageLoaderClient::trace(visitor); 201 ImageLoaderClient::trace(visitor);
236 } 202 }
237 203
238 } 204 }
OLDNEW
« no previous file with comments | « sky/engine/core/frame/ImageBitmap.h ('k') | sky/engine/core/frame/UseCounter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698