| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "webkit/glue/plugins/pepper_image_data.h" | 5 #include "webkit/glue/plugins/pepper_image_data.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 } | 129 } |
| 130 | 130 |
| 131 void ImageData::Describe(PP_ImageDataDesc* desc) const { | 131 void ImageData::Describe(PP_ImageDataDesc* desc) const { |
| 132 desc->format = PP_IMAGEDATAFORMAT_BGRA_PREMUL; | 132 desc->format = PP_IMAGEDATAFORMAT_BGRA_PREMUL; |
| 133 desc->width = width_; | 133 desc->width = width_; |
| 134 desc->height = height_; | 134 desc->height = height_; |
| 135 desc->stride = width_ * 4; | 135 desc->stride = width_ * 4; |
| 136 } | 136 } |
| 137 | 137 |
| 138 void* ImageData::Map() { | 138 void* ImageData::Map() { |
| 139 if (!is_valid()) | |
| 140 return NULL; | |
| 141 | |
| 142 if (!mapped_canvas_.get()) { | 139 if (!mapped_canvas_.get()) { |
| 143 mapped_canvas_.reset(platform_image_->Map()); | 140 mapped_canvas_.reset(platform_image_->Map()); |
| 144 if (!mapped_canvas_.get()) | 141 if (!mapped_canvas_.get()) |
| 145 return NULL; | 142 return NULL; |
| 146 } | 143 } |
| 147 const SkBitmap& bitmap = | 144 const SkBitmap& bitmap = |
| 148 mapped_canvas_->getTopPlatformDevice().accessBitmap(true); | 145 mapped_canvas_->getTopPlatformDevice().accessBitmap(true); |
| 149 | 146 |
| 150 // Our platform bitmaps are set to opaque by default, which we don't want. | 147 // Our platform bitmaps are set to opaque by default, which we don't want. |
| 151 const_cast<SkBitmap&>(bitmap).setIsOpaque(false); | 148 const_cast<SkBitmap&>(bitmap).setIsOpaque(false); |
| 152 | 149 |
| 153 bitmap.lockPixels(); | 150 bitmap.lockPixels(); |
| 154 return bitmap.getAddr32(0, 0); | 151 return bitmap.getAddr32(0, 0); |
| 155 } | 152 } |
| 156 | 153 |
| 157 void ImageData::Unmap() { | 154 void ImageData::Unmap() { |
| 158 // This is currently unimplemented, which is OK. The data will just always | 155 // This is currently unimplemented, which is OK. The data will just always |
| 159 // be around once it's mapped. Chrome's TransportDIB isn't currently | 156 // be around once it's mapped. Chrome's TransportDIB isn't currently |
| 160 // unmappable without freeing it, but this may be something we want to support | 157 // unmappable without freeing it, but this may be something we want to support |
| 161 // in the future to save some memory. | 158 // in the future to save some memory. |
| 162 } | 159 } |
| 163 | 160 |
| 164 const SkBitmap& ImageData::GetMappedBitmap() const { | 161 const SkBitmap* ImageData::GetMappedBitmap() const { |
| 165 DCHECK(is_valid()); | 162 if (!mapped_canvas_.get()) |
| 166 return mapped_canvas_->getTopPlatformDevice().accessBitmap(false); | 163 return NULL; |
| 164 return &mapped_canvas_->getTopPlatformDevice().accessBitmap(false); |
| 167 } | 165 } |
| 168 | 166 |
| 169 void ImageData::Swap(ImageData* other) { | 167 void ImageData::Swap(ImageData* other) { |
| 170 swap(other->platform_image_, platform_image_); | 168 swap(other->platform_image_, platform_image_); |
| 171 swap(other->mapped_canvas_, mapped_canvas_); | 169 swap(other->mapped_canvas_, mapped_canvas_); |
| 172 std::swap(other->width_, width_); | 170 std::swap(other->width_, width_); |
| 173 std::swap(other->height_, height_); | 171 std::swap(other->height_, height_); |
| 174 } | 172 } |
| 175 | 173 |
| 176 } // namespace pepper | 174 } // namespace pepper |
| OLD | NEW |