|
Line 0
a/WebCore/platform/graphics/haiku/ImageHaiku.cpp_sec1
|
| 0 |
- |
1 |
/* |
|
|
2 |
* Copyright (C) 2006 Dirk Mueller <mueller@kde.org> |
| 3 |
* Copyright (C) 2006 Zack Rusin <zack@kde.org> |
| 4 |
* Copyright (C) 2006 Simon Hausmann <hausmann@kde.org> |
| 5 |
* Copyright (C) 2007 Ryan Leavengood <leavengood@gmail.com> |
| 6 |
* Copyright (C) 2008 Andrea Anzani <andrea.anzani@gmail.com> |
| 7 |
* |
| 8 |
* All rights reserved. |
| 9 |
* |
| 10 |
* Redistribution and use in source and binary forms, with or without |
| 11 |
* modification, are permitted provided that the following conditions |
| 12 |
* are met: |
| 13 |
* 1. Redistributions of source code must retain the above copyright |
| 14 |
* notice, this list of conditions and the following disclaimer. |
| 15 |
* 2. Redistributions in binary form must reproduce the above copyright |
| 16 |
* notice, this list of conditions and the following disclaimer in the |
| 17 |
* documentation and/or other materials provided with the distribution. |
| 18 |
* |
| 19 |
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
| 20 |
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 22 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| 23 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 24 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 25 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 26 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 27 |
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 |
*/ |
| 31 |
|
| 32 |
#include "config.h" |
| 33 |
#include "Image.h" |
| 34 |
|
| 35 |
#include "BitmapImage.h" |
| 36 |
#include "FloatRect.h" |
| 37 |
#include "GraphicsContext.h" |
| 38 |
#include "NotImplemented.h" |
| 39 |
#include "PlatformString.h" |
| 40 |
#include <Application.h> |
| 41 |
#include <Bitmap.h> |
| 42 |
#include <View.h> |
| 43 |
|
| 44 |
|
| 45 |
// This function loads resources from WebKit |
| 46 |
Vector<char> loadResourceIntoArray(const char*); |
| 47 |
|
| 48 |
|
| 49 |
namespace WebCore { |
| 50 |
|
| 51 |
bool FrameData::clear(bool clearMetadata) |
| 52 |
{ |
| 53 |
if (clearMetadata) |
| 54 |
m_haveMetadata = false; |
| 55 |
|
| 56 |
if (m_frame) { |
| 57 |
delete m_frame; |
| 58 |
m_frame = 0; |
| 59 |
m_duration = 0.0f; |
| 60 |
m_hasAlpha = true; |
| 61 |
return true; |
| 62 |
} |
| 63 |
|
| 64 |
return false; |
| 65 |
} |
| 66 |
|
| 67 |
WTF::PassRefPtr<Image> Image::loadPlatformResource(const char* name) |
| 68 |
{ |
| 69 |
Vector<char> array = loadResourceIntoArray(name); |
| 70 |
WTF::PassRefPtr<BitmapImage> image = BitmapImage::create(); |
| 71 |
RefPtr<SharedBuffer> buffer = SharedBuffer::create(array.data(), array.size()); |
| 72 |
image->setData(buffer, true); |
| 73 |
|
| 74 |
return image; |
| 75 |
} |
| 76 |
|
| 77 |
void BitmapImage::initPlatformData() |
| 78 |
{ |
| 79 |
} |
| 80 |
|
| 81 |
void BitmapImage::invalidatePlatformData() |
| 82 |
{ |
| 83 |
} |
| 84 |
|
| 85 |
// Drawing Routines |
| 86 |
void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dst, const FloatRect& src, CompositeOperator op) |
| 87 |
{ |
| 88 |
startAnimation(); |
| 89 |
|
| 90 |
BBitmap* image = nativeImageForCurrentFrame(); |
| 91 |
if (!image || !image->IsValid()) // If the image hasn't fully loaded. |
| 92 |
return; |
| 93 |
|
| 94 |
if (mayFillWithSolidColor()) { |
| 95 |
fillWithSolidColor(ctxt, dst, solidColor(), op); |
| 96 |
return; |
| 97 |
} |
| 98 |
|
| 99 |
ctxt->save(); |
| 100 |
ctxt->setCompositeOperation(op); |
| 101 |
|
| 102 |
BRect srcRect(src); |
| 103 |
BRect dstRect(dst); |
| 104 |
|
| 105 |
// Test using example site at |
| 106 |
// http://www.meyerweb.com/eric/css/edge/complexspiral/demo.html |
| 107 |
ctxt->platformContext()->SetDrawingMode(B_OP_ALPHA); |
| 108 |
ctxt->platformContext()->DrawBitmap(image, srcRect & image->Bounds(), dstRect); |
| 109 |
ctxt->restore(); |
| 110 |
} |
| 111 |
|
| 112 |
void Image::drawPattern(GraphicsContext* context, const FloatRect& tileRect, const TransformationMatrix& patternTransform, const FloatPoint& srcPoint, CompositeOperator op, const FloatRect& dstRect) |
| 113 |
{ |
| 114 |
// FIXME: finish this to support also phased position (srcPoint) |
| 115 |
startAnimation(); |
| 116 |
|
| 117 |
BBitmap* image = nativeImageForCurrentFrame(); |
| 118 |
if (!image || !image->IsValid()) // If the image hasn't fully loaded. |
| 119 |
return; |
| 120 |
|
| 121 |
float currentWidth = 0; |
| 122 |
float currentHeight = 0; |
| 123 |
|
| 124 |
context->save(); |
| 125 |
context->platformContext()->SetDrawingMode(B_OP_ALPHA); |
| 126 |
context->clip(enclosingIntRect(dstRect)); |
| 127 |
|
| 128 |
while (currentWidth < dstRect.width()) { |
| 129 |
while (currentHeight < dstRect.height()) { |
| 130 |
context->platformContext()->DrawBitmap(image, BPoint(dstRect.x() + currentWidth, dstRect.y() + currentHeight)); |
| 131 |
currentHeight += tileRect.height(); |
| 132 |
} |
| 133 |
currentWidth += tileRect.width(); |
| 134 |
currentHeight = 0; |
| 135 |
} |
| 136 |
context->restore(); |
| 137 |
} |
| 138 |
|
| 139 |
void BitmapImage::checkForSolidColor() |
| 140 |
{ |
| 141 |
// FIXME: need to check the RGBA32 buffer to see if it is 1x1. |
| 142 |
m_isSolidColor = false; |
| 143 |
m_checkedForSolidColor = true; |
| 144 |
} |
| 145 |
|
| 146 |
BBitmap* BitmapImage::getBBitmap() const |
| 147 |
{ |
| 148 |
return const_cast<BitmapImage*>(this)->frameAtIndex(0); |
| 149 |
} |
| 150 |
|
| 151 |
} // namespace WebCore |
| 152 |
|