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

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: build fixes for win+mac 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 "core/platform/graphics/BitmapImage.h" 12 #include "core/platform/graphics/BitmapImage.h"
13 #include "core/platform/graphics/GraphicsContext.h" 13 #include "core/platform/graphics/GraphicsContext.h"
14 #include "core/platform/graphics/ImageBuffer.h" 14 #include "core/platform/graphics/ImageBuffer.h"
15 #include "platform/graphics/UnacceleratedImageBufferSurface.h"
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<ImageBufferSurface> surface = adoptPtr(new UnacceleratedImageBufferSu rface(videoRect.size()));
67 GraphicsContext* c = buf->context(); 68 if (!surface->isValid())
69 return;
70 ImageBuffer buf(surface.release());
71 GraphicsContext* c = buf.context();
68 c->clip(dstRect); 72 c->clip(dstRect);
69 c->translate(-srcRect.x(), -srcRect.y()); 73 c->translate(-srcRect.x(), -srcRect.y());
70 video->paintCurrentFrameInContext(c, videoRect); 74 video->paintCurrentFrameInContext(c, videoRect);
71 m_bitmap = buf->copyImage(DontCopyBackingStore); 75 m_bitmap = buf.copyImage(DontCopyBackingStore);
72 m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y()) ), srcRect.size()); 76 m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y()) ), srcRect.size());
73 77
74 ScriptWrappable::init(this); 78 ScriptWrappable::init(this);
75 } 79 }
76 80
77 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect) 81 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect)
78 : m_imageElement(0) 82 : m_imageElement(0)
79 , m_cropRect(cropRect) 83 , m_cropRect(cropRect)
80 , m_bitmapOffset(IntPoint()) 84 , m_bitmapOffset(IntPoint())
81 { 85 {
82 CanvasRenderingContext* sourceContext = canvas->renderingContext(); 86 CanvasRenderingContext* sourceContext = canvas->renderingContext();
83 if (sourceContext && sourceContext->is3d()) 87 if (sourceContext && sourceContext->is3d())
84 sourceContext->paintRenderingResultsToCanvas(); 88 sourceContext->paintRenderingResultsToCanvas();
85 89
86 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), canvas->size()) ); 90 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), canvas->size()) );
87 m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y()) ), srcRect.size()); 91 m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y()) ), srcRect.size());
88 m_bitmap = cropImage(canvas->buffer()->copyImage(CopyBackingStore).get(), cr opRect); 92 m_bitmap = cropImage(canvas->buffer()->copyImage(CopyBackingStore).get(), cr opRect);
89 93
90 ScriptWrappable::init(this); 94 ScriptWrappable::init(this);
91 } 95 }
92 96
93 ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect) 97 ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect)
94 : m_imageElement(0) 98 : m_imageElement(0)
95 , m_cropRect(cropRect) 99 , m_cropRect(cropRect)
96 , m_bitmapOffset(IntPoint()) 100 , m_bitmapOffset(IntPoint())
97 { 101 {
98 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size())); 102 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size()));
99 103
100 OwnPtr<ImageBuffer> buf = ImageBuffer::create(data->size(), 1, Unaccelerated NonPlatformBuffer); 104 OwnPtr<ImageBufferSurface> surface = adoptPtr(new UnacceleratedImageBufferSu rface(data->size()));
105 if (!surface->isValid())
106 return;
107 ImageBuffer buf(surface.release());
101 if (srcRect.width() > 0 && srcRect.height() > 0) 108 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()))); 109 buf.putByteArray(Premultiplied, data->data(), data->size(), srcRect, Int Point(min(0, -cropRect.x()), min(0, -cropRect.y())));
103 110
104 m_bitmap = buf->copyImage(DontCopyBackingStore); 111 m_bitmap = buf.copyImage(DontCopyBackingStore);
105 m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y()) ), srcRect.size()); 112 m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y()) ), srcRect.size());
106 113
107 ScriptWrappable::init(this); 114 ScriptWrappable::init(this);
108 } 115 }
109 116
110 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, const IntRect& cropRect) 117 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, const IntRect& cropRect)
111 : m_imageElement(bitmap->imageElement()) 118 : m_imageElement(bitmap->imageElement())
112 , m_bitmap(0) 119 , m_bitmap(0)
113 , m_cropRect(cropRect) 120 , m_cropRect(cropRect)
114 , m_bitmapOffset(IntPoint()) 121 , m_bitmapOffset(IntPoint())
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 197
191 PassRefPtr<Image> ImageBitmap::bitmapImage() const 198 PassRefPtr<Image> ImageBitmap::bitmapImage() const
192 { 199 {
193 ASSERT((m_imageElement || m_bitmap || !m_bitmapRect.width() || !m_bitmapRect .height()) && (!m_imageElement || !m_bitmap)); 200 ASSERT((m_imageElement || m_bitmap || !m_bitmapRect.width() || !m_bitmapRect .height()) && (!m_imageElement || !m_bitmap));
194 if (m_imageElement) 201 if (m_imageElement)
195 return m_imageElement->cachedImage()->image(); 202 return m_imageElement->cachedImage()->image();
196 return m_bitmap; 203 return m_bitmap;
197 } 204 }
198 205
199 } 206 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698