| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkSurface_Base.h" | 8 #include "SkSurface_Base.h" |
| 9 #include "SkImagePriv.h" | 9 #include "SkImagePriv.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 } | 80 } |
| 81 | 81 |
| 82 return true; | 82 return true; |
| 83 } | 83 } |
| 84 | 84 |
| 85 SkSurface_Raster::SkSurface_Raster(const SkImageInfo& info, void* pixels, size_t
rb, | 85 SkSurface_Raster::SkSurface_Raster(const SkImageInfo& info, void* pixels, size_t
rb, |
| 86 void (*releaseProc)(void* pixels, void* conte
xt), void* context, | 86 void (*releaseProc)(void* pixels, void* conte
xt), void* context, |
| 87 const SkSurfaceProps* props) | 87 const SkSurfaceProps* props) |
| 88 : INHERITED(info, props) | 88 : INHERITED(info, props) |
| 89 { | 89 { |
| 90 fBitmap.installPixels(info, pixels, rb, NULL, releaseProc, context); | 90 fBitmap.installPixels(info, pixels, rb, nullptr, releaseProc, context); |
| 91 fWeOwnThePixels = false; // We are "Direct" | 91 fWeOwnThePixels = false; // We are "Direct" |
| 92 } | 92 } |
| 93 | 93 |
| 94 SkSurface_Raster::SkSurface_Raster(SkPixelRef* pr, const SkSurfaceProps* props) | 94 SkSurface_Raster::SkSurface_Raster(SkPixelRef* pr, const SkSurfaceProps* props) |
| 95 : INHERITED(pr->info().width(), pr->info().height(), props) | 95 : INHERITED(pr->info().width(), pr->info().height(), props) |
| 96 { | 96 { |
| 97 const SkImageInfo& info = pr->info(); | 97 const SkImageInfo& info = pr->info(); |
| 98 | 98 |
| 99 fBitmap.setInfo(info, info.minRowBytes()); | 99 fBitmap.setInfo(info, info.minRowBytes()); |
| 100 fBitmap.setPixelRef(pr); | 100 fBitmap.setPixelRef(pr); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 pr->restoreMutability(); | 136 pr->restoreMutability(); |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 | 139 |
| 140 void SkSurface_Raster::onCopyOnWrite(ContentChangeMode mode) { | 140 void SkSurface_Raster::onCopyOnWrite(ContentChangeMode mode) { |
| 141 // are we sharing pixelrefs with the image? | 141 // are we sharing pixelrefs with the image? |
| 142 SkASSERT(this->getCachedImage(kNo_Budgeted)); | 142 SkASSERT(this->getCachedImage(kNo_Budgeted)); |
| 143 if (SkBitmapImageGetPixelRef(this->getCachedImage(kNo_Budgeted)) == fBitmap.
pixelRef()) { | 143 if (SkBitmapImageGetPixelRef(this->getCachedImage(kNo_Budgeted)) == fBitmap.
pixelRef()) { |
| 144 SkASSERT(fWeOwnThePixels); | 144 SkASSERT(fWeOwnThePixels); |
| 145 if (kDiscard_ContentChangeMode == mode) { | 145 if (kDiscard_ContentChangeMode == mode) { |
| 146 fBitmap.setPixelRef(NULL); | 146 fBitmap.setPixelRef(nullptr); |
| 147 fBitmap.allocPixels(); | 147 fBitmap.allocPixels(); |
| 148 } else { | 148 } else { |
| 149 SkBitmap prev(fBitmap); | 149 SkBitmap prev(fBitmap); |
| 150 prev.deepCopyTo(&fBitmap); | 150 prev.deepCopyTo(&fBitmap); |
| 151 } | 151 } |
| 152 // Now fBitmap is a deep copy of itself (and therefore different from | 152 // Now fBitmap is a deep copy of itself (and therefore different from |
| 153 // what is being used by the image. Next we update the canvas to use | 153 // what is being used by the image. Next we update the canvas to use |
| 154 // this as its backend, so we can't modify the image's pixels anymore. | 154 // this as its backend, so we can't modify the image's pixels anymore. |
| 155 SkASSERT(this->getCachedCanvas()); | 155 SkASSERT(this->getCachedCanvas()); |
| 156 this->getCachedCanvas()->getDevice()->replaceBitmapBackendForRasterSurfa
ce(fBitmap); | 156 this->getCachedCanvas()->getDevice()->replaceBitmapBackendForRasterSurfa
ce(fBitmap); |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 | 159 |
| 160 /////////////////////////////////////////////////////////////////////////////// | 160 /////////////////////////////////////////////////////////////////////////////// |
| 161 | 161 |
| 162 SkSurface* SkSurface::NewRasterDirectReleaseProc(const SkImageInfo& info, void*
pixels, size_t rb, | 162 SkSurface* SkSurface::NewRasterDirectReleaseProc(const SkImageInfo& info, void*
pixels, size_t rb, |
| 163 void (*releaseProc)(void* pixel
s, void* context), | 163 void (*releaseProc)(void* pixel
s, void* context), |
| 164 void* context, const SkSurfaceP
rops* props) { | 164 void* context, const SkSurfaceP
rops* props) { |
| 165 if (NULL == releaseProc) { | 165 if (nullptr == releaseProc) { |
| 166 context = NULL; | 166 context = nullptr; |
| 167 } | 167 } |
| 168 if (!SkSurface_Raster::Valid(info, rb)) { | 168 if (!SkSurface_Raster::Valid(info, rb)) { |
| 169 return NULL; | 169 return nullptr; |
| 170 } | 170 } |
| 171 if (NULL == pixels) { | 171 if (nullptr == pixels) { |
| 172 return NULL; | 172 return nullptr; |
| 173 } | 173 } |
| 174 | 174 |
| 175 return new SkSurface_Raster(info, pixels, rb, releaseProc, context, props); | 175 return new SkSurface_Raster(info, pixels, rb, releaseProc, context, props); |
| 176 } | 176 } |
| 177 | 177 |
| 178 SkSurface* SkSurface::NewRasterDirect(const SkImageInfo& info, void* pixels, siz
e_t rowBytes, | 178 SkSurface* SkSurface::NewRasterDirect(const SkImageInfo& info, void* pixels, siz
e_t rowBytes, |
| 179 const SkSurfaceProps* props) { | 179 const SkSurfaceProps* props) { |
| 180 return NewRasterDirectReleaseProc(info, pixels, rowBytes, NULL, NULL, props)
; | 180 return NewRasterDirectReleaseProc(info, pixels, rowBytes, nullptr, nullptr,
props); |
| 181 } | 181 } |
| 182 | 182 |
| 183 SkSurface* SkSurface::NewRaster(const SkImageInfo& info, const SkSurfaceProps* p
rops) { | 183 SkSurface* SkSurface::NewRaster(const SkImageInfo& info, const SkSurfaceProps* p
rops) { |
| 184 if (!SkSurface_Raster::Valid(info)) { | 184 if (!SkSurface_Raster::Valid(info)) { |
| 185 return NULL; | 185 return nullptr; |
| 186 } | 186 } |
| 187 | 187 |
| 188 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewAllocate(info, 0, NULL)); | 188 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewAllocate(info, 0, nullptr))
; |
| 189 if (NULL == pr.get()) { | 189 if (nullptr == pr.get()) { |
| 190 return NULL; | 190 return nullptr; |
| 191 } | 191 } |
| 192 return new SkSurface_Raster(pr, props); | 192 return new SkSurface_Raster(pr, props); |
| 193 } | 193 } |
| OLD | NEW |