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

Side by Side Diff: src/effects/SkBitmapSource.cpp

Issue 395603002: Simplify flattening to just write enough to call the factory (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 years, 4 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/effects/SkAvoidXfermode.cpp ('k') | src/effects/SkBlurDrawLooper.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 The Android Open Source Project 2 * Copyright 2012 The Android Open Source Project
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 "SkBitmapSource.h" 8 #include "SkBitmapSource.h"
9 #include "SkDevice.h" 9 #include "SkDevice.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkReadBuffer.h" 11 #include "SkReadBuffer.h"
12 #include "SkWriteBuffer.h" 12 #include "SkWriteBuffer.h"
13 #include "SkValidationUtils.h" 13 #include "SkValidationUtils.h"
14 14
15 SkBitmapSource::SkBitmapSource(const SkBitmap& bitmap) 15 SkBitmapSource::SkBitmapSource(const SkBitmap& bitmap)
16 : INHERITED(0, 0), 16 : INHERITED(0, 0)
17 fBitmap(bitmap), 17 , fBitmap(bitmap)
18 fSrcRect(SkRect::MakeWH(SkIntToScalar(bitmap.width()), 18 , fSrcRect(SkRect::MakeWH(SkIntToScalar(bitmap.width()),
19 SkIntToScalar(bitmap.height()))), 19 SkIntToScalar(bitmap.height())))
20 fDstRect(fSrcRect) { 20 , fDstRect(fSrcRect)
21 } 21 {}
22 22
23 SkBitmapSource::SkBitmapSource(const SkBitmap& bitmap, const SkRect& srcRect, co nst SkRect& dstRect) 23 SkBitmapSource::SkBitmapSource(const SkBitmap& bitmap, const SkRect& srcRect, co nst SkRect& dstRect)
24 : INHERITED(0, 0) 24 : INHERITED(0, 0)
25 , fBitmap(bitmap) 25 , fBitmap(bitmap)
26 , fSrcRect(srcRect) 26 , fSrcRect(srcRect)
27 , fDstRect(dstRect) {} 27 , fDstRect(dstRect) {}
28 28
29 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
29 SkBitmapSource::SkBitmapSource(SkReadBuffer& buffer) : INHERITED(0, buffer) { 30 SkBitmapSource::SkBitmapSource(SkReadBuffer& buffer) : INHERITED(0, buffer) {
30 if (buffer.isVersionLT(SkReadBuffer::kNoMoreBitmapFlatten_Version)) { 31 if (buffer.isVersionLT(SkReadBuffer::kNoMoreBitmapFlatten_Version)) {
31 fBitmap.legacyUnflatten(buffer); 32 fBitmap.legacyUnflatten(buffer);
32 } else { 33 } else {
33 buffer.readBitmap(&fBitmap); 34 buffer.readBitmap(&fBitmap);
34 } 35 }
35 buffer.readRect(&fSrcRect); 36 buffer.readRect(&fSrcRect);
36 buffer.readRect(&fDstRect); 37 buffer.readRect(&fDstRect);
37 buffer.validate(buffer.isValid() && SkIsValidRect(fSrcRect) && SkIsValidRect (fDstRect)); 38 buffer.validate(buffer.isValid() && SkIsValidRect(fSrcRect) && SkIsValidRect (fDstRect));
38 } 39 }
40 #endif
41
42 SkFlattenable* SkBitmapSource::CreateProc(SkReadBuffer& buffer) {
43 SkRect src, dst;
44 buffer.readRect(&src);
45 buffer.readRect(&dst);
46 SkBitmap bitmap;
47 if (!buffer.readBitmap(&bitmap)) {
48 return NULL;
49 }
50 return SkBitmapSource::Create(bitmap, src, dst);
51 }
39 52
40 void SkBitmapSource::flatten(SkWriteBuffer& buffer) const { 53 void SkBitmapSource::flatten(SkWriteBuffer& buffer) const {
41 this->INHERITED::flatten(buffer);
42 buffer.writeBitmap(fBitmap);
43 buffer.writeRect(fSrcRect); 54 buffer.writeRect(fSrcRect);
44 buffer.writeRect(fDstRect); 55 buffer.writeRect(fDstRect);
56 buffer.writeBitmap(fBitmap);
45 } 57 }
46 58
47 bool SkBitmapSource::onFilterImage(Proxy* proxy, const SkBitmap&, const Context& ctx, 59 bool SkBitmapSource::onFilterImage(Proxy* proxy, const SkBitmap&, const Context& ctx,
48 SkBitmap* result, SkIPoint* offset) const { 60 SkBitmap* result, SkIPoint* offset) const {
49 SkRect bounds, dstRect; 61 SkRect bounds, dstRect;
50 fBitmap.getBounds(&bounds); 62 fBitmap.getBounds(&bounds);
51 ctx.ctm().mapRect(&dstRect, fDstRect); 63 ctx.ctm().mapRect(&dstRect, fDstRect);
52 if (fSrcRect == bounds && dstRect == bounds) { 64 if (fSrcRect == bounds && dstRect == bounds) {
53 // No regions cropped out or resized; return entire bitmap. 65 // No regions cropped out or resized; return entire bitmap.
54 *result = fBitmap; 66 *result = fBitmap;
(...skipping 29 matching lines...) Expand all
84 96
85 void SkBitmapSource::computeFastBounds(const SkRect&, SkRect* dst) const { 97 void SkBitmapSource::computeFastBounds(const SkRect&, SkRect* dst) const {
86 *dst = fDstRect; 98 *dst = fDstRect;
87 } 99 }
88 100
89 bool SkBitmapSource::onFilterBounds(const SkIRect& src, const SkMatrix& ctm, 101 bool SkBitmapSource::onFilterBounds(const SkIRect& src, const SkMatrix& ctm,
90 SkIRect* dst) const { 102 SkIRect* dst) const {
91 *dst = src; 103 *dst = src;
92 return true; 104 return true;
93 } 105 }
OLDNEW
« no previous file with comments | « src/effects/SkAvoidXfermode.cpp ('k') | src/effects/SkBlurDrawLooper.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698