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

Side by Side Diff: third_party/WebKit/Source/core/frame/ImageBitmap.h

Issue 1413583004: refractoring ImageBitmap class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix leaked buffer Created 5 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
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 #ifndef ImageBitmap_h 5 #ifndef ImageBitmap_h
6 #define ImageBitmap_h 6 #define ImageBitmap_h
7 7
8 #include "bindings/core/v8/ScriptWrappable.h" 8 #include "bindings/core/v8/ScriptWrappable.h"
9 #include "core/CoreExport.h" 9 #include "core/CoreExport.h"
10 #include "core/html/HTMLImageElement.h" 10 #include "core/html/HTMLImageElement.h"
11 #include "core/html/canvas/CanvasImageSource.h" 11 #include "core/html/canvas/CanvasImageSource.h"
12 #include "platform/geometry/IntRect.h" 12 #include "platform/geometry/IntRect.h"
13 #include "platform/graphics/Image.h" 13 #include "platform/graphics/Image.h"
14 #include "platform/graphics/ImageBuffer.h"
14 #include "platform/heap/Handle.h" 15 #include "platform/heap/Handle.h"
16 #include "third_party/skia/include/core/SkImage.h"
15 #include "wtf/PassRefPtr.h" 17 #include "wtf/PassRefPtr.h"
16 #include "wtf/RefCounted.h" 18 #include "wtf/RefCounted.h"
17 19
18 namespace blink { 20 namespace blink {
19 21
20 class HTMLCanvasElement; 22 class HTMLCanvasElement;
21 class HTMLVideoElement; 23 class HTMLVideoElement;
22 class ImageData; 24 class ImageData;
23 25
24 class CORE_EXPORT ImageBitmap final : public RefCountedWillBeGarbageCollectedFin alized<ImageBitmap>, public ScriptWrappable, public ImageLoaderClient, public Ca nvasImageSource { 26 class CORE_EXPORT ImageBitmap final : public RefCountedWillBeGarbageCollectedFin alized<ImageBitmap>, public ScriptWrappable, public ImageLoaderClient, public Ca nvasImageSource {
25 DEFINE_WRAPPERTYPEINFO(); 27 DEFINE_WRAPPERTYPEINFO();
26 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(ImageBitmap); 28 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(ImageBitmap);
27 public: 29 public:
28 static PassRefPtrWillBeRawPtr<ImageBitmap> create(HTMLImageElement*, const I ntRect&); 30 static PassRefPtrWillBeRawPtr<ImageBitmap> create(HTMLImageElement*, const I ntRect&);
29 static PassRefPtrWillBeRawPtr<ImageBitmap> create(HTMLVideoElement*, const I ntRect&); 31 static PassRefPtrWillBeRawPtr<ImageBitmap> create(HTMLVideoElement*, const I ntRect&);
30 static PassRefPtrWillBeRawPtr<ImageBitmap> create(HTMLCanvasElement*, const IntRect&); 32 static PassRefPtrWillBeRawPtr<ImageBitmap> create(HTMLCanvasElement*, const IntRect&);
31 static PassRefPtrWillBeRawPtr<ImageBitmap> create(ImageData*, const IntRect& ); 33 static PassRefPtrWillBeRawPtr<ImageBitmap> create(ImageData*, const IntRect& );
32 static PassRefPtrWillBeRawPtr<ImageBitmap> create(ImageBitmap*, const IntRec t&); 34 static PassRefPtrWillBeRawPtr<ImageBitmap> create(ImageBitmap*, const IntRec t&);
33 static PassRefPtrWillBeRawPtr<ImageBitmap> create(Image*, const IntRect&); 35 static PassRefPtrWillBeRawPtr<ImageBitmap> create(Image*, const IntRect&);
34 36
35 PassRefPtr<Image> bitmapImage() const; 37 SkImage* skImage() const { return (m_image) ? m_image.get() : nullptr; }
36 PassRefPtrWillBeRawPtr<HTMLImageElement> imageElement() const { return m_ima geElement; } 38 int width() const { return (m_image) ? m_image->width(): 0; }
37 39 int height() const { return (m_image) ? m_image->height(): 0; }
38 IntRect bitmapRect() const { return m_bitmapRect; } 40 IntSize size() const { return (m_image) ? IntSize(m_image->width(), m_image- >height()) : IntSize(); }
39
40 int width() const { return m_cropRect.width(); }
41 int height() const { return m_cropRect.height(); }
42 IntSize size() const { return m_cropRect.size(); }
43 41
44 ~ImageBitmap() override; 42 ~ImageBitmap() override;
45 43
46 // CanvasImageSource implementation 44 // CanvasImageSource implementation
47 PassRefPtr<Image> getSourceImageForCanvas(SourceImageStatus*, AccelerationHi nt) const override; 45 PassRefPtr<Image> getSourceImageForCanvas(SourceImageStatus*, AccelerationHi nt) const override;
48 bool wouldTaintOrigin(SecurityOrigin*) const override { return false; } 46 bool wouldTaintOrigin(SecurityOrigin*) const override { return false; }
49 void adjustDrawRects(FloatRect* srcRect, FloatRect* dstRect) const override; 47 void adjustDrawRects(FloatRect* srcRect, FloatRect* dstRect) const override;
50 FloatSize elementSize() const override; 48 FloatSize elementSize() const override;
51 49
52 DECLARE_VIRTUAL_TRACE(); 50 DECLARE_VIRTUAL_TRACE();
53 51
54 private: 52 private:
55 ImageBitmap(HTMLImageElement*, const IntRect&); 53 ImageBitmap(HTMLImageElement*, const IntRect&);
56 ImageBitmap(HTMLVideoElement*, const IntRect&); 54 ImageBitmap(HTMLVideoElement*, const IntRect&);
57 ImageBitmap(HTMLCanvasElement*, const IntRect&); 55 ImageBitmap(HTMLCanvasElement*, const IntRect&);
58 ImageBitmap(ImageData*, const IntRect&); 56 ImageBitmap(ImageData*, const IntRect&);
59 ImageBitmap(ImageBitmap*, const IntRect&); 57 ImageBitmap(ImageBitmap*, const IntRect&);
60 ImageBitmap(Image*, const IntRect&); 58 ImageBitmap(Image*, const IntRect&);
61 59
60 PassRefPtr<SkImage> cropImage(PassRefPtr<SkImage>, const IntRect&);
61
62 // ImageLoaderClient 62 // ImageLoaderClient
63 void notifyImageSourceChanged() override; 63 void notifyImageSourceChanged() override;
64 bool requestsHighLiveResourceCachePriority() override { return true; } 64 bool requestsHighLiveResourceCachePriority() override { return true; }
65 65
66 // ImageBitmaps constructed from HTMLImageElements hold a reference to the H TMLImageElement until 66 RefPtr<SkImage> m_image;
67 // the image source changes.
68 RefPtrWillBeMember<HTMLImageElement> m_imageElement;
69 RefPtr<Image> m_bitmap;
70
71 IntRect m_bitmapRect; // The rect where the underlying Image should be place d in reference to the ImageBitmap.
72 IntRect m_cropRect;
73
74 // The offset by which the desired Image is stored internally.
75 // ImageBitmaps constructed from HTMLImageElements reference the entire Imag eResource and may have a non-zero bitmap offset.
76 // ImageBitmaps not constructed from HTMLImageElements always pre-crop and s tore the image at (0, 0).
77 IntPoint m_bitmapOffset;
78
79 }; 67 };
80 68
81 } // namespace blink 69 } // namespace blink
82 70
83 #endif // ImageBitmap_h 71 #endif // ImageBitmap_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698