Home | History | Annotate | Download | only in page
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef ImageBitmap_h
      6 #define ImageBitmap_h
      7 
      8 #include "bindings/v8/ScriptWrappable.h"
      9 #include "core/html/HTMLImageElement.h"
     10 #include "core/platform/graphics/Image.h"
     11 #include "core/platform/graphics/ImageBuffer.h"
     12 #include "core/platform/graphics/IntRect.h"
     13 #include "wtf/PassRefPtr.h"
     14 #include "wtf/RefCounted.h"
     15 
     16 namespace WebCore {
     17 
     18 class HTMLCanvasElement;
     19 class HTMLVideoElement;
     20 class ImageData;
     21 
     22 class ImageBitmap : public RefCounted<ImageBitmap>, public ScriptWrappable, public ImageLoaderClient {
     23 
     24 public:
     25     static PassRefPtr<ImageBitmap> create(HTMLImageElement*, const IntRect&);
     26     static PassRefPtr<ImageBitmap> create(HTMLVideoElement*, const IntRect&);
     27     static PassRefPtr<ImageBitmap> create(HTMLCanvasElement*, const IntRect&);
     28     static PassRefPtr<ImageBitmap> create(ImageData*, const IntRect&);
     29     static PassRefPtr<ImageBitmap> create(ImageBitmap*, const IntRect&);
     30 
     31     PassRefPtr<Image> bitmapImage() const;
     32     PassRefPtr<HTMLImageElement> imageElement() const { return m_imageElement; }
     33 
     34     IntRect bitmapRect() const { return m_bitmapRect; }
     35     IntPoint bitmapOffset() const { return m_bitmapOffset; }
     36 
     37     int width() const { return m_cropRect.width(); }
     38     int height() const { return m_cropRect.height(); }
     39     IntSize size() const { return m_cropRect.size(); }
     40 
     41     virtual ~ImageBitmap();
     42 
     43 private:
     44     ImageBitmap(HTMLImageElement*, const IntRect&);
     45     ImageBitmap(HTMLVideoElement*, const IntRect&);
     46     ImageBitmap(HTMLCanvasElement*, const IntRect&);
     47     ImageBitmap(ImageData*, const IntRect&);
     48     ImageBitmap(ImageBitmap*, const IntRect&);
     49 
     50     // ImageLoaderClient
     51     virtual void notifyImageSourceChanged();
     52     virtual bool requestsHighLiveResourceCachePriority() { return true; }
     53 
     54     // ImageBitmaps constructed from HTMLImageElements hold a reference to the HTMLImageElement until
     55     // the image source changes.
     56     RefPtr<HTMLImageElement> m_imageElement;
     57     RefPtr<Image> m_bitmap;
     58     OwnPtr<ImageBuffer> m_buffer;
     59 
     60     IntRect m_bitmapRect; // The rect where the underlying Image should be placed in reference to the ImageBitmap.
     61     IntRect m_cropRect;
     62 
     63     // The offset by which the desired Image is stored internally.
     64     // ImageBitmaps constructed from HTMLImageElements reference the entire ImageResource and may have a non-zero bitmap offset.
     65     // ImageBitmaps not constructed from HTMLImageElements always pre-crop and store the image at (0, 0).
     66     IntPoint m_bitmapOffset;
     67 
     68 };
     69 
     70 } // namespace WebCore
     71 
     72 #endif // ImageBitmap_h
     73