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

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

Issue 22613002: Allow ImageBitmaps derived from HTMLImageElements to be evicted from RAM. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add test cases. Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/page/ImageBitmap.h ('k') | Source/core/page/ImageBitmapTest.cpp » ('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/page/ImageBitmap.h" 6 #include "core/page/ImageBitmap.h"
7 7
8 #include "core/html/HTMLCanvasElement.h" 8 #include "core/html/HTMLCanvasElement.h"
9 #include "core/html/HTMLImageElement.h" 9 #include "core/html/HTMLImageElement.h"
10 #include "core/html/HTMLVideoElement.h" 10 #include "core/html/HTMLVideoElement.h"
(...skipping 20 matching lines...) Expand all
31 image->nativeImageForCurrentFrame()->bitmap().extractSubset(&cropped, cropRe ct); 31 image->nativeImageForCurrentFrame()->bitmap().extractSubset(&cropped, cropRe ct);
32 return BitmapImage::create(NativeImageSkia::create(cropped)); 32 return BitmapImage::create(NativeImageSkia::create(cropped));
33 } 33 }
34 34
35 ImageBitmap::ImageBitmap(HTMLImageElement* image, const IntRect& cropRect) 35 ImageBitmap::ImageBitmap(HTMLImageElement* image, const IntRect& cropRect)
36 : m_cropRect(cropRect) 36 : m_cropRect(cropRect)
37 , m_imageElement(image) 37 , m_imageElement(image)
38 { 38 {
39 m_imageElement->addClient(this); 39 m_imageElement->addClient(this);
40 40
41 IntSize bitmapSize = intersection(cropRect, IntRect(0, 0, image->width(), im age->height())).size(); 41 IntRect srcRect = intersection(cropRect, IntRect(0, 0, image->width(), image ->height()));
42 m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y()) ), bitmapSize); 42 m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y()) ), srcRect.size());
43 m_bitmapOffset = srcRect.location();
43 44
44 ScriptWrappable::init(this); 45 ScriptWrappable::init(this);
45 } 46 }
46 47
47 ImageBitmap::ImageBitmap(HTMLVideoElement* video, const IntRect& cropRect) 48 ImageBitmap::ImageBitmap(HTMLVideoElement* video, const IntRect& cropRect)
48 : m_cropRect(cropRect) 49 : m_cropRect(cropRect)
49 , m_imageElement(0) 50 , m_imageElement(0)
51 , m_bitmapOffset(IntPoint())
Stephen White 2013/08/08 15:32:11 Out of curiosity, why don't we set a bitmap offset
50 { 52 {
51 IntRect videoRect = IntRect(IntPoint(), video->player()->naturalSize()); 53 IntRect videoRect = IntRect(IntPoint(), video->player()->naturalSize());
52 IntRect srcRect = intersection(cropRect, videoRect); 54 IntRect srcRect = intersection(cropRect, videoRect);
53 IntRect dstRect(IntPoint(), srcRect.size()); 55 IntRect dstRect(IntPoint(), srcRect.size());
54 56
55 m_buffer = ImageBuffer::create(videoRect.size()); 57 m_buffer = ImageBuffer::create(videoRect.size());
56 GraphicsContext* c = m_buffer->context(); 58 GraphicsContext* c = m_buffer->context();
57 c->clip(dstRect); 59 c->clip(dstRect);
58 c->translate(-srcRect.x(), -srcRect.y()); 60 c->translate(-srcRect.x(), -srcRect.y());
59 video->paintCurrentFrameInContext(c, videoRect); 61 video->paintCurrentFrameInContext(c, videoRect);
60 m_bitmap = m_buffer->copyImage(DontCopyBackingStore); 62 m_bitmap = m_buffer->copyImage(DontCopyBackingStore);
61 m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y()) ), srcRect.size()); 63 m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y()) ), srcRect.size());
62 64
63 ScriptWrappable::init(this); 65 ScriptWrappable::init(this);
64 } 66 }
65 67
66 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect) 68 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect)
67 : m_cropRect(cropRect) 69 : m_cropRect(cropRect)
68 , m_imageElement(0) 70 , m_imageElement(0)
71 , m_bitmapOffset(IntPoint())
69 { 72 {
70 IntSize canvasSize = canvas->size(); 73 IntSize canvasSize = canvas->size();
71 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), canvasSize)); 74 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), canvasSize));
72 IntRect dstRect(IntPoint(), srcRect.size()); 75 IntRect dstRect(IntPoint(), srcRect.size());
73 76
74 m_buffer = ImageBuffer::create(canvasSize); 77 m_buffer = ImageBuffer::create(canvasSize);
75 m_buffer->context()->drawImageBuffer(canvas->buffer(), dstRect, srcRect); 78 m_buffer->context()->drawImageBuffer(canvas->buffer(), dstRect, srcRect);
76 m_bitmap = m_buffer->copyImage(DontCopyBackingStore); 79 m_bitmap = m_buffer->copyImage(DontCopyBackingStore);
77 m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y()) ), srcRect.size()); 80 m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y()) ), srcRect.size());
78 81
79 ScriptWrappable::init(this); 82 ScriptWrappable::init(this);
80 } 83 }
81 84
82 ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect) 85 ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect)
83 : m_cropRect(cropRect) 86 : m_cropRect(cropRect)
84 , m_imageElement(0) 87 , m_imageElement(0)
88 , m_bitmapOffset(IntPoint())
85 { 89 {
86 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size())); 90 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size()));
87 91
88 m_buffer = ImageBuffer::create(data->size()); 92 m_buffer = ImageBuffer::create(data->size());
89 if (srcRect.width() > 0 && srcRect.height() > 0) 93 if (srcRect.width() > 0 && srcRect.height() > 0)
90 m_buffer->putByteArray(Unmultiplied, data->data(), data->size(), srcRect , IntPoint(min(0, -cropRect.x()), min(0, -cropRect.y()))); 94 m_buffer->putByteArray(Unmultiplied, data->data(), data->size(), srcRect , IntPoint(min(0, -cropRect.x()), min(0, -cropRect.y())));
91 95
92 m_bitmap = m_buffer->copyImage(DontCopyBackingStore); 96 m_bitmap = m_buffer->copyImage(DontCopyBackingStore);
93 m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y()) ), srcRect.size()); 97 m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y()) ), srcRect.size());
94 98
95 ScriptWrappable::init(this); 99 ScriptWrappable::init(this);
96 } 100 }
97 101
98 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, const IntRect& cropRect) 102 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, const IntRect& cropRect)
99 : m_cropRect(cropRect) 103 : m_cropRect(cropRect)
100 , m_imageElement(bitmap->imageElement()) 104 , m_imageElement(bitmap->imageElement())
Stephen White 2013/08/08 15:32:11 Nit: might be clearer to initialize m_bitmapOffset
101 { 105 {
102 IntRect oldBitmapRect = bitmap->bitmapRect(); 106 IntRect oldBitmapRect = bitmap->bitmapRect();
103 IntSize bitmapSize = intersection(cropRect, oldBitmapRect).size(); 107 IntRect srcRect = intersection(cropRect, oldBitmapRect);
104 IntPoint bitmapOffset(max(0, oldBitmapRect.x() - cropRect.x()), max(0, oldBi tmapRect.y() - cropRect.y())); 108 m_bitmapRect = IntRect(IntPoint(max(0, oldBitmapRect.x() - cropRect.x()), ma x(0, oldBitmapRect.y() - cropRect.y())), srcRect.size());
105 m_bitmapRect = IntRect(bitmapOffset, bitmapSize); 109
106 if (m_imageElement) { 110 if (m_imageElement) {
107 m_imageElement->addClient(this); 111 m_imageElement->addClient(this);
108 m_bitmap = 0; 112 m_bitmap = 0;
113 m_bitmapOffset = srcRect.location();
109 } else { 114 } else {
110 IntRect adjustedCropRect(IntPoint(cropRect.x() -oldBitmapRect.x(), cropR ect.y() - oldBitmapRect.y()), cropRect.size()); 115 IntRect adjustedCropRect(IntPoint(cropRect.x() -oldBitmapRect.x(), cropR ect.y() - oldBitmapRect.y()), cropRect.size());
111 m_bitmap = cropImage(bitmap->bitmapImage().get(), adjustedCropRect); 116 m_bitmap = cropImage(bitmap->bitmapImage().get(), adjustedCropRect);
117 m_bitmapOffset = IntPoint();
112 } 118 }
113 ScriptWrappable::init(this); 119 ScriptWrappable::init(this);
114 } 120 }
115 121
116 ImageBitmap::~ImageBitmap() 122 ImageBitmap::~ImageBitmap()
117 { 123 {
118 if (m_imageElement) 124 if (m_imageElement)
119 m_imageElement->removeClient(this); 125 m_imageElement->removeClient(this);
120 } 126 }
121 127
(...skipping 28 matching lines...) Expand all
150 PassRefPtr<ImageBitmap> ImageBitmap::create(ImageBitmap* bitmap, const IntRect& cropRect) 156 PassRefPtr<ImageBitmap> ImageBitmap::create(ImageBitmap* bitmap, const IntRect& cropRect)
151 { 157 {
152 IntRect normalizedCropRect = normalizeRect(cropRect); 158 IntRect normalizedCropRect = normalizeRect(cropRect);
153 RefPtr<ImageBitmap> imageBitmap(adoptRef(new ImageBitmap(bitmap, normalizedC ropRect))); 159 RefPtr<ImageBitmap> imageBitmap(adoptRef(new ImageBitmap(bitmap, normalizedC ropRect)));
154 return imageBitmap.release(); 160 return imageBitmap.release();
155 } 161 }
156 162
157 void ImageBitmap::notifyImageSourceChanged() 163 void ImageBitmap::notifyImageSourceChanged()
158 { 164 {
159 m_bitmap = cropImage(m_imageElement->cachedImage()->image(), m_cropRect); 165 m_bitmap = cropImage(m_imageElement->cachedImage()->image(), m_cropRect);
166 m_bitmapOffset = IntPoint();
160 m_imageElement = 0; 167 m_imageElement = 0;
161 } 168 }
162 169
163 PassRefPtr<Image> ImageBitmap::bitmapImage() const 170 PassRefPtr<Image> ImageBitmap::bitmapImage() const
164 { 171 {
165 ASSERT((m_imageElement || m_bitmap) && (!m_imageElement || !m_bitmap)); 172 ASSERT((m_imageElement || m_bitmap) && (!m_imageElement || !m_bitmap));
166 if (m_imageElement) 173 if (m_imageElement)
167 return cropImage(m_imageElement->cachedImage()->image(), m_cropRect); 174 return m_imageElement->cachedImage()->image();
168 return m_bitmap; 175 return m_bitmap;
169 } 176 }
170 177
171 } 178 }
OLDNEW
« no previous file with comments | « Source/core/page/ImageBitmap.h ('k') | Source/core/page/ImageBitmapTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698