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

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

Issue 551463004: introduce Props to surface (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add new file Created 6 years, 3 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 | « src/image/SkSurface_Gpu.cpp ('k') | src/pdf/SkPDFDevice.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 void (*releaseProc)(void* pixels, void* context), void* con text,
22 SkSurface_Raster(SkPixelRef*); 22 const SkSurfaceProps*);
23 SkSurface_Raster(SkPixelRef*, const SkSurfaceProps*);
23 24
24 virtual SkCanvas* onNewCanvas() SK_OVERRIDE; 25 virtual SkCanvas* onNewCanvas() SK_OVERRIDE;
25 virtual SkSurface* onNewSurface(const SkImageInfo&) SK_OVERRIDE; 26 virtual SkSurface* onNewSurface(const SkImageInfo&) SK_OVERRIDE;
26 virtual SkImage* onNewImageSnapshot() SK_OVERRIDE; 27 virtual SkImage* onNewImageSnapshot() SK_OVERRIDE;
27 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, 28 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y,
28 const SkPaint*) SK_OVERRIDE; 29 const SkPaint*) SK_OVERRIDE;
29 virtual void onCopyOnWrite(ContentChangeMode) SK_OVERRIDE; 30 virtual void onCopyOnWrite(ContentChangeMode) SK_OVERRIDE;
30 31
31 private: 32 private:
32 SkBitmap fBitmap; 33 SkBitmap fBitmap;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 72
72 uint64_t size = sk_64_mul(info.height(), rowBytes); 73 uint64_t size = sk_64_mul(info.height(), rowBytes);
73 if (size > kMaxTotalSize) { 74 if (size > kMaxTotalSize) {
74 return false; 75 return false;
75 } 76 }
76 77
77 return true; 78 return true;
78 } 79 }
79 80
80 SkSurface_Raster::SkSurface_Raster(const SkImageInfo& info, void* pixels, size_t rb, 81 SkSurface_Raster::SkSurface_Raster(const SkImageInfo& info, void* pixels, size_t rb,
81 void (*releaseProc)(void* pixels, void* conte xt), void* context) 82 void (*releaseProc)(void* pixels, void* conte xt), void* context,
82 : INHERITED(info) 83 const SkSurfaceProps* props)
84 : INHERITED(info, props)
83 { 85 {
84 fBitmap.installPixels(info, pixels, rb, NULL, releaseProc, context); 86 fBitmap.installPixels(info, pixels, rb, NULL, releaseProc, context);
85 fWeOwnThePixels = false; // We are "Direct" 87 fWeOwnThePixels = false; // We are "Direct"
86 } 88 }
87 89
88 SkSurface_Raster::SkSurface_Raster(SkPixelRef* pr) 90 SkSurface_Raster::SkSurface_Raster(SkPixelRef* pr, const SkSurfaceProps* props)
89 : INHERITED(pr->info().width(), pr->info().height()) 91 : INHERITED(pr->info().width(), pr->info().height(), props)
90 { 92 {
91 const SkImageInfo& info = pr->info(); 93 const SkImageInfo& info = pr->info();
92 94
93 fBitmap.setInfo(info, info.minRowBytes()); 95 fBitmap.setInfo(info, info.minRowBytes());
94 fBitmap.setPixelRef(pr); 96 fBitmap.setPixelRef(pr);
95 fWeOwnThePixels = true; 97 fWeOwnThePixels = true;
96 98
97 if (!info.isOpaque()) { 99 if (!info.isOpaque()) {
98 fBitmap.eraseColor(SK_ColorTRANSPARENT); 100 fBitmap.eraseColor(SK_ColorTRANSPARENT);
99 } 101 }
100 } 102 }
101 103
102 SkCanvas* SkSurface_Raster::onNewCanvas() { 104 SkCanvas* SkSurface_Raster::onNewCanvas() {
103 return SkNEW_ARGS(SkCanvas, (fBitmap)); 105 return SkNEW_ARGS(SkCanvas, (fBitmap, this->props()));
104 } 106 }
105 107
106 SkSurface* SkSurface_Raster::onNewSurface(const SkImageInfo& info) { 108 SkSurface* SkSurface_Raster::onNewSurface(const SkImageInfo& info) {
107 return SkSurface::NewRaster(info); 109 return SkSurface::NewRaster(info);
108 } 110 }
109 111
110 void SkSurface_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, 112 void SkSurface_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y,
111 const SkPaint* paint) { 113 const SkPaint* paint) {
112 canvas->drawBitmap(fBitmap, x, y, paint); 114 canvas->drawBitmap(fBitmap, x, y, paint);
113 } 115 }
(...skipping 19 matching lines...) Expand all
133 // this as its backend, so we can't modify the image's pixels anymore. 135 // this as its backend, so we can't modify the image's pixels anymore.
134 SkASSERT(this->getCachedCanvas()); 136 SkASSERT(this->getCachedCanvas());
135 this->getCachedCanvas()->getDevice()->replaceBitmapBackendForRasterSurfa ce(fBitmap); 137 this->getCachedCanvas()->getDevice()->replaceBitmapBackendForRasterSurfa ce(fBitmap);
136 } 138 }
137 } 139 }
138 140
139 /////////////////////////////////////////////////////////////////////////////// 141 ///////////////////////////////////////////////////////////////////////////////
140 142
141 SkSurface* SkSurface::NewRasterDirectReleaseProc(const SkImageInfo& info, void* pixels, size_t rb, 143 SkSurface* SkSurface::NewRasterDirectReleaseProc(const SkImageInfo& info, void* pixels, size_t rb,
142 void (*releaseProc)(void* pixel s, void* context), 144 void (*releaseProc)(void* pixel s, void* context),
143 void* context) { 145 void* context, const SkSurfaceP rops* props) {
144 if (NULL == releaseProc) { 146 if (NULL == releaseProc) {
145 context = NULL; 147 context = NULL;
146 } 148 }
147 if (!SkSurface_Raster::Valid(info, rb)) { 149 if (!SkSurface_Raster::Valid(info, rb)) {
148 return NULL; 150 return NULL;
149 } 151 }
150 if (NULL == pixels) { 152 if (NULL == pixels) {
151 return NULL; 153 return NULL;
152 } 154 }
153 155
154 return SkNEW_ARGS(SkSurface_Raster, (info, pixels, rb, releaseProc, context) ); 156 return SkNEW_ARGS(SkSurface_Raster, (info, pixels, rb, releaseProc, context, props));
155 } 157 }
156 158
157 SkSurface* SkSurface::NewRasterDirect(const SkImageInfo& info, void* pixels, siz e_t rowBytes) { 159 SkSurface* SkSurface::NewRasterDirect(const SkImageInfo& info, void* pixels, siz e_t rowBytes,
158 return NewRasterDirectReleaseProc(info, pixels, rowBytes, NULL, NULL); 160 const SkSurfaceProps* props) {
161 return NewRasterDirectReleaseProc(info, pixels, rowBytes, NULL, NULL, props) ;
159 } 162 }
160 163
161 SkSurface* SkSurface::NewRaster(const SkImageInfo& info) { 164 SkSurface* SkSurface::NewRaster(const SkImageInfo& info, const SkSurfaceProps* p rops) {
162 if (!SkSurface_Raster::Valid(info)) { 165 if (!SkSurface_Raster::Valid(info)) {
163 return NULL; 166 return NULL;
164 } 167 }
165 168
166 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewAllocate(info, 0, NULL)); 169 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewAllocate(info, 0, NULL));
167 if (NULL == pr.get()) { 170 if (NULL == pr.get()) {
168 return NULL; 171 return NULL;
169 } 172 }
170 return SkNEW_ARGS(SkSurface_Raster, (pr)); 173 return SkNEW_ARGS(SkSurface_Raster, (pr, props));
171 } 174 }
OLDNEW
« no previous file with comments | « src/image/SkSurface_Gpu.cpp ('k') | src/pdf/SkPDFDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698