OLD | NEW |
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" |
(...skipping 30 matching lines...) Expand all Loading... |
41 , m_cropRect(cropRect) | 41 , m_cropRect(cropRect) |
42 { | 42 { |
43 IntRect srcRect = intersection(cropRect, IntRect(0, 0, image->width(), image
->height())); | 43 IntRect srcRect = intersection(cropRect, IntRect(0, 0, image->width(), image
->height())); |
44 m_bitmapRect = IntRect(IntPoint(std::max(0, -cropRect.x()), std::max(0, -cro
pRect.y())), srcRect.size()); | 44 m_bitmapRect = IntRect(IntPoint(std::max(0, -cropRect.x()), std::max(0, -cro
pRect.y())), srcRect.size()); |
45 m_bitmapOffset = srcRect.location(); | 45 m_bitmapOffset = srcRect.location(); |
46 | 46 |
47 if (!srcRect.width() || !srcRect.height()) | 47 if (!srcRect.width() || !srcRect.height()) |
48 m_imageElement = nullptr; | 48 m_imageElement = nullptr; |
49 else | 49 else |
50 m_imageElement->addClient(this); | 50 m_imageElement->addClient(this); |
51 | |
52 ScriptWrappable::init(this); | |
53 } | 51 } |
54 | 52 |
55 ImageBitmap::ImageBitmap(HTMLVideoElement* video, const IntRect& cropRect) | 53 ImageBitmap::ImageBitmap(HTMLVideoElement* video, const IntRect& cropRect) |
56 : m_imageElement(nullptr) | 54 : m_imageElement(nullptr) |
57 , m_cropRect(cropRect) | 55 , m_cropRect(cropRect) |
58 , m_bitmapOffset(IntPoint()) | 56 , m_bitmapOffset(IntPoint()) |
59 { | 57 { |
60 IntSize playerSize; | 58 IntSize playerSize; |
61 | 59 |
62 if (video->webMediaPlayer()) | 60 if (video->webMediaPlayer()) |
63 playerSize = video->webMediaPlayer()->naturalSize(); | 61 playerSize = video->webMediaPlayer()->naturalSize(); |
64 | 62 |
65 IntRect videoRect = IntRect(IntPoint(), playerSize); | 63 IntRect videoRect = IntRect(IntPoint(), playerSize); |
66 IntRect srcRect = intersection(cropRect, videoRect); | 64 IntRect srcRect = intersection(cropRect, videoRect); |
67 IntRect dstRect(IntPoint(), srcRect.size()); | 65 IntRect dstRect(IntPoint(), srcRect.size()); |
68 | 66 |
69 OwnPtr<ImageBuffer> buf = ImageBuffer::create(videoRect.size()); | 67 OwnPtr<ImageBuffer> buf = ImageBuffer::create(videoRect.size()); |
70 if (!buf) | 68 if (!buf) |
71 return; | 69 return; |
72 GraphicsContext* c = buf->context(); | 70 GraphicsContext* c = buf->context(); |
73 c->clip(dstRect); | 71 c->clip(dstRect); |
74 c->translate(-srcRect.x(), -srcRect.y()); | 72 c->translate(-srcRect.x(), -srcRect.y()); |
75 video->paintCurrentFrameInContext(c, videoRect); | 73 video->paintCurrentFrameInContext(c, videoRect); |
76 m_bitmap = buf->copyImage(DontCopyBackingStore); | 74 m_bitmap = buf->copyImage(DontCopyBackingStore); |
77 m_bitmapRect = IntRect(IntPoint(std::max(0, -cropRect.x()), std::max(0, -cro
pRect.y())), srcRect.size()); | 75 m_bitmapRect = IntRect(IntPoint(std::max(0, -cropRect.x()), std::max(0, -cro
pRect.y())), srcRect.size()); |
78 | |
79 ScriptWrappable::init(this); | |
80 } | 76 } |
81 | 77 |
82 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect) | 78 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect) |
83 : m_imageElement(nullptr) | 79 : m_imageElement(nullptr) |
84 , m_cropRect(cropRect) | 80 , m_cropRect(cropRect) |
85 , m_bitmapOffset(IntPoint()) | 81 , m_bitmapOffset(IntPoint()) |
86 { | 82 { |
87 CanvasRenderingContext* sourceContext = canvas->renderingContext(); | 83 CanvasRenderingContext* sourceContext = canvas->renderingContext(); |
88 if (sourceContext && sourceContext->is3d()) | 84 if (sourceContext && sourceContext->is3d()) |
89 sourceContext->paintRenderingResultsToCanvas(); | 85 sourceContext->paintRenderingResultsToCanvas(); |
90 | 86 |
91 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), canvas->size())
); | 87 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), canvas->size())
); |
92 m_bitmapRect = IntRect(IntPoint(std::max(0, -cropRect.x()), std::max(0, -cro
pRect.y())), srcRect.size()); | 88 m_bitmapRect = IntRect(IntPoint(std::max(0, -cropRect.x()), std::max(0, -cro
pRect.y())), srcRect.size()); |
93 m_bitmap = cropImage(canvas->buffer()->copyImage(CopyBackingStore).get(), cr
opRect); | 89 m_bitmap = cropImage(canvas->buffer()->copyImage(CopyBackingStore).get(), cr
opRect); |
94 | |
95 ScriptWrappable::init(this); | |
96 } | 90 } |
97 | 91 |
98 ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect) | 92 ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect) |
99 : m_imageElement(nullptr) | 93 : m_imageElement(nullptr) |
100 , m_cropRect(cropRect) | 94 , m_cropRect(cropRect) |
101 , m_bitmapOffset(IntPoint()) | 95 , m_bitmapOffset(IntPoint()) |
102 { | 96 { |
103 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size())); | 97 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size())); |
104 | 98 |
105 OwnPtr<ImageBuffer> buf = ImageBuffer::create(data->size()); | 99 OwnPtr<ImageBuffer> buf = ImageBuffer::create(data->size()); |
106 if (!buf) | 100 if (!buf) |
107 return; | 101 return; |
108 if (srcRect.width() > 0 && srcRect.height() > 0) | 102 if (srcRect.width() > 0 && srcRect.height() > 0) |
109 buf->putByteArray(Premultiplied, data->data(), data->size(), srcRect, In
tPoint(std::min(0, -cropRect.x()), std::min(0, -cropRect.y()))); | 103 buf->putByteArray(Premultiplied, data->data(), data->size(), srcRect, In
tPoint(std::min(0, -cropRect.x()), std::min(0, -cropRect.y()))); |
110 | 104 |
111 m_bitmap = buf->copyImage(DontCopyBackingStore); | 105 m_bitmap = buf->copyImage(DontCopyBackingStore); |
112 m_bitmapRect = IntRect(IntPoint(std::max(0, -cropRect.x()), std::max(0, -cro
pRect.y())), srcRect.size()); | 106 m_bitmapRect = IntRect(IntPoint(std::max(0, -cropRect.x()), std::max(0, -cro
pRect.y())), srcRect.size()); |
113 | |
114 ScriptWrappable::init(this); | |
115 } | 107 } |
116 | 108 |
117 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, const IntRect& cropRect) | 109 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, const IntRect& cropRect) |
118 : m_imageElement(bitmap->imageElement()) | 110 : m_imageElement(bitmap->imageElement()) |
119 , m_bitmap(nullptr) | 111 , m_bitmap(nullptr) |
120 , m_cropRect(cropRect) | 112 , m_cropRect(cropRect) |
121 , m_bitmapOffset(IntPoint()) | 113 , m_bitmapOffset(IntPoint()) |
122 { | 114 { |
123 IntRect oldBitmapRect = bitmap->bitmapRect(); | 115 IntRect oldBitmapRect = bitmap->bitmapRect(); |
124 IntRect srcRect = intersection(cropRect, oldBitmapRect); | 116 IntRect srcRect = intersection(cropRect, oldBitmapRect); |
125 m_bitmapRect = IntRect(IntPoint(std::max(0, oldBitmapRect.x() - cropRect.x()
), std::max(0, oldBitmapRect.y() - cropRect.y())), srcRect.size()); | 117 m_bitmapRect = IntRect(IntPoint(std::max(0, oldBitmapRect.x() - cropRect.x()
), std::max(0, oldBitmapRect.y() - cropRect.y())), srcRect.size()); |
126 | 118 |
127 if (m_imageElement) { | 119 if (m_imageElement) { |
128 m_imageElement->addClient(this); | 120 m_imageElement->addClient(this); |
129 m_bitmapOffset = srcRect.location(); | 121 m_bitmapOffset = srcRect.location(); |
130 } else if (bitmap->bitmapImage()) { | 122 } else if (bitmap->bitmapImage()) { |
131 IntRect adjustedCropRect(IntPoint(cropRect.x() -oldBitmapRect.x(), cropR
ect.y() - oldBitmapRect.y()), cropRect.size()); | 123 IntRect adjustedCropRect(IntPoint(cropRect.x() -oldBitmapRect.x(), cropR
ect.y() - oldBitmapRect.y()), cropRect.size()); |
132 m_bitmap = cropImage(bitmap->bitmapImage().get(), adjustedCropRect); | 124 m_bitmap = cropImage(bitmap->bitmapImage().get(), adjustedCropRect); |
133 } | 125 } |
134 | |
135 ScriptWrappable::init(this); | |
136 } | 126 } |
137 | 127 |
138 ImageBitmap::ImageBitmap(Image* image, const IntRect& cropRect) | 128 ImageBitmap::ImageBitmap(Image* image, const IntRect& cropRect) |
139 : m_imageElement(nullptr) | 129 : m_imageElement(nullptr) |
140 , m_cropRect(cropRect) | 130 , m_cropRect(cropRect) |
141 { | 131 { |
142 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), image->size()))
; | 132 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), image->size()))
; |
143 m_bitmap = cropImage(image, cropRect); | 133 m_bitmap = cropImage(image, cropRect); |
144 m_bitmapRect = IntRect(IntPoint(std::max(0, -cropRect.x()), std::max(0, -cro
pRect.y())), srcRect.size()); | 134 m_bitmapRect = IntRect(IntPoint(std::max(0, -cropRect.x()), std::max(0, -cro
pRect.y())), srcRect.size()); |
145 | |
146 ScriptWrappable::init(this); | |
147 } | 135 } |
148 | 136 |
149 ImageBitmap::~ImageBitmap() | 137 ImageBitmap::~ImageBitmap() |
150 { | 138 { |
151 #if !ENABLE(OILPAN) | 139 #if !ENABLE(OILPAN) |
152 if (m_imageElement) | 140 if (m_imageElement) |
153 m_imageElement->removeClient(this); | 141 m_imageElement->removeClient(this); |
154 #endif | 142 #endif |
155 } | 143 } |
156 | 144 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 { | 216 { |
229 return FloatSize(width(), height()); | 217 return FloatSize(width(), height()); |
230 } | 218 } |
231 | 219 |
232 void ImageBitmap::trace(Visitor* visitor) | 220 void ImageBitmap::trace(Visitor* visitor) |
233 { | 221 { |
234 visitor->trace(m_imageElement); | 222 visitor->trace(m_imageElement); |
235 ImageLoaderClient::trace(visitor); | 223 ImageLoaderClient::trace(visitor); |
236 } | 224 } |
237 | 225 |
238 } | 226 } // namespace blink |
OLD | NEW |