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

Side by Side Diff: Source/core/frame/ImageBitmap.cpp

Issue 104023007: Refactoring ImageBuffer to decouple it from Canvas2DLayerBridge (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: mac+win build fix Created 7 years 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 | Annotate | Revision Log
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" 9 #include "core/html/HTMLVideoElement.h"
10 #include "core/html/ImageData.h" 10 #include "core/html/ImageData.h"
11 #include "core/html/canvas/CanvasRenderingContext.h" 11 #include "core/html/canvas/CanvasRenderingContext.h"
12 #include "platform/graphics/BitmapImage.h" 12 #include "platform/graphics/BitmapImage.h"
13 #include "platform/graphics/GraphicsContext.h" 13 #include "platform/graphics/GraphicsContext.h"
14 #include "platform/graphics/ImageBuffer.h" 14 #include "platform/graphics/ImageBuffer.h"
15 #include "platform/graphics/UnacceleratedImageBufferSurface.h"
Stephen White 2013/12/09 15:33:08 Please remove this if it's no longer necessary.
15 #include "wtf/RefPtr.h" 16 #include "wtf/RefPtr.h"
16 17
17 using namespace std; 18 using namespace std;
18 19
19 namespace WebCore { 20 namespace WebCore {
20 21
21 static inline IntRect normalizeRect(const IntRect& rect) 22 static inline IntRect normalizeRect(const IntRect& rect)
22 { 23 {
23 return IntRect(min(rect.x(), rect.maxX()), 24 return IntRect(min(rect.x(), rect.maxX()),
24 min(rect.y(), rect.maxY()), 25 min(rect.y(), rect.maxY()),
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 57
57 ImageBitmap::ImageBitmap(HTMLVideoElement* video, const IntRect& cropRect) 58 ImageBitmap::ImageBitmap(HTMLVideoElement* video, const IntRect& cropRect)
58 : m_imageElement(0) 59 : m_imageElement(0)
59 , m_cropRect(cropRect) 60 , m_cropRect(cropRect)
60 , m_bitmapOffset(IntPoint()) 61 , m_bitmapOffset(IntPoint())
61 { 62 {
62 IntRect videoRect = IntRect(IntPoint(), video->player()->naturalSize()); 63 IntRect videoRect = IntRect(IntPoint(), video->player()->naturalSize());
63 IntRect srcRect = intersection(cropRect, videoRect); 64 IntRect srcRect = intersection(cropRect, videoRect);
64 IntRect dstRect(IntPoint(), srcRect.size()); 65 IntRect dstRect(IntPoint(), srcRect.size());
65 66
66 OwnPtr<ImageBuffer> buf = ImageBuffer::create(videoRect.size(), 1, Unacceler atedNonPlatformBuffer); 67 OwnPtr<ImageBuffer> buf = ImageBuffer::create(videoRect.size());
68 if (!buf)
69 return;
67 GraphicsContext* c = buf->context(); 70 GraphicsContext* c = buf->context();
68 c->clip(dstRect); 71 c->clip(dstRect);
69 c->translate(-srcRect.x(), -srcRect.y()); 72 c->translate(-srcRect.x(), -srcRect.y());
70 video->paintCurrentFrameInContext(c, videoRect); 73 video->paintCurrentFrameInContext(c, videoRect);
71 m_bitmap = buf->copyImage(DontCopyBackingStore); 74 m_bitmap = buf->copyImage(DontCopyBackingStore);
72 m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y()) ), srcRect.size()); 75 m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y()) ), srcRect.size());
73 76
74 ScriptWrappable::init(this); 77 ScriptWrappable::init(this);
75 } 78 }
76 79
(...skipping 13 matching lines...) Expand all
90 ScriptWrappable::init(this); 93 ScriptWrappable::init(this);
91 } 94 }
92 95
93 ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect) 96 ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect)
94 : m_imageElement(0) 97 : m_imageElement(0)
95 , m_cropRect(cropRect) 98 , m_cropRect(cropRect)
96 , m_bitmapOffset(IntPoint()) 99 , m_bitmapOffset(IntPoint())
97 { 100 {
98 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size())); 101 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size()));
99 102
100 OwnPtr<ImageBuffer> buf = ImageBuffer::create(data->size(), 1, Unaccelerated NonPlatformBuffer); 103 OwnPtr<ImageBuffer> buf = ImageBuffer::create(data->size());
104 if (!buf)
105 return;
101 if (srcRect.width() > 0 && srcRect.height() > 0) 106 if (srcRect.width() > 0 && srcRect.height() > 0)
102 buf->putByteArray(Premultiplied, data->data(), data->size(), srcRect, In tPoint(min(0, -cropRect.x()), min(0, -cropRect.y()))); 107 buf->putByteArray(Premultiplied, data->data(), data->size(), srcRect, In tPoint(min(0, -cropRect.x()), min(0, -cropRect.y())));
103 108
104 m_bitmap = buf->copyImage(DontCopyBackingStore); 109 m_bitmap = buf->copyImage(DontCopyBackingStore);
105 m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y()) ), srcRect.size()); 110 m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y()) ), srcRect.size());
106 111
107 ScriptWrappable::init(this); 112 ScriptWrappable::init(this);
108 } 113 }
109 114
110 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, const IntRect& cropRect) 115 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, const IntRect& cropRect)
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 195
191 PassRefPtr<Image> ImageBitmap::bitmapImage() const 196 PassRefPtr<Image> ImageBitmap::bitmapImage() const
192 { 197 {
193 ASSERT((m_imageElement || m_bitmap || !m_bitmapRect.width() || !m_bitmapRect .height()) && (!m_imageElement || !m_bitmap)); 198 ASSERT((m_imageElement || m_bitmap || !m_bitmapRect.width() || !m_bitmapRect .height()) && (!m_imageElement || !m_bitmap));
194 if (m_imageElement) 199 if (m_imageElement)
195 return m_imageElement->cachedImage()->image(); 200 return m_imageElement->cachedImage()->image();
196 return m_bitmap; 201 return m_bitmap;
197 } 202 }
198 203
199 } 204 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698