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

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

Issue 134843008: Revert of Revert "Revert of https://codereview.chromium.org/129423002/" (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « src/image/SkImage_Base.h ('k') | src/image/SkSurface_Raster.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 "SkImage_Base.h" 8 #include "SkImage_Base.h"
9 #include "SkImagePriv.h" 9 #include "SkImagePriv.h"
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 static SkImage* NewEmpty(); 51 static SkImage* NewEmpty();
52 52
53 SkImage_Raster(const SkImageInfo&, SkData*, size_t rb); 53 SkImage_Raster(const SkImageInfo&, SkData*, size_t rb);
54 virtual ~SkImage_Raster(); 54 virtual ~SkImage_Raster();
55 55
56 virtual void onDraw(SkCanvas*, SkScalar, SkScalar, const SkPaint*) SK_OVERRI DE; 56 virtual void onDraw(SkCanvas*, SkScalar, SkScalar, const SkPaint*) SK_OVERRI DE;
57 virtual void onDrawRectToRect(SkCanvas*, const SkRect*, const SkRect&, const SkPaint*) SK_OVERRIDE; 57 virtual void onDrawRectToRect(SkCanvas*, const SkRect*, const SkRect&, const SkPaint*) SK_OVERRIDE;
58 virtual bool getROPixels(SkBitmap*) const SK_OVERRIDE; 58 virtual bool getROPixels(SkBitmap*) const SK_OVERRIDE;
59 59
60 // exposed for SkSurface_Raster via SkNewImageFromPixelRef 60 // exposed for SkSurface_Raster via SkNewImageFromPixelRef
61 SkImage_Raster(SkPixelRef*); 61 SkImage_Raster(const SkImageInfo&, SkPixelRef*, size_t rowBytes);
62 62
63 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } 63 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); }
64 64
65 private: 65 private:
66 SkImage_Raster() : INHERITED(0, 0) {} 66 SkImage_Raster() : INHERITED(0, 0) {}
67 67
68 SkBitmap fBitmap; 68 SkBitmap fBitmap;
69 69
70 typedef SkImage_Base INHERITED; 70 typedef SkImage_Base INHERITED;
71 }; 71 };
72 72
73 /////////////////////////////////////////////////////////////////////////////// 73 ///////////////////////////////////////////////////////////////////////////////
74 74
75 SkImage* SkImage_Raster::NewEmpty() { 75 SkImage* SkImage_Raster::NewEmpty() {
76 // Returns lazily created singleton 76 // Returns lazily created singleton
77 static SkImage* gEmpty; 77 static SkImage* gEmpty;
78 if (NULL == gEmpty) { 78 if (NULL == gEmpty) {
79 gEmpty = SkNEW(SkImage_Raster); 79 gEmpty = SkNEW(SkImage_Raster);
80 } 80 }
81 gEmpty->ref(); 81 gEmpty->ref();
82 return gEmpty; 82 return gEmpty;
83 } 83 }
84 84
85 SkImage_Raster::SkImage_Raster(const Info& info, SkData* data, size_t rowBytes) 85 SkImage_Raster::SkImage_Raster(const Info& info, SkData* data, size_t rowBytes)
86 : INHERITED(info.fWidth, info.fHeight) { 86 : INHERITED(info.fWidth, info.fHeight) {
87 fBitmap.setConfig(info, rowBytes);
87 SkAutoTUnref<SkPixelRef> ref( 88 SkAutoTUnref<SkPixelRef> ref(
88 SkMallocPixelRef::NewWithData(info, rowBytes, NULL, data, 0)); 89 SkMallocPixelRef::NewWithData(info, rowBytes, NULL, data, 0));
89 fBitmap.installPixelRef(ref); 90 fBitmap.setPixelRef(ref);
90 fBitmap.setImmutable(); 91 fBitmap.setImmutable();
91 } 92 }
92 93
93 SkImage_Raster::SkImage_Raster(SkPixelRef* pr) 94 SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, size_t rowBytes )
94 : INHERITED(pr->info()) 95 : INHERITED(info.fWidth, info.fHeight)
95 { 96 {
96 fBitmap.installPixelRef(pr); 97 fBitmap.setConfig(info, rowBytes);
98 fBitmap.setPixelRef(pr);
97 } 99 }
98 100
99 SkImage_Raster::~SkImage_Raster() {} 101 SkImage_Raster::~SkImage_Raster() {}
100 102
101 void SkImage_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPa int* paint) { 103 void SkImage_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPa int* paint) {
102 canvas->drawBitmap(fBitmap, x, y, paint); 104 canvas->drawBitmap(fBitmap, x, y, paint);
103 } 105 }
104 106
105 void SkImage_Raster::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, const SkRect& dst, const SkPaint* paint) { 107 void SkImage_Raster::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, const SkRect& dst, const SkPaint* paint) {
106 canvas->drawBitmapRectToRect(fBitmap, src, dst, paint); 108 canvas->drawBitmapRectToRect(fBitmap, src, dst, paint);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 // did they give us enough data? 148 // did they give us enough data?
147 size_t size = info.fHeight * rowBytes; 149 size_t size = info.fHeight * rowBytes;
148 if (pixelData->size() < size) { 150 if (pixelData->size() < size) {
149 return NULL; 151 return NULL;
150 } 152 }
151 153
152 SkAutoDataUnref data(pixelData); 154 SkAutoDataUnref data(pixelData);
153 return SkNEW_ARGS(SkImage_Raster, (info, data, rowBytes)); 155 return SkNEW_ARGS(SkImage_Raster, (info, data, rowBytes));
154 } 156 }
155 157
156 SkImage* SkNewImageFromPixelRef(SkPixelRef* pr) { 158 SkImage* SkNewImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr,
157 return SkNEW_ARGS(SkImage_Raster, (pr)); 159 size_t rowBytes) {
160 return SkNEW_ARGS(SkImage_Raster, (info, pr, rowBytes));
158 } 161 }
159 162
160 SkPixelRef* SkBitmapImageGetPixelRef(SkImage* image) { 163 SkPixelRef* SkBitmapImageGetPixelRef(SkImage* image) {
161 return ((SkImage_Raster*)image)->getPixelRef(); 164 return ((SkImage_Raster*)image)->getPixelRef();
162 } 165 }
OLDNEW
« no previous file with comments | « src/image/SkImage_Base.h ('k') | src/image/SkSurface_Raster.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698