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

Side by Side Diff: src/core/SkBlitter.cpp

Issue 267923005: remove unneeded SkShader::validContext (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 7 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
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkBlitter.h" 10 #include "SkBlitter.h"
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 } 584 }
585 585
586 virtual size_t contextSize() const SK_OVERRIDE { 586 virtual size_t contextSize() const SK_OVERRIDE {
587 size_t size = sizeof(Sk3DShaderContext); 587 size_t size = sizeof(Sk3DShaderContext);
588 if (fProxy) { 588 if (fProxy) {
589 size += fProxy->contextSize(); 589 size += fProxy->contextSize();
590 } 590 }
591 return size; 591 return size;
592 } 592 }
593 593
594 virtual bool validContext(const ContextRec& rec, SkMatrix* totalInverse) con st SK_OVERRIDE { 594 virtual Context* onCreateContext(const ContextRec& rec, void* storage) const SK_OVERRIDE {
595 if (!this->INHERITED::validContext(rec, totalInverse)) { 595 SkShader::Context* proxyContext = NULL;
596 return false;
597 }
598 if (fProxy) {
599 return fProxy->validContext(rec);
600 }
601 return true;
602 }
603
604 virtual SkShader::Context* createContext(const ContextRec& rec, void* storag e) const SK_OVERRIDE
605 {
606 if (!this->validContext(rec, NULL)) {
607 return NULL;
608 }
609
610 SkShader::Context* proxyContext;
611 if (fProxy) { 596 if (fProxy) {
612 char* proxyContextStorage = (char*) storage + sizeof(Sk3DShaderConte xt); 597 char* proxyContextStorage = (char*) storage + sizeof(Sk3DShaderConte xt);
613 proxyContext = fProxy->createContext(rec, proxyContextStorage); 598 proxyContext = fProxy->createContext(rec, proxyContextStorage);
614 SkASSERT(proxyContext); 599 if (!proxyContext) {
615 } else { 600 return NULL;
616 proxyContext = NULL; 601 }
617 } 602 }
618 return SkNEW_PLACEMENT_ARGS(storage, Sk3DShaderContext, (*this, rec, pro xyContext)); 603 return SkNEW_PLACEMENT_ARGS(storage, Sk3DShaderContext, (*this, rec, pro xyContext));
619 } 604 }
620 605
621 class Sk3DShaderContext : public SkShader::Context { 606 class Sk3DShaderContext : public SkShader::Context {
622 public: 607 public:
623 // Calls proxyContext's destructor but will NOT free its memory. 608 // Calls proxyContext's destructor but will NOT free its memory.
624 Sk3DShaderContext(const Sk3DShader& shader, const ContextRec& rec, 609 Sk3DShaderContext(const Sk3DShader& shader, const ContextRec& rec,
625 SkShader::Context* proxyContext) 610 SkShader::Context* proxyContext)
626 : INHERITED(shader, rec) 611 : INHERITED(shader, rec)
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 fShaderFlags = fShaderContext->getFlags(); 1013 fShaderFlags = fShaderContext->getFlags();
1029 } 1014 }
1030 1015
1031 SkShaderBlitter::~SkShaderBlitter() { 1016 SkShaderBlitter::~SkShaderBlitter() {
1032 fShader->unref(); 1017 fShader->unref();
1033 } 1018 }
1034 1019
1035 bool SkShaderBlitter::resetShaderContext(const SkBitmap& device, const SkPaint& paint, 1020 bool SkShaderBlitter::resetShaderContext(const SkBitmap& device, const SkPaint& paint,
1036 const SkMatrix& matrix) { 1021 const SkMatrix& matrix) {
1037 SkShader::ContextRec rec(device, paint, matrix); 1022 SkShader::ContextRec rec(device, paint, matrix);
1038 if (!fShader->validContext(rec)) {
1039 return false;
1040 }
1041 1023
1042 // Only destroy the old context if we have a new one. We need to ensure to h ave a 1024 // Only destroy the old context if we have a new one. We need to ensure to h ave a
1043 // live context in fShaderContext because the storage is owned by an SkSmall Allocator 1025 // live context in fShaderContext because the storage is owned by an SkSmall Allocator
1044 // outside of this class. 1026 // outside of this class.
1045 // The new context will be of the same size as the old one because we use th e same 1027 // The new context will be of the same size as the old one because we use th e same
1046 // shader to create it. It is therefore safe to re-use the storage. 1028 // shader to create it. It is therefore safe to re-use the storage.
1047 fShaderContext->~Context(); 1029 fShaderContext->~Context();
1048 fShaderContext = fShader->createContext(rec, (void*)fShaderContext); 1030 fShaderContext = fShader->createContext(rec, (void*)fShaderContext);
1049 SkASSERT(fShaderContext); 1031 return fShaderContext != NULL;
1050
1051 return true;
1052 } 1032 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698