• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "skia/ext/paint_simplifier.h"
6 #include "third_party/skia/include/core/SkPaint.h"
7 #include "third_party/skia/include/core/SkShader.h"
8 
9 namespace skia {
10 namespace {
11 
PaintHasBitmap(const SkPaint & paint)12 bool PaintHasBitmap(const SkPaint &paint) {
13   SkShader* shader = paint.getShader();
14   if (!shader)
15     return false;
16 
17   if (shader->asAGradient(NULL) == SkShader::kNone_GradientType)
18     return false;
19 
20   return shader->asABitmap(NULL, NULL, NULL) != SkShader::kNone_BitmapType;
21 }
22 
23 }  // namespace
24 
PaintSimplifier()25 PaintSimplifier::PaintSimplifier()
26   : INHERITED() {
27 
28 }
29 
~PaintSimplifier()30 PaintSimplifier::~PaintSimplifier() {
31 
32 }
33 
filter(SkPaint * paint,Type type)34 bool PaintSimplifier::filter(SkPaint* paint, Type type) {
35   // Bitmaps are expensive. Skip draw if type has a bitmap.
36   if (type == kBitmap_Type || PaintHasBitmap(*paint))
37     return false;
38 
39   // Preserve a modicum of text quality; black & white text is
40   // just too blocky, even during a fling.
41   if (type != kText_Type) {
42     paint->setAntiAlias(false);
43   }
44   paint->setSubpixelText(false);
45   paint->setLCDRenderText(false);
46 
47   paint->setMaskFilter(NULL);
48 
49   // Uncomment this line to shade simplified tiles pink during debugging.
50   //paint->setColor(SkColorSetRGB(255, 127, 127));
51 
52   return true;
53 }
54 
55 
56 }  // namespace skia
57 
58 
59