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

Side by Side Diff: src/image/SkSurface_Raster.cpp

Issue 351373005: add SkSurface::NewRasterDirectReleaseProc (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 6 months 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
« no previous file with comments | « include/core/SkSurface.h ('k') | tests/SurfaceTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "SkDevice.h" 11 #include "SkDevice.h"
12 #include "SkMallocPixelRef.h" 12 #include "SkMallocPixelRef.h"
13 13
14 static const size_t kIgnoreRowBytesValue = (size_t)~0; 14 static const size_t kIgnoreRowBytesValue = (size_t)~0;
15 15
16 class SkSurface_Raster : public SkSurface_Base { 16 class SkSurface_Raster : public SkSurface_Base {
17 public: 17 public:
18 static bool Valid(const SkImageInfo&, size_t rb = kIgnoreRowBytesValue); 18 static bool Valid(const SkImageInfo&, size_t rb = kIgnoreRowBytesValue);
19 19
20 SkSurface_Raster(const SkImageInfo&, void*, size_t rb); 20 SkSurface_Raster(const SkImageInfo&, void*, size_t rb,
21 void (*releaseProc)(void* pixels, void* context), void* con text);
21 SkSurface_Raster(SkPixelRef*); 22 SkSurface_Raster(SkPixelRef*);
22 23
23 virtual SkCanvas* onNewCanvas() SK_OVERRIDE; 24 virtual SkCanvas* onNewCanvas() SK_OVERRIDE;
24 virtual SkSurface* onNewSurface(const SkImageInfo&) SK_OVERRIDE; 25 virtual SkSurface* onNewSurface(const SkImageInfo&) SK_OVERRIDE;
25 virtual SkImage* onNewImageSnapshot() SK_OVERRIDE; 26 virtual SkImage* onNewImageSnapshot() SK_OVERRIDE;
26 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, 27 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y,
27 const SkPaint*) SK_OVERRIDE; 28 const SkPaint*) SK_OVERRIDE;
28 virtual void onCopyOnWrite(ContentChangeMode) SK_OVERRIDE; 29 virtual void onCopyOnWrite(ContentChangeMode) SK_OVERRIDE;
29 30
30 private: 31 private:
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 } 70 }
70 71
71 uint64_t size = sk_64_mul(info.fHeight, rowBytes); 72 uint64_t size = sk_64_mul(info.fHeight, rowBytes);
72 if (size > kMaxTotalSize) { 73 if (size > kMaxTotalSize) {
73 return false; 74 return false;
74 } 75 }
75 76
76 return true; 77 return true;
77 } 78 }
78 79
79 SkSurface_Raster::SkSurface_Raster(const SkImageInfo& info, void* pixels, size_t rb) 80 SkSurface_Raster::SkSurface_Raster(const SkImageInfo& info, void* pixels, size_t rb,
81 void (*releaseProc)(void* pixels, void* conte xt), void* context)
80 : INHERITED(info) 82 : INHERITED(info)
81 { 83 {
82 fBitmap.installPixels(info, pixels, rb); 84 fBitmap.installPixels(info, pixels, rb, NULL, releaseProc, context);
83 fWeOwnThePixels = false; // We are "Direct" 85 fWeOwnThePixels = false; // We are "Direct"
84 } 86 }
85 87
86 SkSurface_Raster::SkSurface_Raster(SkPixelRef* pr) 88 SkSurface_Raster::SkSurface_Raster(SkPixelRef* pr)
87 : INHERITED(pr->info().fWidth, pr->info().fHeight) 89 : INHERITED(pr->info().fWidth, pr->info().fHeight)
88 { 90 {
89 const SkImageInfo& info = pr->info(); 91 const SkImageInfo& info = pr->info();
90 92
91 fBitmap.setInfo(info, info.minRowBytes()); 93 fBitmap.setInfo(info, info.minRowBytes());
92 fBitmap.setPixelRef(pr); 94 fBitmap.setPixelRef(pr);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 // Now fBitmap is a deep copy of itself (and therefore different from 131 // Now fBitmap is a deep copy of itself (and therefore different from
130 // what is being used by the image. Next we update the canvas to use 132 // what is being used by the image. Next we update the canvas to use
131 // this as its backend, so we can't modify the image's pixels anymore. 133 // this as its backend, so we can't modify the image's pixels anymore.
132 SkASSERT(NULL != this->getCachedCanvas()); 134 SkASSERT(NULL != this->getCachedCanvas());
133 this->getCachedCanvas()->getDevice()->replaceBitmapBackendForRasterSurfa ce(fBitmap); 135 this->getCachedCanvas()->getDevice()->replaceBitmapBackendForRasterSurfa ce(fBitmap);
134 } 136 }
135 } 137 }
136 138
137 /////////////////////////////////////////////////////////////////////////////// 139 ///////////////////////////////////////////////////////////////////////////////
138 140
139 SkSurface* SkSurface::NewRasterDirect(const SkImageInfo& info, void* pixels, siz e_t rowBytes) { 141 SkSurface* SkSurface::NewRasterDirectReleaseProc(const SkImageInfo& info, void* pixels, size_t rb,
140 if (!SkSurface_Raster::Valid(info, rowBytes)) { 142 void (*releaseProc)(void* pixel s, void* context),
143 void* context) {
144 if (NULL == releaseProc) {
145 context = NULL;
146 }
147 if (!SkSurface_Raster::Valid(info, rb)) {
141 return NULL; 148 return NULL;
142 } 149 }
143 if (NULL == pixels) { 150 if (NULL == pixels) {
144 return NULL; 151 return NULL;
145 } 152 }
153
154 return SkNEW_ARGS(SkSurface_Raster, (info, pixels, rb, releaseProc, context) );
155 }
146 156
147 return SkNEW_ARGS(SkSurface_Raster, (info, pixels, rowBytes)); 157 SkSurface* SkSurface::NewRasterDirect(const SkImageInfo& info, void* pixels, siz e_t rowBytes) {
158 return NewRasterDirectReleaseProc(info, pixels, rowBytes, NULL, NULL);
148 } 159 }
149 160
150 SkSurface* SkSurface::NewRaster(const SkImageInfo& info) { 161 SkSurface* SkSurface::NewRaster(const SkImageInfo& info) {
151 if (!SkSurface_Raster::Valid(info)) { 162 if (!SkSurface_Raster::Valid(info)) {
152 return NULL; 163 return NULL;
153 } 164 }
154 165
155 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewAllocate(info, 0, NULL)); 166 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewAllocate(info, 0, NULL));
156 if (NULL == pr.get()) { 167 if (NULL == pr.get()) {
157 return NULL; 168 return NULL;
158 } 169 }
159 return SkNEW_ARGS(SkSurface_Raster, (pr)); 170 return SkNEW_ARGS(SkSurface_Raster, (pr));
160 } 171 }
OLDNEW
« no previous file with comments | « include/core/SkSurface.h ('k') | tests/SurfaceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698