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

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: un-plumb props into device (not needed) 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
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 Props*);
23 SkSurface_Raster(SkPixelRef*, const Props*);
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 Props* props)
84 : INHERITED(info, props ? *props : 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 Props* props)
89 : INHERITED(pr->info().width(), pr->info().height()) 91 : INHERITED(pr->info().width(), pr->info().height(), props ? *props : 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() {
robertphillips 2014/09/16 14:15:19 const SkSurfacePropos& props = ?
reed1 2014/09/16 18:16:01 Done.
103 return SkNEW_ARGS(SkCanvas, (fBitmap)); 105 SkSurfaceProps props = this->props();
106 return SkNEW_ARGS(SkCanvas, (fBitmap, &props));
104 } 107 }
105 108
106 SkSurface* SkSurface_Raster::onNewSurface(const SkImageInfo& info) { 109 SkSurface* SkSurface_Raster::onNewSurface(const SkImageInfo& info) {
107 return SkSurface::NewRaster(info); 110 return SkSurface::NewRaster(info);
108 } 111 }
109 112
110 void SkSurface_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, 113 void SkSurface_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y,
111 const SkPaint* paint) { 114 const SkPaint* paint) {
112 canvas->drawBitmap(fBitmap, x, y, paint); 115 canvas->drawBitmap(fBitmap, x, y, paint);
113 } 116 }
(...skipping 19 matching lines...) Expand all
133 // this as its backend, so we can't modify the image's pixels anymore. 136 // this as its backend, so we can't modify the image's pixels anymore.
134 SkASSERT(this->getCachedCanvas()); 137 SkASSERT(this->getCachedCanvas());
135 this->getCachedCanvas()->getDevice()->replaceBitmapBackendForRasterSurfa ce(fBitmap); 138 this->getCachedCanvas()->getDevice()->replaceBitmapBackendForRasterSurfa ce(fBitmap);
136 } 139 }
137 } 140 }
138 141
139 /////////////////////////////////////////////////////////////////////////////// 142 ///////////////////////////////////////////////////////////////////////////////
140 143
141 SkSurface* SkSurface::NewRasterDirectReleaseProc(const SkImageInfo& info, void* pixels, size_t rb, 144 SkSurface* SkSurface::NewRasterDirectReleaseProc(const SkImageInfo& info, void* pixels, size_t rb,
142 void (*releaseProc)(void* pixel s, void* context), 145 void (*releaseProc)(void* pixel s, void* context),
143 void* context) { 146 void* context, const Props* pro ps) {
144 if (NULL == releaseProc) { 147 if (NULL == releaseProc) {
145 context = NULL; 148 context = NULL;
146 } 149 }
147 if (!SkSurface_Raster::Valid(info, rb)) { 150 if (!SkSurface_Raster::Valid(info, rb)) {
148 return NULL; 151 return NULL;
149 } 152 }
150 if (NULL == pixels) { 153 if (NULL == pixels) {
151 return NULL; 154 return NULL;
152 } 155 }
153 156
154 return SkNEW_ARGS(SkSurface_Raster, (info, pixels, rb, releaseProc, context) ); 157 return SkNEW_ARGS(SkSurface_Raster, (info, pixels, rb, releaseProc, context, props));
155 } 158 }
156 159
157 SkSurface* SkSurface::NewRasterDirect(const SkImageInfo& info, void* pixels, siz e_t rowBytes) { 160 SkSurface* SkSurface::NewRasterDirect(const SkImageInfo& info, void* pixels, siz e_t rowBytes,
158 return NewRasterDirectReleaseProc(info, pixels, rowBytes, NULL, NULL); 161 const Props* props) {
162 return NewRasterDirectReleaseProc(info, pixels, rowBytes, NULL, NULL, props) ;
159 } 163 }
160 164
161 SkSurface* SkSurface::NewRaster(const SkImageInfo& info) { 165 SkSurface* SkSurface::NewRaster(const SkImageInfo& info, const Props* props) {
162 if (!SkSurface_Raster::Valid(info)) { 166 if (!SkSurface_Raster::Valid(info)) {
163 return NULL; 167 return NULL;
164 } 168 }
165 169
166 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewAllocate(info, 0, NULL)); 170 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewAllocate(info, 0, NULL));
167 if (NULL == pr.get()) { 171 if (NULL == pr.get()) {
168 return NULL; 172 return NULL;
169 } 173 }
170 return SkNEW_ARGS(SkSurface_Raster, (pr)); 174 return SkNEW_ARGS(SkSurface_Raster, (pr, props));
171 } 175 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698